Skip to content

Commit

Permalink
Merge pull request #3047 from glific/template-flows/refactoring
Browse files Browse the repository at this point in the history
Refactored the code for template flows
  • Loading branch information
kurund authored Sep 2, 2024
2 parents 44bb539 + 110be3e commit 7584cb0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/components/floweditor/FlowEditor.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -31,13 +31,10 @@ 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);
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);
Expand All @@ -48,6 +45,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 | HTMLElement>(null);
const open = Boolean(anchorEl);
Expand Down Expand Up @@ -141,6 +140,7 @@ export const FlowEditor = () => {
useEffect(() => {
if (flowName && flowName.flows.length > 0) {
setFlowId(flowName.flows[0].id);
setIsTemplate(flowName.flows[0].isTemplate);
}
}, [flowName]);

Expand Down
26 changes: 24 additions & 2 deletions src/containers/Flow/Flow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
18 changes: 1 addition & 17 deletions src/mocks/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7584cb0

Please sign in to comment.