From de4bd82d1cdfa0478e18054ecd3bab926bb820dc Mon Sep 17 00:00:00 2001 From: wzglinieckisoldevelo Date: Mon, 3 Jun 2024 08:10:05 +0200 Subject: [PATCH 1/6] ONI-255: Allowed sources picker. --- .../groups-management/TaskGroupHeadPanel.js | 18 ++++++++ src/pickers/TaskSourceAllowedPicker.js | 43 +++++++++++++++++++ src/pickers/TaskSourcePicker.js | 3 +- src/translations/en.json | 2 + 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/pickers/TaskSourceAllowedPicker.js diff --git a/src/components/groups-management/TaskGroupHeadPanel.js b/src/components/groups-management/TaskGroupHeadPanel.js index c3ef633..8843032 100644 --- a/src/components/groups-management/TaskGroupHeadPanel.js +++ b/src/components/groups-management/TaskGroupHeadPanel.js @@ -11,6 +11,8 @@ import { withTheme, withStyles } from '@material-ui/core/styles'; import TaskExecutorsPicker from '../../pickers/TaskExecutorsPicker'; import GroupPolicyPicker from '../../pickers/GroupPolicyPicker'; import TaskSourcePicker from '../../pickers/TaskSourcePicker'; +import TaskSourceAllowedPicker from '../../pickers/TaskSourceAllowedPicker'; +import { TASK_GROUP_UPDATE, TASK_GROUP_CREATE } from '../../constants'; const styles = (theme) => ({ tableTitle: theme.table.title, @@ -46,6 +48,14 @@ class TaskGroupHeadPanel extends FormPanel { edited, classes, readOnly, } = this.props; const taskGroup = { ...edited }; + const { rights } = this.props; + const filterAllowedSources = (options) => { + if (!taskGroup?.taskAllowedSources?.length){ + return options + } + const sourcesIds = taskGroup.taskAllowedSources.map((source)=>source.id) + return options.filter((option)=>!sourcesIds.includes(option.id)) + } return ( <> {renderHeadPanelTitle(classes)} @@ -86,6 +96,14 @@ class TaskGroupHeadPanel extends FormPanel { readOnly={readOnly} value={taskGroup?.taskSources} onChange={(sources) => this.updateAttribute('taskSources', sources)} + filterOptions={filterAllowedSources} + /> + + + this.updateAttribute('taskAllowedSources', allowedSources)} /> diff --git a/src/pickers/TaskSourceAllowedPicker.js b/src/pickers/TaskSourceAllowedPicker.js new file mode 100644 index 0000000..14186f5 --- /dev/null +++ b/src/pickers/TaskSourceAllowedPicker.js @@ -0,0 +1,43 @@ +import React from 'react'; +import { + Autocomplete, + useTranslations, + useModulesManager, +} from '@openimis/fe-core'; +import { TASK_CONTRIBUTION_KEY } from '../constants'; + +function TaskSourceAllowedPicker({ + onChange, + readOnly, + required, + withLabel, + value, +}) { + const modulesManager = useModulesManager(); + const { formatMessage } = useTranslations('tasksManagement'); + const contributions = modulesManager.getContribs(TASK_CONTRIBUTION_KEY); + const allowedSources = contributions.flatMap((contribution) => { + const source = contribution.taskSource; + return source ? source.map((item) => ({ id: item, name: item })) : []; + }); + + return ( + `${source.name}`} + onChange={onChange} + filterSelectedOptions + onInputChange={() => {}} + /> + ); +} + +export default TaskSourceAllowedPicker; diff --git a/src/pickers/TaskSourcePicker.js b/src/pickers/TaskSourcePicker.js index 93ea99f..f68f9fd 100644 --- a/src/pickers/TaskSourcePicker.js +++ b/src/pickers/TaskSourcePicker.js @@ -12,6 +12,7 @@ function TaskSourcePicker({ required, withLabel, value, + filterOptions }) { const modulesManager = useModulesManager(); const { formatMessage } = useTranslations('tasksManagement'); @@ -34,7 +35,7 @@ function TaskSourcePicker({ value={value} getOptionLabel={(source) => `${source.name}`} onChange={onChange} - filterSelectedOptions + filterOptions={filterOptions} onInputChange={() => {}} /> ); diff --git a/src/translations/en.json b/src/translations/en.json index e4f352b..2d39117 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -53,6 +53,8 @@ "tasksManagement.menu.taskExecutionerGroups": "Task Executioner Groups", "tasksManagement.TaskSourcePicker.label": "Task Sources", "tasksManagement.TaskSourcePicker.placeholder": "Search for task sources...", + "tasksManagement.TaskSourceAllowedPicker.label": "Allowed Task Sources", + "tasksManagement.TaskSourceAllowedPicker.placeholder": "Search for allowed task sources...", "tasksManagement.entries.tasksManagementAllView": "All Tasks", "tasksManagement.task.source.mutationLabel": "Resolving task", "tasksManagement.task.source.IndividualService": "Individual Service", From 220e3c6ddaa7b495da6a5a1170ec26481c563d37 Mon Sep 17 00:00:00 2001 From: wzglinieckisoldevelo Date: Wed, 5 Jun 2024 11:35:57 +0200 Subject: [PATCH 2/6] ONI-255: Fetching allowed sources fix. --- src/actions.js | 3 +++ src/reducer.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/actions.js b/src/actions.js index b261a96..81616e5 100644 --- a/src/actions.js +++ b/src/actions.js @@ -17,6 +17,7 @@ const TASK_GROUP_PROJECTION = () => [ 'code', 'completionPolicy', 'taskexecutorSet { edges { node { user { id username lastName } } } }', + 'taskAllowedSources' ]; const TASK_FULL_PROJECTION = () => [ @@ -64,6 +65,7 @@ export const formatTaskGroupGQL = (taskGroup) => { ${taskGroup?.id ? `id: "${taskGroup.id}"` : ''} ${taskGroup?.taskexecutorSet ? `userIds: ${executorsString}` : 'userIds: []'} ${taskGroup?.taskSources ? `taskSources: ${taskSourcesString}` : 'taskSources: []'} + ${taskGroup?.taskAllowedSources ? `taskAllowedSources: ${taskSourcesString}` : 'taskAllowedSources: []'} `; }; @@ -122,6 +124,7 @@ export function fetchTaskGroup(modulesManager, variables) { completionPolicy jsonExt taskexecutorSet { edges { node { user { id username lastName } } } }, + taskAllowedSources } } } diff --git a/src/reducer.js b/src/reducer.js index 8be83b1..68ebb2e 100644 --- a/src/reducer.js +++ b/src/reducer.js @@ -166,6 +166,9 @@ function reducer( taskSources: taskGroup?.jsonExt ? JSON.parse(taskGroup.jsonExt).task_sources.map((source) => ({ id: source, name: source })) : [], + taskAllowedSources: taskGroup?.taskAllowedSources + ? JSON.parse(taskGroup?.taskAllowedSources).task_allowed_sources.map((source) => ({ id: source, name: source })) + : [], }))?.[0], fetchingTaskGroup: false, errorTaskGroup: formatGraphQLError(action.payload), From e75e7b221ce30b71f79c12bfe7f35be2aab1727e Mon Sep 17 00:00:00 2001 From: wzglinieckisoldevelo Date: Thu, 6 Jun 2024 13:59:44 +0200 Subject: [PATCH 3/6] ONI-255: Proper filtering of task group by allowed source. --- src/actions.js | 2 +- src/components/TaskHeadPanel.js | 1 + .../groups-management/TaskGroupHeadPanel.js | 8 ++--- src/pickers/TaskGroupPicker.js | 31 ++++++++++++------- src/pickers/TaskSourceAllowedPicker.js | 24 +++++--------- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/actions.js b/src/actions.js index 81616e5..060cbf5 100644 --- a/src/actions.js +++ b/src/actions.js @@ -17,7 +17,7 @@ const TASK_GROUP_PROJECTION = () => [ 'code', 'completionPolicy', 'taskexecutorSet { edges { node { user { id username lastName } } } }', - 'taskAllowedSources' + 'taskAllowedSources', ]; const TASK_FULL_PROJECTION = () => [ diff --git a/src/components/TaskHeadPanel.js b/src/components/TaskHeadPanel.js index b27618a..ff0fc0b 100644 --- a/src/components/TaskHeadPanel.js +++ b/src/components/TaskHeadPanel.js @@ -89,6 +89,7 @@ class TaskHeadPanel extends FormPanel { readOnly={!rights.includes(TASK_UPDATE) || [TASK_STATUS.COMPLETED, TASK_STATUS.FAILED].includes(task.status)} withNull + source={task?.source} value={task?.taskGroup} onChange={(taskGroup) => this.updateAttribute('taskGroup', taskGroup)} /> diff --git a/src/components/groups-management/TaskGroupHeadPanel.js b/src/components/groups-management/TaskGroupHeadPanel.js index 8843032..682ac3f 100644 --- a/src/components/groups-management/TaskGroupHeadPanel.js +++ b/src/components/groups-management/TaskGroupHeadPanel.js @@ -50,11 +50,11 @@ class TaskGroupHeadPanel extends FormPanel { const taskGroup = { ...edited }; const { rights } = this.props; const filterAllowedSources = (options) => { - if (!taskGroup?.taskAllowedSources?.length){ - return options + if (!taskGroup?.taskAllowedSources?.length) { + return options; } - const sourcesIds = taskGroup.taskAllowedSources.map((source)=>source.id) - return options.filter((option)=>!sourcesIds.includes(option.id)) + const sourcesIds = taskGroup.taskAllowedSources.map((source) => source.id); + return options.filter((option) => sourcesIds.includes(option.id)); } return ( <> diff --git a/src/pickers/TaskGroupPicker.js b/src/pickers/TaskGroupPicker.js index 5b1f938..58b0d4b 100644 --- a/src/pickers/TaskGroupPicker.js +++ b/src/pickers/TaskGroupPicker.js @@ -1,11 +1,6 @@ -import React, { useState } from 'react'; +import React, { useState } from "react"; -import { - useModulesManager, - useTranslations, - Autocomplete, - useGraphqlQuery, -} from '@openimis/fe-core'; +import { useModulesManager, useTranslations, Autocomplete, useGraphqlQuery } from "@openimis/fe-core"; function TaskGroupPicker(props) { const { @@ -16,6 +11,7 @@ function TaskGroupPicker(props) { withPlaceholder, value, label, + source = null, filterOptions, filterSelectedOptions, placeholder, @@ -23,8 +19,8 @@ function TaskGroupPicker(props) { } = props; const modulesManager = useModulesManager(); - const { formatMessage } = useTranslations('claim', modulesManager); - const [searchString, setSearchString] = useState(''); + const { formatMessage } = useTranslations("claim", modulesManager); + const [searchString, setSearchString] = useState(""); const { isLoading, data, error } = useGraphqlQuery( ` @@ -35,6 +31,7 @@ function TaskGroupPicker(props) { id code completionPolicy + taskAllowedSources } } } @@ -45,17 +42,27 @@ function TaskGroupPicker(props) { }, ); + const options = data?.taskGroup?.edges.map((edge) => edge.node) ?? []; + + const filteredOptionsWithAllowedSources = options.filter((option) => { + const parsedResponse = JSON.parse(option.taskAllowedSources); + const allowedSources = typeof parsedResponse === "object" ? [parsedResponse] : parsedResponse; + const usersAllowedSources = allowedSources.flatMap((source) => source.task_allowed_sources); + + return usersAllowedSources.includes(source); + }); + return ( edge.node) ?? []} + options={filteredOptionsWithAllowedSources} isLoading={isLoading} value={value} getOptionLabel={(option) => `${option.code}`} diff --git a/src/pickers/TaskSourceAllowedPicker.js b/src/pickers/TaskSourceAllowedPicker.js index 14186f5..f957728 100644 --- a/src/pickers/TaskSourceAllowedPicker.js +++ b/src/pickers/TaskSourceAllowedPicker.js @@ -1,20 +1,10 @@ -import React from 'react'; -import { - Autocomplete, - useTranslations, - useModulesManager, -} from '@openimis/fe-core'; -import { TASK_CONTRIBUTION_KEY } from '../constants'; +import React from "react"; +import { Autocomplete, useTranslations, useModulesManager } from "@openimis/fe-core"; +import { TASK_CONTRIBUTION_KEY } from "../constants"; -function TaskSourceAllowedPicker({ - onChange, - readOnly, - required, - withLabel, - value, -}) { +function TaskSourceAllowedPicker({ onChange, readOnly, required, withLabel, value }) { const modulesManager = useModulesManager(); - const { formatMessage } = useTranslations('tasksManagement'); + const { formatMessage } = useTranslations("tasksManagement"); const contributions = modulesManager.getContribs(TASK_CONTRIBUTION_KEY); const allowedSources = contributions.flatMap((contribution) => { const source = contribution.taskSource; @@ -25,8 +15,8 @@ function TaskSourceAllowedPicker({ Date: Thu, 6 Jun 2024 14:10:55 +0200 Subject: [PATCH 4/6] ONI-255: Styling changes. --- .../groups-management/TaskGroupHeadPanel.js | 2 +- src/pickers/TaskGroupPicker.js | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/groups-management/TaskGroupHeadPanel.js b/src/components/groups-management/TaskGroupHeadPanel.js index 682ac3f..66f58d9 100644 --- a/src/components/groups-management/TaskGroupHeadPanel.js +++ b/src/components/groups-management/TaskGroupHeadPanel.js @@ -55,7 +55,7 @@ class TaskGroupHeadPanel extends FormPanel { } const sourcesIds = taskGroup.taskAllowedSources.map((source) => source.id); return options.filter((option) => sourcesIds.includes(option.id)); - } + }; return ( <> {renderHeadPanelTitle(classes)} diff --git a/src/pickers/TaskGroupPicker.js b/src/pickers/TaskGroupPicker.js index 58b0d4b..007520d 100644 --- a/src/pickers/TaskGroupPicker.js +++ b/src/pickers/TaskGroupPicker.js @@ -1,6 +1,8 @@ -import React, { useState } from "react"; +import React, { useState } from 'react'; -import { useModulesManager, useTranslations, Autocomplete, useGraphqlQuery } from "@openimis/fe-core"; +import { + useModulesManager, useTranslations, Autocomplete, useGraphqlQuery +} from '@openimis/fe-core'; function TaskGroupPicker(props) { const { @@ -19,8 +21,8 @@ function TaskGroupPicker(props) { } = props; const modulesManager = useModulesManager(); - const { formatMessage } = useTranslations("claim", modulesManager); - const [searchString, setSearchString] = useState(""); + const { formatMessage } = useTranslations('claim', modulesManager); + const [searchString, setSearchString] = useState(''); const { isLoading, data, error } = useGraphqlQuery( ` @@ -46,7 +48,7 @@ function TaskGroupPicker(props) { const filteredOptionsWithAllowedSources = options.filter((option) => { const parsedResponse = JSON.parse(option.taskAllowedSources); - const allowedSources = typeof parsedResponse === "object" ? [parsedResponse] : parsedResponse; + const allowedSources = typeof parsedResponse === 'object' ? [parsedResponse] : parsedResponse; const usersAllowedSources = allowedSources.flatMap((source) => source.task_allowed_sources); return usersAllowedSources.includes(source); @@ -56,8 +58,8 @@ function TaskGroupPicker(props) { Date: Thu, 6 Jun 2024 19:42:20 +0200 Subject: [PATCH 5/6] ONI-255: Moving rights to destructured properties. --- .../groups-management/TaskGroupHeadPanel.js | 3 +-- src/pickers/TaskGroupPicker.js | 4 ++-- src/pickers/TaskSourceAllowedPicker.js | 16 +++++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/components/groups-management/TaskGroupHeadPanel.js b/src/components/groups-management/TaskGroupHeadPanel.js index 66f58d9..e1e0d69 100644 --- a/src/components/groups-management/TaskGroupHeadPanel.js +++ b/src/components/groups-management/TaskGroupHeadPanel.js @@ -45,10 +45,9 @@ const renderHeadPanelTitle = (classes) => ( class TaskGroupHeadPanel extends FormPanel { render() { const { - edited, classes, readOnly, + edited, classes, readOnly, rights } = this.props; const taskGroup = { ...edited }; - const { rights } = this.props; const filterAllowedSources = (options) => { if (!taskGroup?.taskAllowedSources?.length) { return options; diff --git a/src/pickers/TaskGroupPicker.js b/src/pickers/TaskGroupPicker.js index 007520d..cb3850e 100644 --- a/src/pickers/TaskGroupPicker.js +++ b/src/pickers/TaskGroupPicker.js @@ -1,7 +1,7 @@ import React, { useState } from 'react'; -import { - useModulesManager, useTranslations, Autocomplete, useGraphqlQuery +import { + useModulesManager, useTranslations, Autocomplete, useGraphqlQuery, } from '@openimis/fe-core'; function TaskGroupPicker(props) { diff --git a/src/pickers/TaskSourceAllowedPicker.js b/src/pickers/TaskSourceAllowedPicker.js index f957728..62c3ca1 100644 --- a/src/pickers/TaskSourceAllowedPicker.js +++ b/src/pickers/TaskSourceAllowedPicker.js @@ -1,10 +1,12 @@ -import React from "react"; -import { Autocomplete, useTranslations, useModulesManager } from "@openimis/fe-core"; -import { TASK_CONTRIBUTION_KEY } from "../constants"; +import React from 'react'; +import { Autocomplete, useTranslations, useModulesManager } from '@openimis/fe-core'; +import { TASK_CONTRIBUTION_KEY } from '../constants'; -function TaskSourceAllowedPicker({ onChange, readOnly, required, withLabel, value }) { +function TaskSourceAllowedPicker({ + onChange, readOnly, required, withLabel, value +}) { const modulesManager = useModulesManager(); - const { formatMessage } = useTranslations("tasksManagement"); + const { formatMessage } = useTranslations('tasksManagement'); const contributions = modulesManager.getContribs(TASK_CONTRIBUTION_KEY); const allowedSources = contributions.flatMap((contribution) => { const source = contribution.taskSource; @@ -15,8 +17,8 @@ function TaskSourceAllowedPicker({ onChange, readOnly, required, withLabel, valu Date: Fri, 7 Jun 2024 11:13:01 +0200 Subject: [PATCH 6/6] ONI-255: Linter style changes. --- src/components/groups-management/TaskGroupHeadPanel.js | 2 +- src/pickers/TaskSourceAllowedPicker.js | 2 +- src/pickers/TaskSourcePicker.js | 2 +- src/reducer.js | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/groups-management/TaskGroupHeadPanel.js b/src/components/groups-management/TaskGroupHeadPanel.js index e1e0d69..1f85f9a 100644 --- a/src/components/groups-management/TaskGroupHeadPanel.js +++ b/src/components/groups-management/TaskGroupHeadPanel.js @@ -45,7 +45,7 @@ const renderHeadPanelTitle = (classes) => ( class TaskGroupHeadPanel extends FormPanel { render() { const { - edited, classes, readOnly, rights + edited, classes, readOnly, rights, } = this.props; const taskGroup = { ...edited }; const filterAllowedSources = (options) => { diff --git a/src/pickers/TaskSourceAllowedPicker.js b/src/pickers/TaskSourceAllowedPicker.js index 62c3ca1..6fd7838 100644 --- a/src/pickers/TaskSourceAllowedPicker.js +++ b/src/pickers/TaskSourceAllowedPicker.js @@ -3,7 +3,7 @@ import { Autocomplete, useTranslations, useModulesManager } from '@openimis/fe-c import { TASK_CONTRIBUTION_KEY } from '../constants'; function TaskSourceAllowedPicker({ - onChange, readOnly, required, withLabel, value + onChange, readOnly, required, withLabel, value, }) { const modulesManager = useModulesManager(); const { formatMessage } = useTranslations('tasksManagement'); diff --git a/src/pickers/TaskSourcePicker.js b/src/pickers/TaskSourcePicker.js index f68f9fd..3d94051 100644 --- a/src/pickers/TaskSourcePicker.js +++ b/src/pickers/TaskSourcePicker.js @@ -12,7 +12,7 @@ function TaskSourcePicker({ required, withLabel, value, - filterOptions + filterOptions, }) { const modulesManager = useModulesManager(); const { formatMessage } = useTranslations('tasksManagement'); diff --git a/src/reducer.js b/src/reducer.js index 68ebb2e..d81e26e 100644 --- a/src/reducer.js +++ b/src/reducer.js @@ -167,8 +167,9 @@ function reducer( ? JSON.parse(taskGroup.jsonExt).task_sources.map((source) => ({ id: source, name: source })) : [], taskAllowedSources: taskGroup?.taskAllowedSources - ? JSON.parse(taskGroup?.taskAllowedSources).task_allowed_sources.map((source) => ({ id: source, name: source })) - : [], + ? JSON.parse(taskGroup?.taskAllowedSources).task_allowed_sources.map( + (source) => ({ id: source, name: source }), + ) : [], }))?.[0], fetchingTaskGroup: false, errorTaskGroup: formatGraphQLError(action.payload),