feat(frontend): updated UI of `Records` component

* Removed `modal` prop.
pull/85/head
Samuel Rowe 3 years ago
parent 9b2ba72671
commit dda2173adf

@ -49,7 +49,6 @@ const IPam = () => {
<Records <Records
name="configurations" name="configurations"
modal="network"
title="Configurations" title="Configurations"
referred="configuration" referred="configuration"
fields={(index: number) => [ fields={(index: number) => [
@ -131,7 +130,6 @@ const IPam = () => {
<Records <Records
name="options" name="options"
modal="network"
title="Options" title="Options"
referred="option" referred="option"
fields={(index: number) => [ fields={(index: number) => [

@ -13,7 +13,6 @@ const Labels: FunctionComponent = (): ReactElement => {
<Root> <Root>
<Records <Records
name="labels" name="labels"
modal="network"
title="" title=""
referred="label" referred="label"
fields={(index: number) => [ fields={(index: number) => [

@ -30,7 +30,6 @@ const General = () => {
<Records <Records
name="ports" name="ports"
modal="service"
title="Ports" title="Ports"
referred="port" referred="port"
fields={(index: number) => [ fields={(index: number) => [
@ -67,6 +66,21 @@ const General = () => {
protocol: "" protocol: ""
}} }}
/> />
<Records
name="profiles"
title="Profiles"
referred="profile"
fields={(index: number) => [
{
name: `profiles[${index}]`,
placeholder: "Name",
required: true,
type: "text"
}
]}
newValue={""}
/>
</Root> </Root>
); );
}; };

@ -1,12 +1,12 @@
import { Button, styled } from "@mui/joy"; import { styled } from "@mui/joy";
import { Fragment, FunctionComponent, ReactElement, useCallback } from "react"; import { Fragment, FunctionComponent, ReactElement, useCallback } from "react";
import { PlusIcon } from "@heroicons/react/outline"; import { PlusIcon } from "@heroicons/react/outline";
import Record, { IFieldType } from "./Record"; import Record, { IFieldType } from "./Record";
import { useFormikContext } from "formik"; import { useFormikContext } from "formik";
import lodash from "lodash"; import lodash from "lodash";
import IconButton from "@mui/joy/IconButton";
export interface IRecordsProps { export interface IRecordsProps {
modal: string;
title: string; title: string;
referred: string; referred: string;
name: string; name: string;
@ -18,10 +18,15 @@ export interface IRecordsProps {
renderBorder?: () => ReactElement; renderBorder?: () => ReactElement;
} }
const Group = styled("div")` interface IGroupProps {
empty: boolean;
}
const Group = styled("div")<IGroupProps>`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: ${({ empty }) => (empty ? "center" : "flex-end")};
row-gap: ${({ theme }) => theme.spacing(1)};
`; `;
const GroupTitle = styled("h5")` const GroupTitle = styled("h5")`
@ -42,8 +47,9 @@ const RecordList = styled("div")`
width: 100%; width: 100%;
`; `;
const AddButton = styled(Button)` const AddButton = styled(IconButton)`
margin-top: ${({ theme }) => theme.spacing(1)}; margin-top: ${({ theme }) => theme.spacing(1)};
border-radius: ${({ theme }) => theme.spacing(2)};
`; `;
const Description = styled("p")` const Description = styled("p")`
@ -51,13 +57,13 @@ const Description = styled("p")`
text-align: center; text-align: center;
color: #7a7a7a; color: #7a7a7a;
font-size: 14px; font-size: 14px;
width: 100%;
`; `;
const Records: FunctionComponent<IRecordsProps> = ( const Records: FunctionComponent<IRecordsProps> = (
props: IRecordsProps props: IRecordsProps
): ReactElement => { ): ReactElement => {
const { const {
modal,
title, title,
referred, referred,
name, name,
@ -89,7 +95,7 @@ const Records: FunctionComponent<IRecordsProps> = (
const empty = items && items.length === 0; const empty = items && items.length === 0;
return ( return (
<Group> <Group empty={empty}>
<GroupTitle>{title}</GroupTitle> <GroupTitle>{title}</GroupTitle>
{!empty && ( {!empty && (
<RecordList> <RecordList>
@ -108,11 +114,11 @@ const Records: FunctionComponent<IRecordsProps> = (
))} ))}
</RecordList> </RecordList>
)} )}
{empty && <Description>No {referred}s.</Description>}
<AddButton size="sm" variant="plain" onClick={handleNew}> {empty && <Description>No items available</Description>}
<PlusIcon className="h-4 w-4 mr-2" />
New {referred} <AddButton size="sm" variant="soft" onClick={handleNew}>
<PlusIcon className="h-4 w-4" />
</AddButton> </AddButton>
</Group> </Group>
); );

Loading…
Cancel
Save