added flows variable and current flow and state to zustand
This commit is contained in:
parent
6195acee22
commit
118e425d68
18 changed files with 99 additions and 89 deletions
|
|
@ -48,6 +48,7 @@ import {
|
||||||
} from "../../../../utils/styleUtils";
|
} from "../../../../utils/styleUtils";
|
||||||
import { classNames, groupByFamily } from "../../../../utils/utils";
|
import { classNames, groupByFamily } from "../../../../utils/utils";
|
||||||
import { useTypesStore } from "../../../../stores/typesStore";
|
import { useTypesStore } from "../../../../stores/typesStore";
|
||||||
|
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
||||||
|
|
||||||
export default function ParameterComponent({
|
export default function ParameterComponent({
|
||||||
left,
|
left,
|
||||||
|
|
@ -69,12 +70,12 @@ export default function ParameterComponent({
|
||||||
const refHtml = useRef<HTMLDivElement & ReactNode>(null);
|
const refHtml = useRef<HTMLDivElement & ReactNode>(null);
|
||||||
const infoHtml = useRef<HTMLDivElement & ReactNode>(null);
|
const infoHtml = useRef<HTMLDivElement & ReactNode>(null);
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const { tabId, flows } = useContext(FlowsContext);
|
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
||||||
const nodes = useFlowStore((state) => state.nodes);
|
const nodes = useFlowStore((state) => state.nodes);
|
||||||
const edges = useFlowStore((state) => state.edges);
|
const edges = useFlowStore((state) => state.edges);
|
||||||
const setNode = useFlowStore((state) => state.setNode);
|
const setNode = useFlowStore((state) => state.setNode);
|
||||||
|
|
||||||
const flow = flows.find((flow) => flow.id === tabId)?.data?.nodes ?? null;
|
const flow = currentFlow?.data?.nodes ?? null;
|
||||||
|
|
||||||
const groupedEdge = useRef(null);
|
const groupedEdge = useRef(null);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,13 @@ import { useNavigate } from "react-router-dom";
|
||||||
import { undoRedoContext } from "../../../../contexts/undoRedoContext";
|
import { undoRedoContext } from "../../../../contexts/undoRedoContext";
|
||||||
import FlowSettingsModal from "../../../../modals/flowSettingsModal";
|
import FlowSettingsModal from "../../../../modals/flowSettingsModal";
|
||||||
import useAlertStore from "../../../../stores/alertStore";
|
import useAlertStore from "../../../../stores/alertStore";
|
||||||
import { menuBarPropsType } from "../../../../types/components";
|
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
||||||
import IconComponent from "../../../genericIconComponent";
|
import IconComponent from "../../../genericIconComponent";
|
||||||
import { Button } from "../../../ui/button";
|
import { Button } from "../../../ui/button";
|
||||||
|
|
||||||
export const MenuBar = ({ flows, tabId }: menuBarPropsType): JSX.Element => {
|
export const MenuBar = (): JSX.Element => {
|
||||||
const { addFlow } = useContext(FlowsContext);
|
const { addFlow } = useContext(FlowsContext);
|
||||||
|
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const { undo, redo } = useContext(undoRedoContext);
|
const { undo, redo } = useContext(undoRedoContext);
|
||||||
const [openSettings, setOpenSettings] = useState(false);
|
const [openSettings, setOpenSettings] = useState(false);
|
||||||
|
|
@ -34,9 +35,8 @@ export const MenuBar = ({ flows, tabId }: menuBarPropsType): JSX.Element => {
|
||||||
setErrorData(err as { title: string; list?: Array<string> });
|
setErrorData(err as { title: string; list?: Array<string> });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let current_flow = flows.find((flow) => flow.id === tabId);
|
|
||||||
|
|
||||||
return (
|
return currentFlow ? (
|
||||||
<div className="round-button-div">
|
<div className="round-button-div">
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|
@ -51,7 +51,7 @@ export const MenuBar = ({ flows, tabId }: menuBarPropsType): JSX.Element => {
|
||||||
<Button asChild variant="primary" size="sm">
|
<Button asChild variant="primary" size="sm">
|
||||||
<div className="header-menu-bar-display">
|
<div className="header-menu-bar-display">
|
||||||
<div className="header-menu-flow-name">
|
<div className="header-menu-flow-name">
|
||||||
{current_flow!.name}
|
{currentFlow.name}
|
||||||
</div>
|
</div>
|
||||||
<IconComponent name="ChevronDown" className="h-4 w-4" />
|
<IconComponent name="ChevronDown" className="h-4 w-4" />
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -108,6 +108,8 @@ export const MenuBar = ({ flows, tabId }: menuBarPropsType): JSX.Element => {
|
||||||
></FlowSettingsModal>
|
></FlowSettingsModal>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ import {
|
||||||
} from "../ui/dropdown-menu";
|
} from "../ui/dropdown-menu";
|
||||||
import { Separator } from "../ui/separator";
|
import { Separator } from "../ui/separator";
|
||||||
import MenuBar from "./components/menuBar";
|
import MenuBar from "./components/menuBar";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
|
|
||||||
export default function Header(): JSX.Element {
|
export default function Header(): JSX.Element {
|
||||||
const { flows, tabId } = useContext(FlowsContext);
|
|
||||||
const notificationCenter = useAlertStore((state) => state.notificationCenter);
|
const notificationCenter = useAlertStore((state) => state.notificationCenter);
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { logout, autoLogin, isAdmin, userData } = useContext(AuthContext);
|
const { logout, autoLogin, isAdmin, userData } = useContext(AuthContext);
|
||||||
|
|
@ -52,10 +52,7 @@ export default function Header(): JSX.Element {
|
||||||
<Link to="/">
|
<Link to="/">
|
||||||
<span className="ml-4 text-2xl">⛓️</span>
|
<span className="ml-4 text-2xl">⛓️</span>
|
||||||
</Link>
|
</Link>
|
||||||
|
<MenuBar />
|
||||||
{flows.findIndex((f) => tabId === f.id) !== -1 && tabId !== "" && (
|
|
||||||
<MenuBar flows={flows} tabId={tabId} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="round-button-div">
|
<div className="round-button-div">
|
||||||
<Link to="/">
|
<Link to="/">
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { uploadFile } from "../../controllers/API";
|
||||||
import useAlertStore from "../../stores/alertStore";
|
import useAlertStore from "../../stores/alertStore";
|
||||||
import { FileComponentType } from "../../types/components";
|
import { FileComponentType } from "../../types/components";
|
||||||
import IconComponent from "../genericIconComponent";
|
import IconComponent from "../genericIconComponent";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
|
|
||||||
export default function InputFileComponent({
|
export default function InputFileComponent({
|
||||||
value,
|
value,
|
||||||
|
|
@ -13,10 +14,10 @@ export default function InputFileComponent({
|
||||||
onFileChange,
|
onFileChange,
|
||||||
editNode = false,
|
editNode = false,
|
||||||
}: FileComponentType): JSX.Element {
|
}: FileComponentType): JSX.Element {
|
||||||
|
const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
|
||||||
const [myValue, setMyValue] = useState(value);
|
const [myValue, setMyValue] = useState(value);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const { tabId } = useContext(FlowsContext);
|
|
||||||
|
|
||||||
// Clear component state
|
// Clear component state
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -58,7 +59,7 @@ export default function InputFileComponent({
|
||||||
// Check if the file type is correct
|
// Check if the file type is correct
|
||||||
if (file && checkFileType(file.name)) {
|
if (file && checkFileType(file.name)) {
|
||||||
// Upload the file
|
// Upload the file
|
||||||
uploadFile(file, tabId)
|
uploadFile(file, currentFlowId)
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.log("File uploaded successfully");
|
console.log("File uploaded successfully");
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import {
|
||||||
} from "../types/typesContext";
|
} from "../types/typesContext";
|
||||||
import { isWrappedWithClass } from "../utils/utils";
|
import { isWrappedWithClass } from "../utils/utils";
|
||||||
import { FlowsContext } from "./flowsContext";
|
import { FlowsContext } from "./flowsContext";
|
||||||
|
import useFlowsManagerStore from "../stores/flowsManagerStore";
|
||||||
|
|
||||||
const initialValue = {
|
const initialValue = {
|
||||||
undo: () => {},
|
undo: () => {},
|
||||||
|
|
@ -29,7 +30,8 @@ const defaultOptions: UseUndoRedoOptions = {
|
||||||
export const undoRedoContext = createContext<undoRedoContextType>(initialValue);
|
export const undoRedoContext = createContext<undoRedoContextType>(initialValue);
|
||||||
|
|
||||||
export function UndoRedoProvider({ children }) {
|
export function UndoRedoProvider({ children }) {
|
||||||
const { tabId, flows } = useContext(FlowsContext);
|
const flows = useFlowsManagerStore((state) => state.flows);
|
||||||
|
const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
|
||||||
|
|
||||||
const setNodes = useFlowStore((state) => state.setNodes);
|
const setNodes = useFlowStore((state) => state.setNodes);
|
||||||
const setEdges = useFlowStore((state) => state.setEdges);
|
const setEdges = useFlowStore((state) => state.setEdges);
|
||||||
|
|
@ -39,7 +41,7 @@ export function UndoRedoProvider({ children }) {
|
||||||
const [past, setPast] = useState<HistoryItem[][]>(flows.map(() => []));
|
const [past, setPast] = useState<HistoryItem[][]>(flows.map(() => []));
|
||||||
const [future, setFuture] = useState<HistoryItem[][]>(flows.map(() => []));
|
const [future, setFuture] = useState<HistoryItem[][]>(flows.map(() => []));
|
||||||
const [tabIndex, setTabIndex] = useState(
|
const [tabIndex, setTabIndex] = useState(
|
||||||
flows.findIndex((flow) => flow.id === tabId)
|
flows.findIndex((flow) => flow.id === currentFlowId)
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -50,8 +52,8 @@ export function UndoRedoProvider({ children }) {
|
||||||
setFuture((old) =>
|
setFuture((old) =>
|
||||||
flows.map((flow, index) => (old[index] ? old[index] : []))
|
flows.map((flow, index) => (old[index] ? old[index] : []))
|
||||||
);
|
);
|
||||||
setTabIndex(flows.findIndex((flow) => flow.id === tabId));
|
setTabIndex(flows.findIndex((flow) => flow.id === currentFlowId));
|
||||||
}, [flows, tabId]);
|
}, [flows, currentFlowId]);
|
||||||
|
|
||||||
const takeSnapshot = useCallback(() => {
|
const takeSnapshot = useCallback(() => {
|
||||||
// push the current graph to the past state
|
// push the current graph to the past state
|
||||||
|
|
@ -79,7 +81,7 @@ export function UndoRedoProvider({ children }) {
|
||||||
newFuture[tabIndex] = [];
|
newFuture[tabIndex] = [];
|
||||||
return newFuture;
|
return newFuture;
|
||||||
});
|
});
|
||||||
}, [nodes, edges, past, future, flows, tabId, setPast, setFuture]);
|
}, [nodes, edges, past, future, flows, currentFlowId, setPast, setFuture]);
|
||||||
|
|
||||||
const undo = useCallback(() => {
|
const undo = useCallback(() => {
|
||||||
// get the last state that we want to go back to
|
// get the last state that we want to go back to
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,21 @@ import useAlertStore from "../../stores/alertStore";
|
||||||
import { removeApiKeys } from "../../utils/reactflowUtils";
|
import { removeApiKeys } from "../../utils/reactflowUtils";
|
||||||
import BaseModal from "../baseModal";
|
import BaseModal from "../baseModal";
|
||||||
import { useDarkStore } from "../../stores/darkStore";
|
import { useDarkStore } from "../../stores/darkStore";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
|
|
||||||
const ExportModal = forwardRef(
|
const ExportModal = forwardRef(
|
||||||
(props: { children: ReactNode }, ref): JSX.Element => {
|
(props: { children: ReactNode }, ref): JSX.Element => {
|
||||||
const { flows, tabId, downloadFlow } = useContext(FlowsContext);
|
const { downloadFlow } = useContext(FlowsContext);
|
||||||
const version = useDarkStore((state) => state.version);
|
const version = useDarkStore((state) => state.version);
|
||||||
const setNoticeData = useAlertStore((state) => state.setNoticeData);
|
const setNoticeData = useAlertStore((state) => state.setNoticeData);
|
||||||
const [checked, setChecked] = useState(true);
|
const [checked, setChecked] = useState(true);
|
||||||
const flow = flows.find((f) => f.id === tabId);
|
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setName(flow!.name);
|
setName(currentFlow!.name);
|
||||||
setDescription(flow!.description);
|
setDescription(currentFlow!.description);
|
||||||
}, [flow!.name, flow!.description]);
|
}, [currentFlow!.name, currentFlow!.description]);
|
||||||
const [name, setName] = useState(flow!.name);
|
const [name, setName] = useState(currentFlow!.name);
|
||||||
const [description, setDescription] = useState(flow!.description);
|
const [description, setDescription] = useState(currentFlow!.description);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -67,8 +68,8 @@ const ExportModal = forwardRef(
|
||||||
if (checked) {
|
if (checked) {
|
||||||
downloadFlow(
|
downloadFlow(
|
||||||
{
|
{
|
||||||
id: tabId,
|
id: currentFlow!.id,
|
||||||
data: flow!.data!,
|
data: currentFlow!.data!,
|
||||||
description,
|
description,
|
||||||
name,
|
name,
|
||||||
last_tested_version: version,
|
last_tested_version: version,
|
||||||
|
|
@ -84,8 +85,8 @@ const ExportModal = forwardRef(
|
||||||
} else
|
} else
|
||||||
downloadFlow(
|
downloadFlow(
|
||||||
removeApiKeys({
|
removeApiKeys({
|
||||||
id: tabId,
|
id: currentFlow!.id,
|
||||||
data: flow!.data!,
|
data: currentFlow!.data!,
|
||||||
description,
|
description,
|
||||||
name,
|
name,
|
||||||
last_tested_version: version,
|
last_tested_version: version,
|
||||||
|
|
|
||||||
|
|
@ -7,26 +7,27 @@ import { FlowsContext } from "../../contexts/flowsContext";
|
||||||
import { FlowSettingsPropsType } from "../../types/components";
|
import { FlowSettingsPropsType } from "../../types/components";
|
||||||
import { FlowType } from "../../types/flow";
|
import { FlowType } from "../../types/flow";
|
||||||
import BaseModal from "../baseModal";
|
import BaseModal from "../baseModal";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
|
|
||||||
export default function FlowSettingsModal({
|
export default function FlowSettingsModal({
|
||||||
open,
|
open,
|
||||||
setOpen,
|
setOpen,
|
||||||
}: FlowSettingsPropsType): JSX.Element {
|
}: FlowSettingsPropsType): JSX.Element {
|
||||||
const { flows, tabId, saveFlow } = useContext(FlowsContext);
|
const { saveFlow } = useContext(FlowsContext);
|
||||||
const flow = flows.find((f) => f.id === tabId);
|
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
||||||
|
const flows = useFlowsManagerStore((state) => state.flows);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setName(flow!.name);
|
setName(currentFlow!.name);
|
||||||
setDescription(flow!.description);
|
setDescription(currentFlow!.description);
|
||||||
}, [flow!.name, flow!.description, open]);
|
}, [currentFlow!.name, currentFlow!.description, open]);
|
||||||
|
|
||||||
const [name, setName] = useState(flow!.name);
|
const [name, setName] = useState(currentFlow!.name);
|
||||||
const [description, setDescription] = useState(flow!.description);
|
const [description, setDescription] = useState(currentFlow!.description);
|
||||||
|
|
||||||
function handleClick(): void {
|
function handleClick(): void {
|
||||||
let savedFlow = flows.find((flow) => flow.id === tabId);
|
currentFlow!.name = name;
|
||||||
savedFlow!.name = name;
|
currentFlow!.description = description;
|
||||||
savedFlow!.description = description;
|
saveFlow(currentFlow!);
|
||||||
saveFlow(savedFlow!);
|
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,7 +38,7 @@ export default function FlowSettingsModal({
|
||||||
flows.forEach((flow: FlowType) => {
|
flows.forEach((flow: FlowType) => {
|
||||||
if ((flow.is_component ?? false) === false) tempNameList.push(flow.name);
|
if ((flow.is_component ?? false) === false) tempNameList.push(flow.name);
|
||||||
});
|
});
|
||||||
setNameList(tempNameList.filter((name) => name !== flow!.name));
|
setNameList(tempNameList.filter((name) => name !== currentFlow!.name));
|
||||||
}, [flows]);
|
}, [flows]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -58,7 +59,7 @@ export default function FlowSettingsModal({
|
||||||
|
|
||||||
<BaseModal.Footer>
|
<BaseModal.Footer>
|
||||||
<Button
|
<Button
|
||||||
disabled={nameLists.includes(name) && name !== flow!.name}
|
disabled={nameLists.includes(name) && name !== currentFlow!.name}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
type="submit"
|
type="submit"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ export default function ShareModal({
|
||||||
const [unavaliableNames, setUnavaliableNames] = useState<
|
const [unavaliableNames, setUnavaliableNames] = useState<
|
||||||
{ id: string; name: string }[]
|
{ id: string; name: string }[]
|
||||||
>([]);
|
>([]);
|
||||||
const { saveFlow, flows, tabId } = useContext(FlowsContext);
|
const { saveFlow } = useContext(FlowsContext);
|
||||||
|
|
||||||
const [loadingNames, setLoadingNames] = useState(false);
|
const [loadingNames, setLoadingNames] = useState(false);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import UserManagementModal from "../../modals/UserManagementModal";
|
||||||
import useAlertStore from "../../stores/alertStore";
|
import useAlertStore from "../../stores/alertStore";
|
||||||
import { Users } from "../../types/api";
|
import { Users } from "../../types/api";
|
||||||
import { UserInputType } from "../../types/components";
|
import { UserInputType } from "../../types/components";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
|
|
||||||
export default function AdminPage() {
|
export default function AdminPage() {
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
|
|
@ -44,12 +45,11 @@ export default function AdminPage() {
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const { userData } = useContext(AuthContext);
|
const { userData } = useContext(AuthContext);
|
||||||
const [totalRowsCount, setTotalRowsCount] = useState(0);
|
const [totalRowsCount, setTotalRowsCount] = useState(0);
|
||||||
|
const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId);
|
||||||
const { setTabId } = useContext(FlowsContext);
|
|
||||||
|
|
||||||
// set null id
|
// set null id
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTabId("");
|
setCurrentFlowId("");
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const userList = useRef([]);
|
const userList = useRef([]);
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,15 @@ import {
|
||||||
import DisclosureComponent from "../DisclosureComponent";
|
import DisclosureComponent from "../DisclosureComponent";
|
||||||
import SidebarDraggableComponent from "./sideBarDraggableComponent";
|
import SidebarDraggableComponent from "./sideBarDraggableComponent";
|
||||||
import { useTypesStore } from "../../../../stores/typesStore";
|
import { useTypesStore } from "../../../../stores/typesStore";
|
||||||
|
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
||||||
|
|
||||||
export default function ExtraSidebar(): JSX.Element {
|
export default function ExtraSidebar(): JSX.Element {
|
||||||
const data = useTypesStore((state) => state.data);
|
const data = useTypesStore((state) => state.data);
|
||||||
const templates = useTypesStore((state) => state.templates);
|
const templates = useTypesStore((state) => state.templates);
|
||||||
const getFilterEdge = useTypesStore((state) => state.getFilterEdge);
|
const getFilterEdge = useTypesStore((state) => state.getFilterEdge);
|
||||||
const setFilterEdge = useTypesStore((state) => state.setFilterEdge);
|
const setFilterEdge = useTypesStore((state) => state.setFilterEdge);
|
||||||
const { flows, tabId, uploadFlow, saveFlow } = useContext(FlowsContext);
|
const { uploadFlow, saveFlow } = useContext(FlowsContext);
|
||||||
|
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
||||||
const hasStore = useStoreStore((state) => state.hasStore);
|
const hasStore = useStoreStore((state) => state.hasStore);
|
||||||
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
||||||
const validApiKey = useStoreStore((state) => state.validApiKey);
|
const validApiKey = useStoreStore((state) => state.validApiKey);
|
||||||
|
|
@ -79,7 +80,7 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const flow = flows.find((flow) => flow.id === tabId);
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// show components with error on load
|
// show components with error on load
|
||||||
let errors: string[] = [];
|
let errors: string[] = [];
|
||||||
|
|
@ -194,7 +195,7 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
() => (
|
() => (
|
||||||
<ShareModal
|
<ShareModal
|
||||||
is_component={false}
|
is_component={false}
|
||||||
component={flow!}
|
component={currentFlow!}
|
||||||
disabled={!hasApiKey || !validApiKey || !hasStore}
|
disabled={!hasApiKey || !validApiKey || !hasStore}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
|
|
@ -219,7 +220,7 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
</button>
|
</button>
|
||||||
</ShareModal>
|
</ShareModal>
|
||||||
),
|
),
|
||||||
[hasApiKey, validApiKey, flow, hasStore]
|
[hasApiKey, validApiKey, currentFlow, hasStore]
|
||||||
);
|
);
|
||||||
|
|
||||||
const ExportMemo = useMemo(
|
const ExportMemo = useMemo(
|
||||||
|
|
@ -273,8 +274,8 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
{(!hasApiKey || !validApiKey) && ExportMemo}
|
{(!hasApiKey || !validApiKey) && ExportMemo}
|
||||||
<ShadTooltip content={"Code"} side="top">
|
<ShadTooltip content={"Code"} side="top">
|
||||||
<div className="side-bar-button">
|
<div className="side-bar-button">
|
||||||
{flow && flow.data && (
|
{currentFlow && currentFlow.data && (
|
||||||
<ApiModal flow={flow}>
|
<ApiModal flow={currentFlow}>
|
||||||
<button
|
<button
|
||||||
className={"w-full " + (!isBuilt ? "button-disable" : "")}
|
className={"w-full " + (!isBuilt ? "button-disable" : "")}
|
||||||
>
|
>
|
||||||
|
|
@ -293,7 +294,7 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
</div>
|
</div>
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
<div className="side-bar-button" data-testid="save-button">
|
<div className="side-bar-button" data-testid="save-button">
|
||||||
{flow && flow.data && (
|
{currentFlow && currentFlow.data && (
|
||||||
<ShadTooltip content="Save" side="top">
|
<ShadTooltip content="Save" side="top">
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,28 @@
|
||||||
import { useContext, useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import Header from "../../components/headerComponent";
|
import Header from "../../components/headerComponent";
|
||||||
import { FlowsContext } from "../../contexts/flowsContext";
|
|
||||||
import Page from "./components/PageComponent";
|
|
||||||
import { useDarkStore } from "../../stores/darkStore";
|
import { useDarkStore } from "../../stores/darkStore";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
|
import Page from "./components/PageComponent";
|
||||||
|
|
||||||
export default function FlowPage(): JSX.Element {
|
export default function FlowPage(): JSX.Element {
|
||||||
const { flows, tabId, setTabId } = useContext(FlowsContext);
|
const setCurrentFlowId = useFlowsManagerStore(
|
||||||
|
(state) => state.setCurrentFlowId
|
||||||
|
);
|
||||||
const version = useDarkStore((state) => state.version);
|
const version = useDarkStore((state) => state.version);
|
||||||
|
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
// Set flow tab id
|
// Set flow tab id
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTabId(id!);
|
setCurrentFlowId(id!);
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Header />
|
<Header />
|
||||||
<div className="flow-page-positioning">
|
<div className="flow-page-positioning">
|
||||||
{flows.length > 0 &&
|
{currentFlow && <Page flow={currentFlow} />}
|
||||||
tabId !== "" &&
|
|
||||||
flows.findIndex((flow) => flow.id === tabId) !== -1 && (
|
|
||||||
<Page flow={flows.find((flow) => flow.id === tabId)!} />
|
|
||||||
)}
|
|
||||||
<a
|
<a
|
||||||
target={"_blank"}
|
target={"_blank"}
|
||||||
href="https://logspace.ai/"
|
href="https://logspace.ai/"
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,13 @@ import { Button } from "../../components/ui/button";
|
||||||
import { USER_PROJECTS_HEADER } from "../../constants/constants";
|
import { USER_PROJECTS_HEADER } from "../../constants/constants";
|
||||||
import { FlowsContext } from "../../contexts/flowsContext";
|
import { FlowsContext } from "../../contexts/flowsContext";
|
||||||
import useAlertStore from "../../stores/alertStore";
|
import useAlertStore from "../../stores/alertStore";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
export default function HomePage(): JSX.Element {
|
export default function HomePage(): JSX.Element {
|
||||||
const { setTabId, downloadFlows, uploadFlows, addFlow, uploadFlow } =
|
const { downloadFlows, uploadFlows, addFlow, uploadFlow } =
|
||||||
useContext(FlowsContext);
|
useContext(FlowsContext);
|
||||||
|
const setCurrentFlowId = useFlowsManagerStore(
|
||||||
|
(state) => state.setCurrentFlowId
|
||||||
|
);
|
||||||
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
@ -57,7 +61,7 @@ export default function HomePage(): JSX.Element {
|
||||||
|
|
||||||
// Set a null id
|
// Set a null id
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTabId("");
|
setCurrentFlowId("");
|
||||||
}, [pathname]);
|
}, [pathname]);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@ import {
|
||||||
patchUserInputStateType,
|
patchUserInputStateType,
|
||||||
} from "../../types/components";
|
} from "../../types/components";
|
||||||
import { gradients } from "../../utils/styleUtils";
|
import { gradients } from "../../utils/styleUtils";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
export default function ProfileSettingsPage(): JSX.Element {
|
export default function ProfileSettingsPage(): JSX.Element {
|
||||||
const { setTabId } = useContext(FlowsContext);
|
const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId);
|
||||||
|
|
||||||
const [inputState, setInputState] = useState<patchUserInputStateType>(
|
const [inputState, setInputState] = useState<patchUserInputStateType>(
|
||||||
CONTROL_PATCH_USER_STATE
|
CONTROL_PATCH_USER_STATE
|
||||||
|
|
@ -25,7 +26,7 @@ export default function ProfileSettingsPage(): JSX.Element {
|
||||||
|
|
||||||
// set null id
|
// set null id
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTabId("");
|
setCurrentFlowId("");
|
||||||
}, []);
|
}, []);
|
||||||
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import useAlertStore from "../../stores/alertStore";
|
||||||
import { useStoreStore } from "../../stores/storeStore";
|
import { useStoreStore } from "../../stores/storeStore";
|
||||||
import { storeComponent } from "../../types/store";
|
import { storeComponent } from "../../types/store";
|
||||||
import { cn } from "../../utils/utils";
|
import { cn } from "../../utils/utils";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
|
|
||||||
export default function StorePage(): JSX.Element {
|
export default function StorePage(): JSX.Element {
|
||||||
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
const hasApiKey = useStoreStore((state) => state.hasApiKey);
|
||||||
|
|
@ -45,7 +46,7 @@ export default function StorePage(): JSX.Element {
|
||||||
const { apiKey } = useContext(AuthContext);
|
const { apiKey } = useContext(AuthContext);
|
||||||
|
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const { setTabId } = useContext(FlowsContext);
|
const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [loadingTags, setLoadingTags] = useState(true);
|
const [loadingTags, setLoadingTags] = useState(true);
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
@ -166,7 +167,7 @@ export default function StorePage(): JSX.Element {
|
||||||
|
|
||||||
// Set a null id
|
// Set a null id
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTabId("");
|
setCurrentFlowId("");
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function resetPagination() {
|
function resetPagination() {
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,22 @@
|
||||||
import { useContext, useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { FlowsContext } from "../../contexts/flowsContext";
|
|
||||||
import Page from "../FlowPage/components/PageComponent";
|
import Page from "../FlowPage/components/PageComponent";
|
||||||
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
|
|
||||||
export default function ViewPage() {
|
export default function ViewPage() {
|
||||||
const { flows, tabId, setTabId } = useContext(FlowsContext);
|
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
||||||
|
const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId);
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
// Set flow tab id
|
// Set flow tab id
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTabId(id!);
|
setCurrentFlowId(id!);
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flow-page-positioning">
|
<div className="flow-page-positioning">
|
||||||
{flows.length > 0 &&
|
{currentFlow && (
|
||||||
tabId !== "" &&
|
<Page view flow={currentFlow} />
|
||||||
flows.findIndex((flow) => flow.id === tabId) !== -1 && (
|
|
||||||
<Page view flow={flows.find((flow) => flow.id === tabId)!} />
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,23 @@ import { FlowState } from "../types/tabs";
|
||||||
|
|
||||||
const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
|
const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
|
||||||
currentFlowId: "",
|
currentFlowId: "",
|
||||||
|
setCurrentFlowId: (currentFlowId: string) => {
|
||||||
|
set({ currentFlowId, currentFlow: get().flows.find((flow) => flow.id === currentFlowId) });
|
||||||
|
},
|
||||||
flows: [],
|
flows: [],
|
||||||
currentFlow: get().flows[get().currentFlowId],
|
currentFlow: undefined,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
setIsLoading: (isLoading: boolean) => set({ isLoading }),
|
setIsLoading: (isLoading: boolean) => set({ isLoading }),
|
||||||
flowsState: {},
|
flowsState: {},
|
||||||
currentFlowState: get().flowsState[get().currentFlowId],
|
currentFlowState: undefined,
|
||||||
setCurrentFlowState: (flowState: FlowState | ((oldState: FlowState) => FlowState)) => {
|
setCurrentFlowState: (flowState: FlowState | ((oldState: FlowState | undefined) => FlowState)) => {
|
||||||
const newFlowState = typeof flowState === "function" ? flowState(get().currentFlowState) : flowState;
|
const newFlowState = typeof flowState === "function" ? flowState(get().currentFlowState) : flowState;
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
flowsState: {
|
flowsState: {
|
||||||
...state.flowsState,
|
...state.flowsState,
|
||||||
[state.currentFlowId]: newFlowState,
|
[state.currentFlowId]: newFlowState,
|
||||||
},
|
},
|
||||||
|
currentFlowState: newFlowState,
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -440,11 +440,6 @@ export type headerFlowsType = {
|
||||||
style?: FlowStyleType;
|
style?: FlowStyleType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type menuBarPropsType = {
|
|
||||||
flows: Array<headerFlowsType>;
|
|
||||||
tabId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type chatInputType = {
|
export type chatInputType = {
|
||||||
chatValue: string;
|
chatValue: string;
|
||||||
inputRef: {
|
inputRef: {
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ export type FlowsManagerStoreType = {
|
||||||
flows: Array<FlowType>;
|
flows: Array<FlowType>;
|
||||||
currentFlow: FlowType | undefined;
|
currentFlow: FlowType | undefined;
|
||||||
currentFlowId: string;
|
currentFlowId: string;
|
||||||
|
setCurrentFlowId: (currentFlowId: string) => void;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
setIsLoading: (isLoading: boolean) => void;
|
setIsLoading: (isLoading: boolean) => void;
|
||||||
flowsState: FlowsState;
|
flowsState: FlowsState;
|
||||||
currentFlowState: FlowState;
|
currentFlowState: FlowState | undefined;
|
||||||
setCurrentFlowState: (state: FlowState | ((oldState: FlowState) => FlowState)) => void;
|
setCurrentFlowState: (state: FlowState | ((oldState: FlowState | undefined) => FlowState)) => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue