fix: grid updates on other fields, reportErrorsAndSubmit fixes

pull/106/head
corpulent 3 years ago
parent efec86dec1
commit 9226684e3b

@ -6,13 +6,34 @@ const Root = styled("div")`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
row-gap: ${({ theme }) => theme.spacing(1)}; row-gap: ${({ theme }) => theme.spacing(1)};
@media (max-width: 640px) {
row-gap: 0;
}
`;
const Group = styled("div")`
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-column-gap: 0px;
grid-row-gap: 0px;
@media (max-width: 640px) {
grid-template-columns: repeat(1, 1fr);
}
column-gap: ${({ theme }) => theme.spacing(1)};
width: 100%;
`; `;
const General = () => { const General = () => {
return ( return (
<Root> <Root>
<Group>
<TextField label="Entry name" name="entryName" required={true} /> <TextField label="Entry name" name="entryName" required={true} />
</Group>
<Group>
<TextField label="Network name" name="networkName" required={true} /> <TextField label="Network name" name="networkName" required={true} />
</Group>
<Records <Records
name="labels" name="labels"
title="Labels" title="Labels"

@ -5,10 +5,24 @@ import TextField from "../../global/FormElements/TextField";
import { IFieldType } from "../../Record"; import { IFieldType } from "../../Record";
import Records from "../../Records"; import Records from "../../Records";
const Fields = styled("div")` const Root = styled("div")`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
row-gap: ${({ theme }) => theme.spacing(1)}; row-gap: ${({ theme }) => theme.spacing(1)};
@media (max-width: 640px) {
row-gap: 0;
}
`;
const Group = styled("div")`
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-column-gap: 0px;
grid-row-gap: 0px;
@media (max-width: 640px) {
grid-template-columns: repeat(1, 1fr);
}
column-gap: ${({ theme }) => theme.spacing(1)};
width: 100%; width: 100%;
`; `;
@ -44,8 +58,10 @@ const ConfigurationBorder = styled("div")`
const IPAM: FunctionComponent = (): ReactElement => { const IPAM: FunctionComponent = (): ReactElement => {
return ( return (
<Fields> <Root>
<Group>
<TextField label="Driver" name="driver" /> <TextField label="Driver" name="driver" />
</Group>
<Records <Records
name="configurations" name="configurations"
@ -150,7 +166,7 @@ const IPAM: FunctionComponent = (): ReactElement => {
<Field>{element}</Field> <Field>{element}</Field>
)} )}
/> />
</Fields> </Root>
); );
}; };

@ -38,7 +38,7 @@ const ListItem = styled("div")<IListItemProps>`
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
column-gap: ${({ theme }) => theme.spacing(2)}; column-gap: ${({ theme }) => theme.spacing(1)};
padding: ${({ theme }) => theme.spacing(1, 1, 1, 2)}; padding: ${({ theme }) => theme.spacing(1, 1, 1, 2)};
cursor: pointer; cursor: pointer;
background-color: ${({ selected }) => selected && "#f5f5f5"}; background-color: ${({ selected }) => selected && "#f5f5f5"};

@ -44,7 +44,6 @@ const Bottom = styled("div")`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
row-gap: ${({ theme }) => theme.spacing(1)}; row-gap: ${({ theme }) => theme.spacing(1)};
padding: ${({ theme }) => theme.spacing(0, 2)};
`; `;
const Accordion: FunctionComponent<IAccordionProps> = ( const Accordion: FunctionComponent<IAccordionProps> = (

@ -6,6 +6,9 @@ const Root = styled("div")`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
row-gap: ${({ theme }) => theme.spacing(1)}; row-gap: ${({ theme }) => theme.spacing(1)};
@media (max-width: 640px) {
row-gap: 0;
}
`; `;
const Build = () => { const Build = () => {
@ -15,7 +18,7 @@ const Build = () => {
<TextField label="Dockerfile" name="build.dockerfile" /> <TextField label="Dockerfile" name="build.dockerfile" />
<TextField label="Stage" name="build.stage" /> <TextField label="Target" name="build.target" />
<TextField label="Isolation" name="build.isolation" /> <TextField label="Isolation" name="build.isolation" />

@ -4,7 +4,10 @@ import Records from "../../Records";
const Root = styled("div")` const Root = styled("div")`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; row-gap: ${({ theme }) => theme.spacing(1)};
@media (max-width: 640px) {
row-gap: 0;
}
`; `;
const Volumes = () => { const Volumes = () => {

@ -9,6 +9,9 @@ const Root = styled("div")`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
row-gap: ${({ theme }) => theme.spacing(1)}; row-gap: ${({ theme }) => theme.spacing(1)};
@media (max-width: 640px) {
row-gap: 0;
}
`; `;
const Group = styled("div")` const Group = styled("div")`

@ -4,7 +4,10 @@ import Records from "../../Records";
const Root = styled("div")` const Root = styled("div")`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; row-gap: ${({ theme }) => theme.spacing(1)};
@media (max-width: 640px) {
row-gap: 0;
}
`; `;
const Environment = () => { const Environment = () => {

@ -14,7 +14,7 @@ const Root = styled("div")`
const Group = styled("div")` const Group = styled("div")`
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(2, 1fr);
grid-column-gap: 0px; grid-column-gap: 0px;
grid-row-gap: 0px; grid-row-gap: 0px;
@media (max-width: 640px) { @media (max-width: 640px) {
@ -52,11 +52,15 @@ const General = () => {
</Group> </Group>
<Group> <Group>
<SpanTwo>
<TextField label="Command" name="command" required={false} /> <TextField label="Command" name="command" required={false} />
</SpanTwo>
</Group> </Group>
<Group> <Group>
<SpanTwo>
<TextField label="Entrypoint" name="entrypoint" required={false} /> <TextField label="Entrypoint" name="entrypoint" required={false} />
</SpanTwo>
</Group> </Group>
<Group> <Group>

@ -7,13 +7,34 @@ const Root = styled("div")`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
row-gap: ${({ theme }) => theme.spacing(1)}; row-gap: ${({ theme }) => theme.spacing(1)};
@media (max-width: 640px) {
row-gap: 0;
}
`;
const Group = styled("div")`
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-column-gap: 0px;
grid-row-gap: 0px;
@media (max-width: 640px) {
grid-template-columns: repeat(1, 1fr);
}
column-gap: ${({ theme }) => theme.spacing(1)};
width: 100%;
`; `;
const General = () => { const General = () => {
return ( return (
<Root> <Root>
<Group>
<TextField label="Entry name" name="entryName" required={true} /> <TextField label="Entry name" name="entryName" required={true} />
</Group>
<Group>
<TextField label="Volume name" name="volumeName" required={true} /> <TextField label="Volume name" name="volumeName" required={true} />
</Group>
<Records <Records
name="labels" name="labels"
title="Labels" title="Labels"

@ -40,7 +40,7 @@ const Root = styled("div")`
flex-direction: row; flex-direction: row;
justify-content: flex-start; justify-content: flex-start;
align-items: flex-start; align-items: flex-start;
column-gap: ${({ theme }) => theme.spacing(2)}; column-gap: ${({ theme }) => theme.spacing(1)};
width: 100%; width: 100%;
@media (max-width: 768px) { @media (max-width: 768px) {

@ -35,19 +35,19 @@ const Group = styled("div", {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: ${({ empty }) => (empty ? "center" : "flex-end")}; align-items: ${({ empty }) => (empty ? "center" : "flex-end")};
row-gap: ${({ theme }) => theme.spacing(1)};
width: 100%; width: 100%;
@media (max-width: 640px) { @media (max-width: 640px) {
row-gap: 0; row-gap: 0;
} }
`; `;
const GroupTitle = styled("h5")` const GroupTitle = styled("label")`
font-size: 0.85rem; display: block;
color: #374151; font-size: 0.75rem;
line-height: 1rem;
font-weight: 700; font-weight: 700;
width: 100%; color: #374151;
text-align: left; padding: 0;
`; `;
const RecordList = styled("div")` const RecordList = styled("div")`
@ -56,7 +56,6 @@ const RecordList = styled("div")`
justify-content: center; justify-content: center;
align-items: center; align-items: center;
row-gap: ${({ theme }) => theme.spacing(1)}; row-gap: ${({ theme }) => theme.spacing(1)};
margin-top: ${({ theme }) => theme.spacing(1)};
width: 100%; width: 100%;
`; `;

@ -196,6 +196,35 @@ export const packArrayAsStrings = (
); );
}; };
const isObject = (value: any) => {
return !!(value && typeof value === "object" && !Array.isArray(value));
};
const digForString = (error: any[] | string) => {
if (lodash.isString(error) && /\s/.test(error)) {
toaster(error as string, "error");
return;
}
if (Array.isArray(error)) {
for (const message of error) {
digForString(message);
}
}
if (isObject(error)) {
for (const [_, value] of Object.entries(error)) {
if (Array.isArray(value)) {
digForString(value);
}
if (lodash.isString(value)) {
toaster(value as string, "error");
}
}
}
};
/** /**
* Formik is configured to validate fields automatically using Yup. * Formik is configured to validate fields automatically using Yup.
* The problem is Formik does not call `onSubmit` function when errors * The problem is Formik does not call `onSubmit` function when errors
@ -204,21 +233,9 @@ export const packArrayAsStrings = (
* function basically implements this. * function basically implements this.
*/ */
export const reportErrorsAndSubmit = (formik: any) => () => { export const reportErrorsAndSubmit = (formik: any) => () => {
const errors = Object.entries(formik.errors); const errors: [string, any][] = Object.entries(formik.errors);
if (errors.length > 0) { if (errors.length > 0) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars digForString(errors);
for (const [_field, message] of errors) {
if (Array.isArray(message)) {
message.forEach((m: object) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const [_, value] of Object.entries(m)) {
toaster(value as string, "error");
}
});
} else {
toaster(message as string, "error");
}
}
} else { } else {
formik.submitForm(); formik.submitForm();
} }

Loading…
Cancel
Save