From c1bc2de720c1ac92f8f5bb80a20d579fdece7058 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 2 Nov 2023 09:41:39 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(buildTrigger):=20rename=20im?= =?UTF-8?q?port=20of=20TabsState=20to=20FlowsState=20to=20improve=20semant?= =?UTF-8?q?ics=20=F0=9F=90=9B=20fix(EditNodeModal):=20rename=20import=20of?= =?UTF-8?q?=20TabsState=20to=20FlowsState=20to=20improve=20semantics=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(formModal):=20rename=20import=20of=20TabsSta?= =?UTF-8?q?te=20to=20FlowsState=20to=20improve=20semantics=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(PageComponent):=20rename=20import=20of=20TabsState=20to?= =?UTF-8?q?=20FlowsState=20to=20improve=20semantics=20=F0=9F=90=9B=20fix(r?= =?UTF-8?q?eactflowUtils):=20rename=20import=20of=20TabsState=20to=20Flows?= =?UTF-8?q?State=20to=20improve=20semantics=20=F0=9F=90=9B=20fix(utils):?= =?UTF-8?q?=20rename=20import=20of=20TabsState=20to=20FlowsState=20to=20im?= =?UTF-8?q?prove=20semantics=20=F0=9F=9A=9A=20chore(server.ts):=20change?= =?UTF-8?q?=20port=20variable=20case=20from=20lowercase=20port=20to=20uppe?= =?UTF-8?q?rcase=20PORT=20to=20improve=20semantics=20=E2=9C=A8=20feat(serv?= =?UTF-8?q?er.ts):=20add=20support=20for=20process.env.PORT=20environment?= =?UTF-8?q?=20variable=20to=20be=20able=20to=20run=20app=20on=20a=20config?= =?UTF-8?q?urable=20port?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatComponent/buildTrigger/index.tsx | 4 ++-- .../src/modals/EditNodeModal/index.tsx | 4 ++-- src/frontend/src/modals/formModal/index.tsx | 8 ++++---- .../components/PageComponent/index.tsx | 6 +++--- src/frontend/src/utils/reactflowUtils.ts | 8 ++++---- src/frontend/src/utils/utils.ts | 19 ++++++++++--------- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx index 99e628db5..242cef265 100644 --- a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx +++ b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx @@ -9,7 +9,7 @@ import { FlowType } from "../../../types/flow"; import { FlowsContext } from "../../../contexts/flowsContext"; import { parsedDataType } from "../../../types/components"; -import { TabsState } from "../../../types/tabs"; +import { FlowsState } from "../../../types/tabs"; import { validateNodes } from "../../../utils/reactflowUtils"; import RadialProgressComponent from "../../RadialProgress"; import IconComponent from "../../genericIconComponent"; @@ -99,7 +99,7 @@ export default function BuildTrigger({ setSuccessData({ title: parsedData.log }); } else if (parsedData.input_keys !== undefined) { //@ts-ignore - setTabsState((old: TabsState) => { + setTabsState((old: FlowsState) => { return { ...old, [flowId]: { diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index 3e59461d3..6466d19b9 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -36,7 +36,7 @@ import { limitScrollFieldsModal } from "../../constants/constants"; import { FlowsContext } from "../../contexts/flowsContext"; import { typesContext } from "../../contexts/typesContext"; import { NodeDataType } from "../../types/flow"; -import { TabsState } from "../../types/tabs"; +import { FlowsState } from "../../types/tabs"; import { convertObjToArray, convertValuesToNumbers, @@ -542,7 +542,7 @@ const EditNodeModal = forwardRef( const newData = cloneDeep(myData.current); myData.current = newData; //@ts-ignore - setTabsState((prev: TabsState) => { + setTabsState((prev: FlowsState) => { return { ...prev, [tabId]: { diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 37656d1f7..f6f7c214f 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -26,7 +26,7 @@ import { CHAT_FORM_DIALOG_SUBTITLE } from "../../constants/constants"; import { AuthContext } from "../../contexts/authContext"; import { FlowsContext } from "../../contexts/flowsContext"; import { getBuildStatus } from "../../controllers/API"; -import { TabsState } from "../../types/tabs"; +import { FlowsState } from "../../types/tabs"; import { validateNodes } from "../../utils/reactflowUtils"; export default function FormModal({ @@ -401,7 +401,7 @@ export default function FormModal({ chatKey: chatKey!, }); //@ts-ignore - setTabsState((old: TabsState) => { + setTabsState((old: FlowsState) => { if (!chatKey) return old; let newTabsState = _.cloneDeep(old); newTabsState[id.current].formKeysData.input_keys![chatKey] = ""; @@ -522,7 +522,7 @@ export default function FormModal({ } onChange={(e) => { //@ts-ignore - setTabsState((old: TabsState) => { + setTabsState((old: FlowsState) => { let newTabsState = _.cloneDeep(old); newTabsState[ id.current @@ -634,7 +634,7 @@ export default function FormModal({ setChatValue={(value) => { setChatValue(value); //@ts-ignore - setTabsState((old: TabsState) => { + setTabsState((old: FlowsState) => { let newTabsState = _.cloneDeep(old); newTabsState[id.current].formKeysData.input_keys![ chatKey! diff --git a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx index 6cfd49e60..71931b18c 100644 --- a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx @@ -34,7 +34,7 @@ import { typesContext } from "../../../../contexts/typesContext"; import { undoRedoContext } from "../../../../contexts/undoRedoContext"; import { APIClassType } from "../../../../types/api"; import { FlowType, NodeType, targetHandleType } from "../../../../types/flow"; -import { TabsState } from "../../../../types/tabs"; +import { FlowsState } from "../../../../types/tabs"; import { generateFlow, generateNodeFromFlow, @@ -208,7 +208,7 @@ export default function Page({ return newX; }); //@ts-ignore - setTabsState((prev: TabsState) => { + setTabsState((prev: FlowsState) => { return { ...prev, [tabId]: { @@ -225,7 +225,7 @@ export default function Page({ (change: NodeChange[]) => { onNodesChange(change); //@ts-ignore - setTabsState((prev: TabsState) => { + setTabsState((prev: FlowsState) => { return { ...prev, [tabId]: { diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 64c978c42..543928432 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -25,7 +25,7 @@ import { unselectAllNodesType, updateEdgesHandleIdsType, } from "../types/utils/reactflowUtils"; -import { getFieldTitle } from "./utils"; +import { getFieldTitle, toTitleCase } from "./utils"; export function cleanEdges({ flow: { edges, nodes }, @@ -506,7 +506,7 @@ export function generateFlow( name: string ): generateFlowType { const newFlowData = reactFlowInstance.toObject(); - + const uid = new ShortUniqueId({ length: 5 }); /* remove edges that are not connected to selected nodes on both ends in future we can save this edges to when ungrouping reconect to the old nodes */ @@ -869,7 +869,7 @@ export function ungroupNode( let { field, id } = template[key].proxy!; let nodeIndex = gNodes.findIndex((n) => n.id === id); if (nodeIndex !== -1) { - let display_name: string; + let display_name: string | undefined; let show = gNodes[nodeIndex].data.node!.template[field].show; let advanced = gNodes[nodeIndex].data.node!.template[field].advanced; if (gNodes[nodeIndex].data.node!.template[field].display_name) { @@ -959,7 +959,7 @@ export function expandGroupNode( let nodeIndex = gNodes.findIndex((n) => n.id === id); if (nodeIndex !== -1) { let proxy: { id: string; field: string } | undefined; - let display_name: string; + let display_name: string | undefined; let show = gNodes[nodeIndex].data.node!.template[field].show; let advanced = gNodes[nodeIndex].data.node!.template[field].advanced; if (gNodes[nodeIndex].data.node!.template[field].display_name) { diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index 60433a149..c32962747 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -12,7 +12,7 @@ import { tweakType, } from "../types/components"; import { FlowType, NodeType } from "../types/flow"; -import { TabsState } from "../types/tabs"; +import { FlowsState } from "../types/tabs"; import { buildTweaks } from "./reactflowUtils"; export function classNames(...classes: Array): string { @@ -57,7 +57,8 @@ export function normalCaseToSnakeCase(str: string): string { .join("_"); } -export function toTitleCase(str: string): string { +export function toTitleCase(str: string | undefined): string { + if (!str) return ""; let result = str .split("_") .map((word, index) => { @@ -199,7 +200,7 @@ export function groupByFamily( })); } -export function buildInputs(tabsState: TabsState, id: string): string { +export function buildInputs(tabsState: FlowsState, id: string): string { return tabsState && tabsState[id] && tabsState[id].formKeysData && @@ -277,10 +278,10 @@ export function buildTweakObject(tweak: tweakType) { /** * Function to get Chat Input Field * @param {FlowType} flow - The current flow. - * @param {TabsState} tabsState - The current tabs state. + * @param {FlowsState} tabsState - The current tabs state. * @returns {string} - The chat input field */ -export function getChatInputField(flow: FlowType, tabsState?: TabsState) { +export function getChatInputField(flow: FlowType, tabsState?: FlowsState) { let chat_input_field = "text"; if ( @@ -305,7 +306,7 @@ export function getPythonApiCode( flow: FlowType, isAuth: boolean, tweak?: any[], - tabsState?: TabsState + tabsState?: FlowsState ): string { const flowId = flow.id; @@ -369,7 +370,7 @@ export function getCurlCode( flow: FlowType, isAuth: boolean, tweak?: any[], - tabsState?: TabsState + tabsState?: FlowsState ): string { const flowId = flow.id; const tweaks = buildTweaks(flow); @@ -397,7 +398,7 @@ export function getCurlCode( export function getPythonCode( flow: FlowType, tweak?: any[], - tabsState?: TabsState + tabsState?: FlowsState ): string { const flowName = flow.name; const tweaks = buildTweaks(flow); @@ -422,7 +423,7 @@ flow(inputs)`; export function getWidgetCode( flow: FlowType, isAuth: boolean, - tabsState?: TabsState + tabsState?: FlowsState ): string { const flowId = flow.id; const flowName = flow.name;