From 14cd1b30fd5cd789e0a4a0d71b123d0905617283 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Thu, 30 Nov 2023 14:58:02 -0300 Subject: [PATCH] fix(storeContext.tsx): set initial value of hasStore to false instead of true to fix incorrect initial state fix(shareModal/index.tsx): import has function from lodash to fix missing import error fix(shareModal/index.tsx): add hasStore to the list of dependencies in useEffect to fix missing dependency warning fix(extraSidebarComponent/index.tsx): add hasStore to the list of dependencies in useEffect to fix missing dependency warning fix(extraSidebarComponent/index.tsx): disable share button if hasStore is false to prevent sharing without a store fix(extraSidebarComponent/index.tsx): disable share button in ShareModal if hasStore is false to prevent sharing without a store fix(extraSidebarComponent/index.tsx): disable share button in ShareModal if hasStore is false to prevent sharing without a store fix(nodeToolbarComponent/index.tsx): add hasStore to the list of dependencies to fix missing dependency warning fix(nodeToolbarComponent/index.tsx): disable share option in SelectItem if hasStore is false to prevent sharing without a store --- src/frontend/src/contexts/storeContext.tsx | 2 +- src/frontend/src/modals/shareModal/index.tsx | 6 ++--- .../extraSidebarComponent/index.tsx | 26 +++++++++++------- .../components/nodeToolbarComponent/index.tsx | 27 +++++++++++-------- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/frontend/src/contexts/storeContext.tsx b/src/frontend/src/contexts/storeContext.tsx index d9a3194c9..d78a5aa1b 100644 --- a/src/frontend/src/contexts/storeContext.tsx +++ b/src/frontend/src/contexts/storeContext.tsx @@ -17,7 +17,7 @@ const initialValue = { export const StoreContext = createContext(initialValue); export function StoreProvider({ children }) { - const [hasStore, setHasStore] = useState(true); + const [hasStore, setHasStore] = useState(false); const [loadingApiKey, setLoadingApiKey] = useState(true); const [hasApiKey, setHasApiKey] = useState(true); const [validApiKey, setValidApiKey] = useState(false); diff --git a/src/frontend/src/modals/shareModal/index.tsx b/src/frontend/src/modals/shareModal/index.tsx index 11dadca1e..d09d03122 100644 --- a/src/frontend/src/modals/shareModal/index.tsx +++ b/src/frontend/src/modals/shareModal/index.tsx @@ -33,7 +33,7 @@ export default function ShareModal({ disabled?: boolean; }): JSX.Element { const { version, addFlow } = useContext(FlowsContext); - const { hasApiKey } = useContext(StoreContext); + const { hasApiKey, hasStore } = useContext(StoreContext); const { setSuccessData, setErrorData } = useContext(alertContext); const [checked, setChecked] = useState(false); const [name, setName] = useState(component?.name ?? ""); @@ -51,12 +51,12 @@ export default function ShareModal({ useEffect(() => { if (open || internalOpen) { - if (hasApiKey) { + if (hasApiKey && hasStore) { handleGetTags(); handleGetNames(); } } - }, [open, internalOpen, hasApiKey]); + }, [open, internalOpen, hasApiKey, hasStore]); function handleGetTags() { setLoadingTags(true); diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index 83938c43c..d484030bc 100644 --- a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -30,7 +30,7 @@ export default function ExtraSidebar(): JSX.Element { useContext(typesContext); const { flows, tabId, uploadFlow, tabsState, saveFlow, isBuilt, version } = useContext(FlowsContext); - const { hasApiKey, validApiKey } = useContext(StoreContext); + const { hasApiKey, validApiKey, hasStore } = useContext(StoreContext); const { setErrorData } = useContext(alertContext); const [dataFilter, setFilterData] = useState(data); const [search, setSearch] = useState(""); @@ -183,17 +183,21 @@ export default function ExtraSidebar(): JSX.Element { () => !hasApiKey || !validApiKey ? ( @@ -201,26 +205,30 @@ export default function ExtraSidebar(): JSX.Element { ), - [hasApiKey, validApiKey, flow] + [hasApiKey, validApiKey, flow, hasStore] ); const ExportMemo = useMemo( diff --git a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx index 728db8948..2273db727 100644 --- a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx @@ -52,7 +52,7 @@ export default function NodeToolbarComponent({ ); const updateNodeInternals = useUpdateNodeInternals(); const { getNodeId } = useContext(FlowsContext); - const { hasApiKey, validApiKey } = useContext(StoreContext); + const { hasApiKey, validApiKey, hasStore } = useContext(StoreContext); function canMinimize() { let countHandles: number = 0; @@ -93,7 +93,7 @@ export default function NodeToolbarComponent({ downloadNode(createFlowComponent(cloneDeep(data), version)); break; case "Share": - if (hasApiKey) setShowconfirmShare(true); + if (hasApiKey || hasStore) setShowconfirmShare(true); break; case "SaveAll": saveComponent(cloneDeep(data), false); @@ -235,15 +235,20 @@ export default function NodeToolbarComponent({ )} - -
- {" "} - Share{" "} -
{" "} -
+ {hasStore && ( + +
+ {" "} + Share{" "} +
{" "} +
+ )}