From d73d0f0d2f7519b92bca752b5abfadeea63c297b Mon Sep 17 00:00:00 2001 From: Weixuan Fu Date: Sat, 17 Feb 2024 02:05:37 +0800 Subject: [PATCH] pass privacy settings to share api --- ui/src/components/CustomSelector.tsx | 44 +++++++++++++---- ui/src/components/DropdownTitle.tsx | 3 +- ui/src/components/HoverMenu.tsx | 49 ++++++++++++++++++ ui/src/share/ShareDialog.tsx | 74 ++++++---------------------- ui/src/share/SharedTopbarButton.tsx | 69 ++++++++++++++++++++------ ui/src/share/shareUtils.tsx | 45 +++++++++++++++++ ui/src/types/dbTypes.ts | 3 +- 7 files changed, 202 insertions(+), 85 deletions(-) create mode 100644 ui/src/components/HoverMenu.tsx create mode 100644 ui/src/share/shareUtils.tsx diff --git a/ui/src/components/CustomSelector.tsx b/ui/src/components/CustomSelector.tsx index 1261c2c..38d15c1 100644 --- a/ui/src/components/CustomSelector.tsx +++ b/ui/src/components/CustomSelector.tsx @@ -2,21 +2,25 @@ import React, { useState, useRef, useEffect } from "react"; import { Box, Button, Card } from "@chakra-ui/react"; import { IconChevronDown } from "@tabler/icons-react"; -export interface CustomSelectorOption { +export interface CustomSelectorOption { label: string; - value: string; + value: T; icon?: React.ReactElement; } -type Props = { - options: CustomSelectorOption[]; +type Props = { + options: CustomSelectorOption[]; + value: T; + onChange: (value: T) => void; }; -export default function CustomSelector({ options }: Props) { +export default function CustomSelector({ + options, + value, + onChange, +}: Props) { const [isOpen, setIsOpen] = useState(false); const ref = useRef(null); - const [selectedOption, setSelectedOption] = useState< - CustomSelectorOption | undefined - >(options[0]); + const selectedOption = options.find((option) => option.value === value); useEffect(() => { const handleClickOutside = (event: any) => { @@ -41,6 +45,25 @@ export default function CustomSelector({ options }: Props) { > {selectedOption?.label} + {/* {isOpen && ( + + + } + iconSpacing={1} + command={saveShortcut} + > + Save + + + + )} */} {isOpen && ( {options.map((option) => ( + { + window.open(workflowsTable?.curWorkflow?.cloudURL); + }} + aria-label={"Shared"} + size={"xs"} + iconSpacing={"2px"} + leftIcon={} + height={"26px"} + px={1} + > + Public + + } + menuContent={ + + + {cloudURL} + + } + aria-label="copy link" + > + + } + /> ); } diff --git a/ui/src/share/shareUtils.tsx b/ui/src/share/shareUtils.tsx new file mode 100644 index 0000000..4841dfc --- /dev/null +++ b/ui/src/share/shareUtils.tsx @@ -0,0 +1,45 @@ +import { IconLink, IconLock, IconWorld } from "@tabler/icons-react"; +import { CustomSelectorOption } from "../components/CustomSelector"; +import { WorkflowPrivacy } from "../types/dbTypes"; +// @ts-expect-error +import { app } from "/scripts/app.js"; + +export function generateRandomKey(length: number) { + // Generate a random array of bytes + const array = new Uint8Array(length); + window.crypto.getRandomValues(array); + + // Convert the bytes to a hex string + return Array.from(array, (byte) => byte.toString(16).padStart(2, "0")).join( + "", + ); +} + +export const privacyOptions: CustomSelectorOption[] = [ + { label: "Private", value: "PRIVATE", icon: }, + { + label: "Anyone with the link can access", + value: "UNLISTED", + icon: , + }, + { label: "Public", value: "PUBLIC", icon: }, +]; + +export const getNodeDefs = () => { + const allNodes = app.graph._nodes; + // console.log("allNodes", allNodes); + // console.log( + // "LiteGraph.registered_node_types", + // LiteGraph.registered_node_types, + // ); + const nodeDefs = {}; + for (let n of allNodes) { + // @ts-ignore + if (n.type in LiteGraph.registered_node_types) { + // TODO: js only nodes has no nodeData field, need to handle this.... + // @ts-ignore + nodeDefs[n.type] = LiteGraph.registered_node_types[n.type].nodeData; + } + } + return nodeDefs; +}; diff --git a/ui/src/types/dbTypes.ts b/ui/src/types/dbTypes.ts index 6406f7e..7543c11 100644 --- a/ui/src/types/dbTypes.ts +++ b/ui/src/types/dbTypes.ts @@ -16,7 +16,6 @@ export interface Workflow extends SortableItem { coverMediaPath?: string; cloudID?: string; cloudURL?: string; - privacy?: WorkflowPrivacy; } export interface TableBaseModel { @@ -121,6 +120,6 @@ export enum EFlowOperationType { DELETE = "delete", } -type WorkflowPrivacy = "PUBLIC" | "PRIVATE" | "UNLISTED"; +export type WorkflowPrivacy = "PUBLIC" | "PRIVATE" | "UNLISTED"; export const WORKSPACE_INDEXDB_NAME = "comfyui_workspace_db";