Skip to content

Commit

Permalink
CM-722: allow to add task source to task group (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdolkowski authored Feb 27, 2024
1 parent 25bdb11 commit cb3066b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ const TASKS_FULL_PROJECTION = () => [

export const formatTaskGroupGQL = (taskGroup) => {
const executors = taskGroup?.taskexecutorSet?.map((executor) => decodeId(executor.id));
const taskSources = taskGroup?.taskSources?.map((taskSource) => taskSource.name);
const executorsString = executors ? `[${executors.map((executorUuid) => `"${executorUuid}"`).join(', ')}]` : '[]';
const taskSourcesString = taskSources
? `[${taskSources.map((taskSourceName) => `"${taskSourceName}"`).join(', ')}]`
: '[]';
return `
${taskGroup?.code ? `code: "${formatGQLString(taskGroup.code)}"` : ''}
${taskGroup?.completionPolicy ? `completionPolicy: ${taskGroup.completionPolicy}` : ''}
${taskGroup?.id ? `id: "${taskGroup.id}"` : ''}
${taskGroup?.taskexecutorSet ? `userIds: ${executorsString}` : 'userIds: []'}
${taskGroup?.taskSources ? `taskSources: ${taskSourcesString}` : 'taskSources: []'}
`;
};

Expand Down Expand Up @@ -116,6 +121,7 @@ export function fetchTaskGroup(modulesManager, variables) {
uuid
code
completionPolicy
jsonExt
taskexecutorSet { edges { node { user { id username lastName } } } },
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/components/groups-management/TaskGroupHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { injectIntl } from 'react-intl';
import { withTheme, withStyles } from '@material-ui/core/styles';
import TaskExecutorsPicker from '../../pickers/TaskExecutorsPicker';
import GroupPolicyPicker from '../../pickers/GroupPolicyPicker';
import TaskSourcePicker from '../../pickers/TaskSourcePicker';

const styles = (theme) => ({
tableTitle: theme.table.title,
Expand Down Expand Up @@ -80,6 +81,13 @@ class TaskGroupHeadPanel extends FormPanel {
onChange={(executors) => this.updateAttribute('taskexecutorSet', executors)}
/>
</Grid>
<Grid item xs={6} className={classes.item}>
<TaskSourcePicker
readOnly={readOnly}
value={taskGroup?.taskSources}
onChange={(sources) => this.updateAttribute('taskSources', sources)}
/>
</Grid>
</Grid>
</>
);
Expand Down
41 changes: 41 additions & 0 deletions src/pickers/TaskSourcePicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import {
Autocomplete, useTranslations, useModulesManager,
} from '@openimis/fe-core';
import { TASK_CONTRIBUTION_KEY } from '../constants';

function TaskSourcePicker({
onChange,
readOnly,
required,
withLabel,
value,
}) {
const modulesManager = useModulesManager();
const { formatMessage } = useTranslations('tasksManagement');
const contributions = modulesManager.getContribs(TASK_CONTRIBUTION_KEY);
const sources = contributions.flatMap((contribution) => {
const source = contribution.taskSource;
return source ? [{ id: source, name: source }] : [];
});

return (
<Autocomplete
multiple
required={required}
label={formatMessage('TaskSourcePicker.label')}
placeholder={formatMessage('TaskSourcePicker.placeholder')}
readOnly={readOnly}
withLabel={withLabel}
withPlaceholder={!value?.length}
options={sources}
value={value}
getOptionLabel={(source) => `${source.name}`}
onChange={onChange}
filterSelectedOptions
onInputChange={() => {}}
/>
);
}

export default TaskSourcePicker;
3 changes: 3 additions & 0 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ function reducer(
...taskGroup,
id: decodeId(taskGroup.id),
taskexecutorSet: taskGroup?.taskexecutorSet?.edges?.map((executor) => executor.node.user),
taskSources: taskGroup?.jsonExt
? JSON.parse(taskGroup.jsonExt).task_sources.map((source) => ({ id: source, name: source }))
: null,
}))?.[0],
fetchingTaskGroup: false,
errorTaskGroup: formatGraphQLError(action.payload),
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
"tasksManagement.task.resolve.confirm.title": "Resolve task",
"tasksManagement.task.resolve.confirm.approve.message": "Are you sure you want to approve this task?",
"tasksManagement.task.resolve.confirm.fail.message": "Are you sure you want to fail this task?",
"tasksManagement.menu.taskExecutionerGroups": "Task Executioner Groups"
"tasksManagement.menu.taskExecutionerGroups": "Task Executioner Groups",
"tasksManagement.TaskSourcePicker.label": "Task Sources",
"tasksManagement.TaskSourcePicker.placeholder": "Search for task sources..."
}

0 comments on commit cb3066b

Please sign in to comment.