From e70351cbad34992dbc7e51927cdafe4ff010b920 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Fri, 8 Jan 2021 15:34:55 -0700 Subject: [PATCH] admin(ui): implement MountEditContainer.tsx, minor tweaks --- .../scripts/api/admin/mounts/getMounts.ts | 2 +- .../scripts/api/admin/mounts/updateMount.ts | 2 +- resources/scripts/api/admin/nests/getNests.ts | 2 +- resources/scripts/api/admin/roles/getRoles.ts | 2 +- .../admin/mounts/MountEditContainer.tsx | 127 +++++++++++++++++- .../admin/nests/NestEditContainer.tsx | 15 ++- .../admin/nests/eggs/EggEditContainer.tsx | 9 +- .../admin/nodes/NodeEditContainer.tsx | 2 +- .../admin/roles/RoleEditContainer.tsx | 9 +- .../admin/servers/ServerEditContainer.tsx | 9 +- 10 files changed, 166 insertions(+), 13 deletions(-) diff --git a/resources/scripts/api/admin/mounts/getMounts.ts b/resources/scripts/api/admin/mounts/getMounts.ts index 0789809c0..a8c1b2917 100644 --- a/resources/scripts/api/admin/mounts/getMounts.ts +++ b/resources/scripts/api/admin/mounts/getMounts.ts @@ -6,7 +6,7 @@ export interface Mount { id: number; uuid: string; name: string; - description: string; + description?: string; source: string; target: string; readOnly: boolean; diff --git a/resources/scripts/api/admin/mounts/updateMount.ts b/resources/scripts/api/admin/mounts/updateMount.ts index b3472809f..f647c7132 100644 --- a/resources/scripts/api/admin/mounts/updateMount.ts +++ b/resources/scripts/api/admin/mounts/updateMount.ts @@ -1,7 +1,7 @@ import http from '@/api/http'; import { Mount, rawDataToMount } from '@/api/admin/mounts/getMounts'; -export default (id: number, name: string, description: string, source: string, target: string, readOnly: boolean, userMountable: boolean): Promise => { +export default (id: number, name: string, description: string | null, source: string, target: string, readOnly: boolean, userMountable: boolean): Promise => { return new Promise((resolve, reject) => { http.patch(`/api/application/mounts/${id}`, { name, description, source, target, read_only: readOnly, user_mountable: userMountable, diff --git a/resources/scripts/api/admin/nests/getNests.ts b/resources/scripts/api/admin/nests/getNests.ts index 32bc97d39..743698a6e 100644 --- a/resources/scripts/api/admin/nests/getNests.ts +++ b/resources/scripts/api/admin/nests/getNests.ts @@ -8,7 +8,7 @@ export interface Nest { uuid: string; author: string; name: string; - description: string | null; + description?: string; createdAt: Date; updatedAt: Date; diff --git a/resources/scripts/api/admin/roles/getRoles.ts b/resources/scripts/api/admin/roles/getRoles.ts index b928e04c6..479e9efa4 100644 --- a/resources/scripts/api/admin/roles/getRoles.ts +++ b/resources/scripts/api/admin/roles/getRoles.ts @@ -3,7 +3,7 @@ import http, { FractalResponseData } from '@/api/http'; export interface Role { id: number; name: string; - description: string | null; + description?: string; } export const rawDataToRole = ({ attributes }: FractalResponseData): Role => ({ diff --git a/resources/scripts/components/admin/mounts/MountEditContainer.tsx b/resources/scripts/components/admin/mounts/MountEditContainer.tsx index 0e992e18e..f33e3ce0a 100644 --- a/resources/scripts/components/admin/mounts/MountEditContainer.tsx +++ b/resources/scripts/components/admin/mounts/MountEditContainer.tsx @@ -8,6 +8,13 @@ import AdminContentBlock from '@/components/admin/AdminContentBlock'; import Spinner from '@/components/elements/Spinner'; import FlashMessageRender from '@/components/FlashMessageRender'; import { ApplicationStore } from '@/state'; +import { boolean, object, string } from 'yup'; +import updateMount from '@/api/admin/mounts/updateMount'; +import AdminBox from '@/components/admin/AdminBox'; +import Button from '@/components/elements/Button'; +import Field from '@/components/elements/Field'; +import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; +import { Form, Formik, FormikHelpers } from 'formik'; interface ctx { mount: Mount | undefined; @@ -22,6 +29,115 @@ export const Context = createContextStore({ }), }); +interface Values { + name: string; + description: string; + source: string; + target: string; + readOnly: boolean; + userMountable: boolean; +} + +const EditInformationContainer = () => { + const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); + const mount = Context.useStoreState(state => state.mount); + const setMount = Context.useStoreActions(actions => actions.setMount); + + if (mount === undefined) { + return ( + <> + ); + } + + const submit = ({ name, description, source, target, readOnly, userMountable }: Values, { setSubmitting }: FormikHelpers) => { + clearFlashes('nest'); + + updateMount(mount.id, name, description, source, target, readOnly, userMountable) + .then(() => setMount({ ...mount, name, description, source, target, readOnly, userMountable })) + .catch(error => { + console.error(error); + clearAndAddHttpError({ key: 'nest', error }); + }) + .then(() => setSubmitting(false)); + }; + + return ( + + { + ({ isSubmitting, isValid }) => ( + + + + +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+
+
+ ) + } +
+ ); +}; + const MountEditContainer = () => { const match = useRouteMatch<{ id?: string }>(); @@ -60,11 +176,20 @@ const MountEditContainer = () => {

{mount.name}

-

{mount.description}

+ { + (mount.description || '').length < 1 ? +

+ No description +

+ : +

{mount.description}

+ }
+ + ); }; diff --git a/resources/scripts/components/admin/nests/NestEditContainer.tsx b/resources/scripts/components/admin/nests/NestEditContainer.tsx index 792086701..c51e604be 100644 --- a/resources/scripts/components/admin/nests/NestEditContainer.tsx +++ b/resources/scripts/components/admin/nests/NestEditContainer.tsx @@ -56,7 +56,7 @@ export const Context = createContextStore({ interface Values { name: string; - description: string | null; + description: string; } const EditInformationContainer = () => { @@ -73,7 +73,7 @@ const EditInformationContainer = () => { const submit = ({ name, description }: Values, { setSubmitting }: FormikHelpers) => { clearFlashes('nest'); - updateNest(nest.id, name, description || undefined) + updateNest(nest.id, name, description) .then(() => setNest({ ...nest, name, description })) .catch(error => { console.error(error); @@ -87,7 +87,7 @@ const EditInformationContainer = () => { onSubmit={submit} initialValues={{ name: nest.name, - description: nest.description, + description: nest.description || '', }} validationSchema={object().shape({ name: string().required().min(1), @@ -251,7 +251,14 @@ const NestEditContainer = () => {

{nest.name}

-

{nest.description}

+ { + (nest.description || '').length < 1 ? +

+ No description +

+ : +

{nest.description}

+ }
diff --git a/resources/scripts/components/admin/nests/eggs/EggEditContainer.tsx b/resources/scripts/components/admin/nests/eggs/EggEditContainer.tsx index 8b6b8cf92..f7e231f54 100644 --- a/resources/scripts/components/admin/nests/eggs/EggEditContainer.tsx +++ b/resources/scripts/components/admin/nests/eggs/EggEditContainer.tsx @@ -59,7 +59,14 @@ const EggEditContainer = () => {

{egg.name}

-

{egg.description}

+ { + (egg.description || '').length < 1 ? +

+ No description +

+ : +

{egg.description}

+ }
diff --git a/resources/scripts/components/admin/nodes/NodeEditContainer.tsx b/resources/scripts/components/admin/nodes/NodeEditContainer.tsx index 4e5be99ea..756e32eb8 100644 --- a/resources/scripts/components/admin/nodes/NodeEditContainer.tsx +++ b/resources/scripts/components/admin/nodes/NodeEditContainer.tsx @@ -60,7 +60,7 @@ const NodeEditContainer = () => {

{node.name}

-

{node.description}

+

{node.uuid}

diff --git a/resources/scripts/components/admin/roles/RoleEditContainer.tsx b/resources/scripts/components/admin/roles/RoleEditContainer.tsx index dc3e68b43..7d5ef9ed0 100644 --- a/resources/scripts/components/admin/roles/RoleEditContainer.tsx +++ b/resources/scripts/components/admin/roles/RoleEditContainer.tsx @@ -60,7 +60,14 @@ const RoleEditContainer = () => {

{role.name}

-

{role.description}

+ { + (role.description || '').length < 1 ? +

+ No description +

+ : +

{role.description}

+ }
diff --git a/resources/scripts/components/admin/servers/ServerEditContainer.tsx b/resources/scripts/components/admin/servers/ServerEditContainer.tsx index a9af2950d..6af94987e 100644 --- a/resources/scripts/components/admin/servers/ServerEditContainer.tsx +++ b/resources/scripts/components/admin/servers/ServerEditContainer.tsx @@ -60,7 +60,14 @@ const ServerEditContainer = () => {

{server.name}

-

{server.description}

+ { + (server.description || '').length < 1 ? +

+ No description +

+ : +

{server.description}

+ }