From 9b08b6b595274aa8876eeb9e9d7601aaa4ed7a1f Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Tue, 16 Feb 2021 13:03:14 -0700 Subject: [PATCH] admin(ui): fix SearchableSelect, other tweaks --- resources/scripts/api/admin/nodes/getNodes.ts | 3 ++- .../components/admin/SubNavigation.tsx | 10 ++++----- .../components/admin/nodes/DatabaseSelect.tsx | 6 ++++- .../components/admin/nodes/LocationSelect.tsx | 6 ++++- .../admin/nodes/NodeSettingsContainer.tsx | 21 ++++++++++-------- .../components/elements/SearchableSelect.tsx | 22 +++++++++---------- 6 files changed, 40 insertions(+), 28 deletions(-) diff --git a/resources/scripts/api/admin/nodes/getNodes.ts b/resources/scripts/api/admin/nodes/getNodes.ts index 3e3fd5cb8..5d70dee4b 100644 --- a/resources/scripts/api/admin/nodes/getNodes.ts +++ b/resources/scripts/api/admin/nodes/getNodes.ts @@ -61,7 +61,8 @@ export const rawDataToNode = ({ attributes }: FractalResponseData): Node => ({ updatedAt: new Date(attributes.updated_at), relations: { - databaseHost: attributes.relationships?.database_host !== undefined ? rawDataToDatabase(attributes.relationships.database_host as FractalResponseData) : undefined, + // eslint-disable-next-line camelcase + databaseHost: attributes.relationships?.database_host !== undefined && attributes.relationships?.database_host.object !== 'null_resource' ? rawDataToDatabase(attributes.relationships.database_host as FractalResponseData) : undefined, location: attributes.relationships?.location !== undefined ? rawDataToLocation(attributes.relationships.location as FractalResponseData) : undefined, }, }); diff --git a/resources/scripts/components/admin/SubNavigation.tsx b/resources/scripts/components/admin/SubNavigation.tsx index 1ce12d408..d9a83a6dd 100644 --- a/resources/scripts/components/admin/SubNavigation.tsx +++ b/resources/scripts/components/admin/SubNavigation.tsx @@ -4,17 +4,17 @@ import styled from 'styled-components/macro'; import tw from 'twin.macro'; export const SubNavigation = styled.div` - ${tw`h-12 flex flex-row items-center border-b border-neutral-700 mb-4`}; + ${tw`flex flex-row items-center flex-shrink-0 h-12 mb-4 border-b border-neutral-700`}; & > div { - ${tw`h-full flex flex-col flex-shrink-0 justify-center`}; + ${tw`flex flex-col justify-center flex-shrink-0 h-full`}; & > a { - ${tw`h-full flex flex-row items-center text-neutral-300 border-t px-4`}; + ${tw`flex flex-row items-center h-full px-4 border-t text-neutral-300`}; border-top-color: transparent !important; & > svg { - ${tw`h-6 w-6 mr-2`}; + ${tw`w-6 h-6 mr-2`}; } & > span { @@ -22,7 +22,7 @@ export const SubNavigation = styled.div` } &:active, &.active { - ${tw`text-primary-300 border-b border-primary-300`}; + ${tw`border-b text-primary-300 border-primary-300`}; } } } diff --git a/resources/scripts/components/admin/nodes/DatabaseSelect.tsx b/resources/scripts/components/admin/nodes/DatabaseSelect.tsx index ac768735a..dc8871550 100644 --- a/resources/scripts/components/admin/nodes/DatabaseSelect.tsx +++ b/resources/scripts/components/admin/nodes/DatabaseSelect.tsx @@ -1,9 +1,12 @@ import React, { useState } from 'react'; +import { useFormikContext } from 'formik'; import { Database } from '@/api/admin/databases/getDatabases'; import searchDatabases from '@/api/admin/databases/searchDatabases'; import SearchableSelect, { Option } from '@/components/elements/SearchableSelect'; export default ({ selected }: { selected: Database | null }) => { + const context = useFormikContext(); + const [ database, setDatabase ] = useState(selected); const [ databases, setDatabases ] = useState([]); @@ -16,8 +19,9 @@ export default ({ selected }: { selected: Database | null }) => { }); }; - const onSelect = (database: Database) => { + const onSelect = (database: Database | null) => { setDatabase(database); + context.setFieldValue('databaseHostId', database?.id || null); }; const getSelectedText = (database: Database | null): string => { diff --git a/resources/scripts/components/admin/nodes/LocationSelect.tsx b/resources/scripts/components/admin/nodes/LocationSelect.tsx index 4f23c2069..1da1e5d04 100644 --- a/resources/scripts/components/admin/nodes/LocationSelect.tsx +++ b/resources/scripts/components/admin/nodes/LocationSelect.tsx @@ -1,9 +1,12 @@ import React, { useState } from 'react'; +import { useFormikContext } from 'formik'; import { Location } from '@/api/admin/locations/getLocations'; import searchLocations from '@/api/admin/locations/searchLocations'; import SearchableSelect, { Option } from '@/components/elements/SearchableSelect'; export default ({ selected }: { selected: Location | null }) => { + const context = useFormikContext(); + const [ location, setLocation ] = useState(selected); const [ locations, setLocations ] = useState([]); @@ -16,8 +19,9 @@ export default ({ selected }: { selected: Location | null }) => { }); }; - const onSelect = (location: Location) => { + const onSelect = (location: Location | null) => { setLocation(location); + context.setFieldValue('locationId', location?.id || null); }; const getSelectedText = (location: Location | null): string => { diff --git a/resources/scripts/components/admin/nodes/NodeSettingsContainer.tsx b/resources/scripts/components/admin/nodes/NodeSettingsContainer.tsx index 5df7e85d0..bd81ced4d 100644 --- a/resources/scripts/components/admin/nodes/NodeSettingsContainer.tsx +++ b/resources/scripts/components/admin/nodes/NodeSettingsContainer.tsx @@ -39,10 +39,13 @@ export default () => { ); } - const submit = ({ name, description, locationId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP }: Values, { setSubmitting }: FormikHelpers) => { + const submit = ({ name, description, locationId, databaseHostId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP }: Values, { setSubmitting }: FormikHelpers) => { clearFlashes('node'); - updateNode(node.id, { name, description, locationId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP }) + console.log(`Location ID: ${locationId}`); + console.log(`Database Host ID: ${databaseHostId || 'null'}`); + + updateNode(node.id, { name, description, locationId, databaseHostId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP }) .then(() => setNode({ ...node, name, description, locationId, fqdn, listenPortHTTP, publicPortHTTP, listenPortSFTP, publicPortSFTP })) .catch(error => { console.error(error); @@ -114,8 +117,8 @@ export default () => { /> -
-
+
+
{ />
-
+
{
-
-
+
+
{ />
-
+
{
-
+