security-checklist/components/ChecklistItem/Apps.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-01-13 07:00:23 +00:00
// @flow
2019-01-17 01:52:09 +00:00
// $FlowIssue
import React, { useState } from 'react';
import { AppsContainer, SectionHeading, ExpandContainer } from './style';
import { Button } from '../Button';
2019-01-13 07:00:23 +00:00
import type { ChecklistResource } from '../../types';
import { AppRow } from './App';
type Props = {
resource: ChecklistResource,
};
2019-01-17 01:52:09 +00:00
export const Apps = ({ resource }: Props) => {
const [overflowExpanded, setOverflowExpanded] = useState(false);
2019-01-17 01:52:09 +00:00
if (!resource.apps) return null;
2019-01-17 01:52:09 +00:00
let appList = resource.apps;
let overflowAppList;
if (appList.length > 3) {
overflowAppList = appList.slice(3, appList.length);
appList = appList.slice(0, 3);
}
2019-01-17 01:52:09 +00:00
return (
<AppsContainer overflowExpanded={overflowExpanded}>
<SectionHeading>Apps</SectionHeading>
{appList.map(app => (
<AppRow key={app.name} app={app} />
))}
{overflowAppList && !overflowExpanded && (
<ExpandContainer onClick={() => setOverflowExpanded(true)}>
<Button>Show more choices</Button>
</ExpandContainer>
)}
{overflowAppList &&
overflowExpanded &&
overflowAppList.map(app => <AppRow key={app.name} app={app} />)}
</AppsContainer>
);
};