From 1a2e75228178119d30537cf4f0f7384c7e7bbe79 Mon Sep 17 00:00:00 2001 From: ajnart Date: Sun, 29 May 2022 10:45:49 +0200 Subject: [PATCH] :sparkles: Add categories! --- src/components/AppShelf/AddAppShelfItem.tsx | 36 ++++++- src/components/AppShelf/AppShelf.tsx | 100 ++++++++++++++------ src/components/AppShelf/AppShelfMenu.tsx | 5 +- src/tools/types.ts | 1 + 4 files changed, 111 insertions(+), 31 deletions(-) diff --git a/src/components/AppShelf/AddAppShelfItem.tsx b/src/components/AppShelf/AddAppShelfItem.tsx index b4734734a..f62c0952c 100644 --- a/src/components/AppShelf/AddAppShelfItem.tsx +++ b/src/components/AppShelf/AddAppShelfItem.tsx @@ -82,7 +82,6 @@ function MatchPort(name: string, form: any) { ]; // Match name with portmap key const port = portmap.find((p) => p.name === name); - console.log('port', port); if (port) { form.setFieldValue('url', `http://localhost:${port.value}`); } @@ -93,10 +92,19 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & const { config, setConfig } = useConfig(); const [isLoading, setLoading] = useState(false); + // Extract all the categories from the services in config + const categoryList = config.services.reduce((acc, cur) => { + if (cur.category && !acc.includes(cur.category)) { + acc.push(cur.category); + } + return acc; + }, [] as string[]); + const form = useForm({ initialValues: { id: props.id ?? uuidv4(), type: props.type ?? 'Other', + category: props.category ?? undefined, name: props.name ?? '', icon: props.icon ?? '/favicon.svg', url: props.url ?? '', @@ -126,6 +134,15 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & }, }); + // Try to set const hostname to new URL(form.values.url).hostname) + // If it fails, set it to the form.values.url + let hostname = form.values.url; + try { + hostname = new URL(form.values.url).origin; + } catch (e) { + // Do nothing + } + return ( <>
@@ -200,6 +217,21 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & data={ServiceTypeList} {...form.getInputProps('type')} /> +