From a251035feefd3a5ee2d98d4b99b050d9a65d786e Mon Sep 17 00:00:00 2001 From: Weixuan Fu Date: Sat, 29 Jun 2024 13:06:50 +0800 Subject: [PATCH] remove backfill indexdb --- ui/src/components/DropdownTitle.tsx | 29 +++++++++- ui/src/db-tables/WorkspaceDB.ts | 82 ----------------------------- 2 files changed, 28 insertions(+), 83 deletions(-) diff --git a/ui/src/components/DropdownTitle.tsx b/ui/src/components/DropdownTitle.tsx index b9c51b3..85f8025 100644 --- a/ui/src/components/DropdownTitle.tsx +++ b/ui/src/components/DropdownTitle.tsx @@ -26,6 +26,7 @@ import { DarkMode, Tag, HStack, + useToast, } from "@chakra-ui/react"; import { IconArrowBackUpDouble, @@ -33,6 +34,7 @@ import { IconDeviceFloppy, IconDownload, IconHistory, + IconLink, IconShare2, IconVersions, } from "@tabler/icons-react"; @@ -83,7 +85,7 @@ export default function DropdownTitle() { setNewFlowName(event.target.value); submitError && setSubmitError(""); }; - + const toast = useToast(); const onSubmit = async () => { if (!curFlowID) { alert("Flow ID is required"); @@ -194,6 +196,31 @@ export default function DropdownTitle() { + { + const cloudHost = userSettingsTable?.settings?.cloudHost!; + + if (workflow?.cloudID) { + navigator.clipboard.writeText( + `${cloudHost}/workflow/${workflow.cloudID}`, + ); + toast({ + title: "Link copied", + status: "success", + duration: 2000, + }); + } else { + setIsOpenNewVersion(true); + } + }} + icon={} + iconSpacing={1} + alignItems={"center"} + > + +

Copy share link

+
+
} diff --git a/ui/src/db-tables/WorkspaceDB.ts b/ui/src/db-tables/WorkspaceDB.ts index 2dc0575..c29353d 100644 --- a/ui/src/db-tables/WorkspaceDB.ts +++ b/ui/src/db-tables/WorkspaceDB.ts @@ -61,86 +61,4 @@ export async function loadDBs() { loadMedia(), loadWorkflowVersions(), ]); - if (localStorage.getItem("WORKSPACE_INDEXDB_BACKFILL") !== "true") { - await backfillIndexdb(); - localStorage.setItem("WORKSPACE_INDEXDB_BACKFILL", "true"); - } -} - -export async function backfillIndexdb() { - const backfillWorkflows = async () => { - try { - const all = await workflowsTable?.getRecords(); - all && (await indexdb.workflows.bulkPut(Object.values(all))); - } catch (error) { - console.error(error); - } - }; - const backfillFolders = async () => { - try { - const all = await foldersTable?.getRecords(); - all && (await indexdb.folders.bulkPut(Object.values(all))); - } catch (error) { - console.error(error); - } - }; - const backfillMedia = async () => { - try { - const all = await mediaTable?.getRecords(); - all && (await indexdb.media.bulkPut(Object.values(all))); - } catch (error) { - console.error(error); - } - }; - const backfillChangelogs = async () => { - try { - const all = await changelogsTable?.getRecords(); - all && (await indexdb.changelogs.bulkPut(Object.values(all))); - } catch (error) { - console.error(error); - } - }; - const backfillTags = async () => { - try { - const all = await tagsTable?.getRecords(); - all && (await indexdb.tags.bulkPut(Object.values(all))); - } catch (error) { - console.error(error); - } - }; - const backfillUserSettings = async () => { - try { - const tableInstance = userSettingsTable!; - const backupData = await tableInstance.getRecords().then((data) => { - if (!data[tableInstance.DEFAULT_USER]) { - // legacy - return data; - } - return data[tableInstance.DEFAULT_USER]; - }); - await indexdb.userSettings.put({ - ...tableInstance.defaultSettings, - ...backupData, - }); - } catch (error) { - console.error(error); - } - }; - const backfillWorkflowVersions = async () => { - try { - const all = await workflowVersionsTable?.getRecords(); - all && (await indexdb.workflowVersions.bulkPut(Object.values(all))); - } catch (error) { - console.error(error); - } - }; - await Promise.all([ - backfillWorkflows(), - backfillFolders(), - backfillMedia(), - backfillChangelogs(), - backfillTags(), - backfillUserSettings(), - backfillWorkflowVersions(), - ]); }