Skip to content

Commit

Permalink
ONI-255: Proper filtering of task group by allowed source.
Browse files Browse the repository at this point in the history
  • Loading branch information
wzgliniecki committed Jun 6, 2024
1 parent 220e3c6 commit e75e7b2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const TASK_GROUP_PROJECTION = () => [
'code',
'completionPolicy',
'taskexecutorSet { edges { node { user { id username lastName } } } }',
'taskAllowedSources'
'taskAllowedSources',
];

const TASK_FULL_PROJECTION = () => [
Expand Down
1 change: 1 addition & 0 deletions src/components/TaskHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
/>
Expand Down
8 changes: 4 additions & 4 deletions src/components/groups-management/TaskGroupHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Check failure on line 58 in src/components/groups-management/TaskGroupHeadPanel.js

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon
return (
<>
Expand Down
31 changes: 19 additions & 12 deletions src/pickers/TaskGroupPicker.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import React, { useState } from 'react';
import React, { useState } from "react";

Check failure on line 1 in src/pickers/TaskGroupPicker.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

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

Check failure on line 3 in src/pickers/TaskGroupPicker.js

View workflow job for this annotation

GitHub Actions / lint

Expected a line break after this opening brace

Check failure on line 3 in src/pickers/TaskGroupPicker.js

View workflow job for this annotation

GitHub Actions / lint

Expected a line break before this closing brace

Check failure on line 3 in src/pickers/TaskGroupPicker.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

function TaskGroupPicker(props) {
const {
Expand All @@ -16,15 +11,16 @@ function TaskGroupPicker(props) {
withPlaceholder,
value,
label,
source = null,
filterOptions,
filterSelectedOptions,
placeholder,
multiple,
} = props;

const modulesManager = useModulesManager();
const { formatMessage } = useTranslations('claim', modulesManager);
const [searchString, setSearchString] = useState('');
const { formatMessage } = useTranslations("claim", modulesManager);

Check failure on line 22 in src/pickers/TaskGroupPicker.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
const [searchString, setSearchString] = useState("");

Check failure on line 23 in src/pickers/TaskGroupPicker.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

const { isLoading, data, error } = useGraphqlQuery(
`
Expand All @@ -35,6 +31,7 @@ function TaskGroupPicker(props) {
id
code
completionPolicy
taskAllowedSources
}
}
}
Expand All @@ -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;

Check failure on line 49 in src/pickers/TaskGroupPicker.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
const usersAllowedSources = allowedSources.flatMap((source) => source.task_allowed_sources);

return usersAllowedSources.includes(source);
});

return (
<Autocomplete
multiple={multiple}
required={required}
placeholder={placeholder ?? formatMessage('tasksManagement.taskGroup.placeholder')}
label={label ?? formatMessage('tasksManagement.task.assignee')}
placeholder={placeholder ?? formatMessage("tasksManagement.taskGroup.placeholder")}

Check failure on line 59 in src/pickers/TaskGroupPicker.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
label={label ?? formatMessage("tasksManagement.task.assignee")}

Check failure on line 60 in src/pickers/TaskGroupPicker.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
error={error}
withLabel={withLabel}
withPlaceholder={withPlaceholder}
readOnly={readOnly}
options={data?.taskGroup?.edges.map((edge) => edge.node) ?? []}
options={filteredOptionsWithAllowedSources}
isLoading={isLoading}
value={value}
getOptionLabel={(option) => `${option.code}`}
Expand Down
24 changes: 7 additions & 17 deletions src/pickers/TaskSourceAllowedPicker.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,8 +15,8 @@ function TaskSourceAllowedPicker({
<Autocomplete
multiple
required={required}
label={formatMessage('TaskSourceAllowedPicker.label')}
placeholder={formatMessage('TaskSourceAllowedPicker.placeholder')}
label={formatMessage("TaskSourceAllowedPicker.label")}
placeholder={formatMessage("TaskSourceAllowedPicker.placeholder")}
readOnly={readOnly}
withLabel={withLabel}
withPlaceholder={!value?.length}
Expand Down

0 comments on commit e75e7b2

Please sign in to comment.