Skip to content

Commit

Permalink
Merge pull request #50 from osstotalsoft/update-export
Browse files Browse the repository at this point in the history
fix export handlers
  • Loading branch information
niemenX authored Jan 8, 2024
2 parents 2363483 + db1e8e8 commit 8762c03
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 46 deletions.
71 changes: 38 additions & 33 deletions gql-bff/src/features/workflow/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const workflowResolvers = {
else return filterResourcesByTenant(allWorkflows, tenant?.id);
},

exportWorkflows: async (_parent, { workflowList }, context, _info) => {
exportWorkflows: async (_parent, { workflowList, allHandlers }, context, _info) => {
const { dataSources, tenant } = context;
const { code } = tenant ?? { code: "" };

Expand All @@ -68,12 +68,13 @@ const workflowResolvers = {
...conductorHandlers.filter((a) => h.includes(a.name))
);
handlers.push(
...conductorHandlers.filter((a) =>
a.actions.some(
(x) =>
x.action === "start_workflow" &&
x?.start_workflow?.name === flow.name
) && !handlers.some((h) => h.name === a.name)
...conductorHandlers.filter(
(a) =>
a.actions.some(
(x) =>
x.action === "start_workflow" &&
x?.start_workflow?.name === flow.name
) && !handlers.some((h) => h.name === a.name)
)
);
}
Expand All @@ -88,12 +89,13 @@ const workflowResolvers = {
...conductorHandlers.filter((a) => h.includes(a.name))
);
handlers.push(
...conductorHandlers.filter((a) =>
a.actions.some(
(x) =>
x.action === "start_workflow" &&
x?.start_workflow?.name === flow.name
) && !handlers.some((h) => h.name === a.name)
...conductorHandlers.filter(
(a) =>
a.actions.some(
(x) =>
x.action === "start_workflow" &&
x?.start_workflow?.name === flow.name
) && !handlers.some((h) => h.name === a.name)
)
);
}
Expand All @@ -112,32 +114,35 @@ const workflowResolvers = {
const h = [...str.matchAll(regex)].map((a) => a[1]);
handlers.push(...conductorHandlers.filter((a) => h.includes(a.name)));
handlers.push(
...conductorHandlers.filter((a) =>
a.actions.some(
(x) =>
x.action === "start_workflow" &&
x?.start_workflow?.name === name[0]
) && !handlers.some((h) => h.name === a.name)
...conductorHandlers.filter(
(a) =>
a.actions.some(
(x) =>
x.action === "start_workflow" &&
x?.start_workflow?.name === name[0]
) && !handlers.some((h) => h.name === a.name)
)
);
}
}

//Add all handlers
if (isMultiTenant) {
const tenantHandlers = filterEvHandlersByTenant(
conductorHandlers,
tenant?.id
);
const newH = tenantHandlers.filter((a) =>
!handlers.some((h) => h.name === a.name)
);
handlers.push(...newH);
} else {
const newH = tenantHandlers.filter((a) =>
!handlers.some((h) => h.name === a.name)
);
handlers.push(...newH);
if (allHandlers) {
if (isMultiTenant) {
const tenantHandlers = filterEvHandlersByTenant(
conductorHandlers,
tenant?.id
);
const newH = tenantHandlers.filter(
(a) => !handlers.some((h) => h.name === a.name)
);
handlers.push(...newH);
} else {
const newH = conductorHandlers.filter(
(a) => !handlers.some((h) => h.name === a.name)
);
handlers.push(...newH);
}
}
return {
data: JSON.stringify({ flows, handlers }),
Expand Down
2 changes: 1 addition & 1 deletion gql-bff/src/features/workflow/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type ExportWorkflows {
extend type Query {
getWorkflow(name: String!, version: Int!): WorkflowDef
getWorkflowList: [WorkflowDef]
exportWorkflows(workflowList: [String]): ExportWorkflows
exportWorkflows(workflowList: [String], allHandlers: Boolean): ExportWorkflows
}

extend input WorkflowTaskInput {
Expand Down
2 changes: 2 additions & 0 deletions react-ui/public/static/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@
}
},
"Export": {
"AllHandlers": "All Handlers",
"WorkflowHandlers": "Workflow Handlers",
"ExportButton": "Export workflows",
"Download": "Download workflows",
"Export": "Export workflows",
Expand Down
2 changes: 2 additions & 0 deletions react-ui/public/static/locales/ro/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@
}
},
"Export": {
"AllHandlers": "Toti Handlerii",
"WorkflowHandlers": "Handlerii Workflow-ului",
"ExportButton": "Exporta workflows",
"Download": "Download workflows",
"Export": "Export workflows",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ const WorkflowHistoryItem = ({ history, workflow, isLatest, onRevert }) => {
maxWidth='xs'
open={revertDialog}
showActions
defaultActions
onYes={handleRevertWorkflow}
onClose={toggleRevertDialog}
textDialogYes={t('Dialog.Yes')}
textDialogNo={t('Dialog.No')}
/>
<CompareDefinitionDialog
open={compareDialog}
Expand Down
14 changes: 12 additions & 2 deletions react-ui/src/features/workflow/list/components/ExportDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,19 @@ const ExportDialog = ({ open, data, onClose, tenantCode }) => {
const handleOnExport = useCallback(() => {
const natsPrefix = data.match(/nats_stream:([A-Za-z.]+)ch\./)
let templateData = data
if (namePrefix) {
let dataObj = JSON.parse(data);
dataObj.flows.forEach(element => {
const newName = element.name.replace(namePrefix, '{{NamePrefix}}');
templateData = templateData.replaceAll(element.name, newName);
});

dataObj.handlers.forEach(element => {
const newName = element.name.replace(namePrefix, '{{NamePrefix}}');
templateData = templateData.replaceAll(element.name, newName);
});
/*if (namePrefix) {
templateData = templateData.replaceAll(namePrefix, '{{NamePrefix}}')
}
}*/
if (natsPrefix && natsPrefix[1]) {
templateData = templateData.replaceAll(`${natsPrefix[1]}`, '{{NatsPrefix}}')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { fieldsToBeRemoved, sortingDirection, sortWorkflowsByField } from 'featu
import { defaults } from 'apollo/defaultCacheData'
import { workflowsPager } from 'apollo/cacheKeyFunctions'
import { useMutation } from '@apollo/client'
import { useToast } from '@totalsoft/rocket-ui'
import { useToast, Dialog, Button } from '@totalsoft/rocket-ui'
import { useNavigate } from 'react-router-dom'
import { useReactOidc } from '@axa-fr/react-oidc-context'
import { WORKFLOW_QUERY } from 'features/workflow/edit/queries/WorkflowQuery'
Expand All @@ -25,6 +25,7 @@ import ImportDialog from './ImportDialog'
import { IMPORT_WORKFLOW_MUTATION } from '../mutations/ImportMutation'
import { useApolloLocalStorage } from 'hooks/apolloLocalStorage'
import { workflowListFilter } from 'apollo/cacheKeyFunctions'
import SwitchWithInternalState from 'features/common/components/SwitchWithInternalState'

const WorkflowListContainer = () => {
const { t } = useTranslation()
Expand All @@ -35,6 +36,9 @@ const WorkflowListContainer = () => {

const defaultPager = defaults[workflowsPager]
const [pager, setPager] = useState(defaultPager)
const [allHandlers, setAllHandlers] = useState(false)
const [exportOptions, setExportOptions] = useState(false)
const [workflowList, setWorkflowList] = useState([])
const [exportModal, setExportModal] = useState(false)
const [exportData, setExportData] = useState('')
const [importModal, setImportModal] = useState(false)
Expand Down Expand Up @@ -149,14 +153,20 @@ const WorkflowListContainer = () => {
)

const onExportButton = useCallback(
workflowList => {
getWorkflowsForExport({
variables: { workflowList }
})
list => {
setExportOptions(true)
setWorkflowList(list)
},
[getWorkflowsForExport]
[setExportOptions, setWorkflowList]
)

const onNextExportButton = useCallback(() => {
setExportOptions(false)
getWorkflowsForExport({
variables: { workflowList, allHandlers }
})
}, [getWorkflowsForExport, workflowList, allHandlers, setExportOptions])

const onCloseExportModal = useCallback(() => setExportModal(false), [setExportModal])
const onCloseImportModal = useCallback(() => {
setImportModal(false)
Expand All @@ -183,10 +193,38 @@ const WorkflowListContainer = () => {
[setImportData]
)

const handleOnClose = useCallback(() => setExportOptions(false), [setExportOptions])
const handleChange = useCallback(() => {
setAllHandlers(prev => !prev)
}, [setAllHandlers])

return (
<>
{importModal && <ImportDialog data={importData} open={importModal} onClose={onCloseImportModal} onImport={handleImport} />}
{exportData && <ExportDialog data={exportData} open={exportModal} onClose={onCloseExportModal} tenantCode={tenantCode} />}
<>
<Dialog
fullWidth={true}
maxWidth={'md'}
id='exportOptions'
open={exportOptions}
title={t('Export.Export')}
onClose={handleOnClose}
actions={[
<Button key='export' color='primary' size='small' onClick={onNextExportButton}>
{t('Export.Next')}
</Button>
]}
content={
<SwitchWithInternalState
labelOn={t('Export.AllHandlers')}
labelOff={t('Export.WorkflowHandlers')}
checked={allHandlers}
onChange={handleChange}
/>
}
/>
</>
<WorkflowListFilter loading={loading} filters={filters} onChangeFilters={handleChangeFilters} />
<WorkflowList
pager={pager}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const WORKFLOW_LIST_QUERY = gql`
`

export const WORKFLOW_EXPORT_QUERY = gql`
query exportWorkflows($workflowList: [String]) {
exportWorkflows(workflowList: $workflowList) {
query exportWorkflows($workflowList: [String], $allHandlers: Boolean) {
exportWorkflows(workflowList: $workflowList, allHandlers: $allHandlers) {
data
tenantCode
}
Expand Down

0 comments on commit 8762c03

Please sign in to comment.