Skip to content

Commit

Permalink
Revert "ONI-255: Basic allowed task source picker and filtering." (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski authored Jun 26, 2024
1 parent 7ce985b commit 008f64a
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 79 deletions.
3 changes: 0 additions & 3 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const TASK_GROUP_PROJECTION = () => [
'code',
'completionPolicy',
'taskexecutorSet { edges { node { user { id username lastName } } } }',
'taskAllowedSources',
];

const TASK_FULL_PROJECTION = () => [
Expand Down Expand Up @@ -65,7 +64,6 @@ export const formatTaskGroupGQL = (taskGroup) => {
${taskGroup?.id ? `id: "${taskGroup.id}"` : ''}
${taskGroup?.taskexecutorSet ? `userIds: ${executorsString}` : 'userIds: []'}
${taskGroup?.taskSources ? `taskSources: ${taskSourcesString}` : 'taskSources: []'}
${taskGroup?.taskAllowedSources ? `taskAllowedSources: ${taskSourcesString}` : 'taskAllowedSources: []'}
`;
};

Expand Down Expand Up @@ -124,7 +122,6 @@ export function fetchTaskGroup(modulesManager, variables) {
completionPolicy
jsonExt
taskexecutorSet { edges { node { user { id username lastName } } } },
taskAllowedSources
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/components/TaskHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ 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)}
/>
Expand Down
19 changes: 1 addition & 18 deletions src/components/groups-management/TaskGroupHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ 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 @@ -45,16 +43,9 @@ const renderHeadPanelTitle = (classes) => (
class TaskGroupHeadPanel extends FormPanel {
render() {
const {
edited, classes, readOnly, rights,
edited, classes, readOnly,
} = this.props;
const taskGroup = { ...edited };
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 @@ -95,14 +86,6 @@ 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
19 changes: 5 additions & 14 deletions src/pickers/TaskGroupPicker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React, { useState } from 'react';

import {
useModulesManager, useTranslations, Autocomplete, useGraphqlQuery,
useModulesManager,
useTranslations,
Autocomplete,
useGraphqlQuery,
} from '@openimis/fe-core';

function TaskGroupPicker(props) {
Expand All @@ -13,7 +16,6 @@ function TaskGroupPicker(props) {
withPlaceholder,
value,
label,
source = null,
filterOptions,
filterSelectedOptions,
placeholder,
Expand All @@ -33,7 +35,6 @@ function TaskGroupPicker(props) {
id
code
completionPolicy
taskAllowedSources
}
}
}
Expand All @@ -44,16 +45,6 @@ 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 (
<Autocomplete
multiple={multiple}
Expand All @@ -64,7 +55,7 @@ function TaskGroupPicker(props) {
withLabel={withLabel}
withPlaceholder={withPlaceholder}
readOnly={readOnly}
options={filteredOptionsWithAllowedSources}
options={data?.taskGroup?.edges.map((edge) => edge.node) ?? []}
isLoading={isLoading}
value={value}
getOptionLabel={(option) => `${option.code}`}
Expand Down
35 changes: 0 additions & 35 deletions src/pickers/TaskSourceAllowedPicker.js

This file was deleted.

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

Please sign in to comment.