From 94a2989a60b9e07b9032a072eb0dfef2acfacc7b Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Thu, 29 Aug 2024 09:02:02 +0530 Subject: [PATCH 1/3] updated the code --- src/components/floweditor/FlowEditor.tsx | 5 +++-- src/containers/Flow/Flow.tsx | 16 ++-------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/components/floweditor/FlowEditor.tsx b/src/components/floweditor/FlowEditor.tsx index 78b8820e3..b7c0883b9 100644 --- a/src/components/floweditor/FlowEditor.tsx +++ b/src/components/floweditor/FlowEditor.tsx @@ -36,8 +36,6 @@ export const FlowEditor = () => { const [loading, setLoading] = useState(true); const [flowEditorLoaded, setFlowEditorLoaded] = useState(false); const [flowId, setFlowId] = useState(); - const isTemplate = location?.state === 'template'; - const config = setConfig(uuid, isTemplate); const [published, setPublished] = useState(false); const [showSimulator, setShowSimulator] = useState(false); const [stayOnPublish, setStayOnPublish] = useState(false); @@ -48,6 +46,8 @@ export const FlowEditor = () => { const [currentEditDialogBox, setCurrentEditDialogBox] = useState(false); const [dialogMessage, setDialogMessage] = useState(''); const [publishLoading, setPublishLoading] = useState(false); + const [isTemplate, setIsTemplate] = useState(false); + const config = setConfig(uuid, isTemplate); const [anchorEl, setAnchorEl] = useState(null); const open = Boolean(anchorEl); @@ -141,6 +141,7 @@ export const FlowEditor = () => { useEffect(() => { if (flowName && flowName.flows.length > 0) { setFlowId(flowName.flows[0].id); + setIsTemplate(flowName.flows[0].isTemplate); } }, [flowName]); diff --git a/src/containers/Flow/Flow.tsx b/src/containers/Flow/Flow.tsx index 150767345..5e0117ed6 100644 --- a/src/containers/Flow/Flow.tsx +++ b/src/containers/Flow/Flow.tsx @@ -156,23 +156,11 @@ export const Flow = () => { cancelLink = 'flow?isTemplate=true'; } - const configureAction = { - label: t('Configure'), + const additionalAction = { + label: isTemplate ? t('View') : t('Configure'), link: '/flow/configure', }; - const viewAction = { - label: t('View'), - link: '/flow/configure', - action: (link: any) => { - navigate(link, { - state: 'template', - }); - }, - }; - - const additionalAction = isTemplate ? viewAction : configureAction; - const formFields = [ { component: Input, From d8db107bb674d8dd4172b82cc66be37e3eb6982d Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Fri, 30 Aug 2024 11:28:46 +0530 Subject: [PATCH 2/3] fixed test cases --- src/containers/Flow/Flow.test.tsx | 26 ++++++++++++++++++++++++-- src/containers/Flow/Flow.tsx | 16 ++++++++++++++-- src/mocks/Flow.tsx | 18 +----------------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/containers/Flow/Flow.test.tsx b/src/containers/Flow/Flow.test.tsx index 3d7a29e04..edf9d67ed 100644 --- a/src/containers/Flow/Flow.test.tsx +++ b/src/containers/Flow/Flow.test.tsx @@ -33,13 +33,35 @@ const mocks = [ getFilterTagQuery, getRoleNameQuery, getOrganizationLanguagesQuery, - copyFlowQuery(), - copyFlowQuery(true), + copyFlowQuery({ + isActive: true, + isPinned: false, + isBackground: false, + name: 'Copy of Help', + keywords: [], + description: '', + ignoreKeywords: false, + addRoleIds: [], + deleteRoleIds: [], + }), + copyFlowQuery({ + isActive: true, + isPinned: false, + isBackground: false, + name: 'Copy of Help', + keywords: ['help', 'activity'], + description: 'Help flow', + ignoreKeywords: false, + addRoleIds: [], + deleteRoleIds: [], + tag_id: '1', + }), createFlowQuery, createTagQuery, getFlowCountQuery({ isActive: true, isTemplate: false }), releaseFlow, getFilterTagQuery, + updateFlowQuery, ]; const mockUseLocationValue: any = { diff --git a/src/containers/Flow/Flow.tsx b/src/containers/Flow/Flow.tsx index 5e0117ed6..150767345 100644 --- a/src/containers/Flow/Flow.tsx +++ b/src/containers/Flow/Flow.tsx @@ -156,11 +156,23 @@ export const Flow = () => { cancelLink = 'flow?isTemplate=true'; } - const additionalAction = { - label: isTemplate ? t('View') : t('Configure'), + const configureAction = { + label: t('Configure'), link: '/flow/configure', }; + const viewAction = { + label: t('View'), + link: '/flow/configure', + action: (link: any) => { + navigate(link, { + state: 'template', + }); + }, + }; + + const additionalAction = isTemplate ? viewAction : configureAction; + const formFields = [ { component: Input, diff --git a/src/mocks/Flow.tsx b/src/mocks/Flow.tsx index d302c24a9..8a6e80846 100644 --- a/src/mocks/Flow.tsx +++ b/src/mocks/Flow.tsx @@ -663,23 +663,7 @@ export const exportFlowTranslationsWithErrors = { }, }; -export const copyFlowQuery = (template: boolean = false) => { - let input = { - isActive: true, - isPinned: false, - isBackground: false, - name: 'Copy of Help', - keywords: template ? [] : ['help', 'activity'], - description: template ? '' : 'Help flow', - ignoreKeywords: false, - addRoleIds: [], - deleteRoleIds: [], - }; - - if (!template) { - Object.assign(input, { tag_id: '1' }); - } - +export const copyFlowQuery = (input: any) => { return { request: { query: CREATE_FLOW_COPY, From 0db3557ab6d9399a36a6c7e214151b240584ee4a Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Fri, 30 Aug 2024 11:31:13 +0530 Subject: [PATCH 3/3] deepscan fixes --- src/components/floweditor/FlowEditor.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/floweditor/FlowEditor.tsx b/src/components/floweditor/FlowEditor.tsx index b7c0883b9..708a055f3 100644 --- a/src/components/floweditor/FlowEditor.tsx +++ b/src/components/floweditor/FlowEditor.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react'; import { useMutation, useLazyQuery, useQuery } from '@apollo/client'; -import { Navigate, useLocation, useNavigate, useParams } from 'react-router-dom'; +import { Navigate, useNavigate, useParams } from 'react-router-dom'; import { Menu, MenuItem, Typography } from '@mui/material'; import BackIconFlow from 'assets/images/icons/BackIconFlow.svg?react'; import WarningIcon from 'assets/images/icons/Warning.svg?react'; @@ -31,7 +31,6 @@ export const FlowEditor = () => { const params = useParams(); const { uuid } = params; const navigate = useNavigate(); - const location = useLocation(); const [publishDialog, setPublishDialog] = useState(false); const [loading, setLoading] = useState(true); const [flowEditorLoaded, setFlowEditorLoaded] = useState(false);