Skip to content

Commit

Permalink
ONI-255: Allowed sources picker.
Browse files Browse the repository at this point in the history
  • Loading branch information
wzgliniecki committed Jun 3, 2024
1 parent 5d2b0d8 commit de4bd82
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/components/groups-management/TaskGroupHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -86,6 +96,14 @@ class TaskGroupHeadPanel extends FormPanel {
readOnly={readOnly}
value={taskGroup?.taskSources}
onChange={(sources) => this.updateAttribute('taskSources', sources)}
filterOptions={filterAllowedSources}
/>
</Grid>
<Grid item xs={6} className={classes.item}>
<TaskSourceAllowedPicker
readOnly={!(rights.includes(TASK_GROUP_CREATE) || rights.includes(TASK_GROUP_UPDATE))}
value={taskGroup?.taskAllowedSources}
onChange={(allowedSources) => this.updateAttribute('taskAllowedSources', allowedSources)}
/>
</Grid>
</Grid>
Expand Down
43 changes: 43 additions & 0 deletions src/pickers/TaskSourceAllowedPicker.js
Original file line number Diff line number Diff line change
@@ -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 (
<Autocomplete
multiple
required={required}
label={formatMessage('TaskSourceAllowedPicker.label')}
placeholder={formatMessage('TaskSourceAllowedPicker.placeholder')}
readOnly={readOnly}
withLabel={withLabel}
withPlaceholder={!value?.length}
options={allowedSources}
value={value}
getOptionLabel={(source) => `${source.name}`}
onChange={onChange}
filterSelectedOptions
onInputChange={() => {}}
/>
);
}

export default TaskSourceAllowedPicker;
3 changes: 2 additions & 1 deletion src/pickers/TaskSourcePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function TaskSourcePicker({
required,
withLabel,
value,
filterOptions
}) {
const modulesManager = useModulesManager();
const { formatMessage } = useTranslations('tasksManagement');
Expand All @@ -34,7 +35,7 @@ function TaskSourcePicker({
value={value}
getOptionLabel={(source) => `${source.name}`}
onChange={onChange}
filterSelectedOptions
filterOptions={filterOptions}
onInputChange={() => {}}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit de4bd82

Please sign in to comment.