Skip to content

Commit

Permalink
Merge pull request #46 from openimis/develop
Browse files Browse the repository at this point in the history
MERGING develop into release/24.04
  • Loading branch information
delcroip authored Apr 25, 2024
2 parents fb80c9e + 9876f51 commit 1cd31e4
Show file tree
Hide file tree
Showing 11 changed files with 493 additions and 11 deletions.
146 changes: 146 additions & 0 deletions src/components/TaskAllFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import React from 'react';
import { injectIntl } from 'react-intl';
import { Grid } from '@material-ui/core';
import { withTheme, withStyles } from '@material-ui/core/styles';
import _debounce from 'lodash/debounce';
import {
TextInput, PublishedComponent, formatMessage, decodeId, toISODateTime,
} from '@openimis/fe-core';
import { defaultFilterStyles } from '../utils/styles';
import {
CONTAINS_LOOKUP, DEFAULT_DEBOUNCE_TIME, EMPTY_STRING, MODULE_NAME,
} from '../constants';

function TaskAllFilter({
intl, classes, filters, onChangeFilters,
}) {
const debouncedOnChangeFilters = _debounce(onChangeFilters, DEFAULT_DEBOUNCE_TIME);

const filterValue = (filterName) => filters?.[filterName]?.value;

const filterTextFieldValue = (filterName) => filters?.[filterName]?.value ?? EMPTY_STRING;

const onChangeStringFilter = (filterName, lookup = null) => (value) => {
if (lookup) {
debouncedOnChangeFilters([
{
id: filterName,
value,
filter: `${filterName}_${lookup}: "${value}"`,
},
]);
} else {
onChangeFilters([
{
id: filterName,
value,
filter: `${filterName}: "${value}"`,
},
]);
}
};

return (
<Grid container className={classes.form}>
<Grid item xs={3} className={classes.item}>
<PublishedComponent
pubRef="tasksManagement.taskSourcesPicker"
module={MODULE_NAME}
withLabel
nullLabel={formatMessage(intl, MODULE_NAME, 'any')}
withNull
value={filterValue('source')}
onChange={(value) => onChangeFilters([
{
id: 'source',
value,
filter: value ? `source: "${value}"` : EMPTY_STRING,
},
])}
/>
</Grid>
<Grid item xs={3} className={classes.item}>
<PublishedComponent
pubRef="tasksManagement.taskTypesPicker"
module={MODULE_NAME}
withLabel
nullLabel={formatMessage(intl, MODULE_NAME, 'any')}
withNull
value={filterValue('businessEvent')}
onChange={onChangeStringFilter('businessEvent', CONTAINS_LOOKUP)}
/>
</Grid>
<Grid item xs={3} className={classes.item}>
<TextInput
module={MODULE_NAME}
label="task.entity"
value={filterTextFieldValue('entityString')}
onChange={onChangeStringFilter('entityString', CONTAINS_LOOKUP)}
/>
</Grid>
<Grid item xs={3} className={classes.item}>
<PublishedComponent
pubRef="tasksManagement.taskGroupPicker"
module={MODULE_NAME}
value={filterValue('taskGroupId')}
onChange={(value) => onChangeFilters([
{
id: 'taskGroupId',
value,
filter: value?.id ? `taskGroupId: "${decodeId(value.id)}"` : '',
},
])}
/>
</Grid>
<Grid item xs={3} className={classes.item}>
<PublishedComponent
pubRef="tasksManagement.taskStatusPicker"
module={MODULE_NAME}
withLabel
nullLabel={formatMessage(intl, MODULE_NAME, 'any')}
withNull
value={filterValue('status')}
onChange={(value) => onChangeFilters([
{
id: 'status',
value,
filter: value ? `status: ${value}` : EMPTY_STRING,
},
])}
/>
</Grid>
<Grid item xs={3} className={classes.item}>
<PublishedComponent
pubRef="core.DatePicker"
module={MODULE_NAME}
label={formatMessage(intl, MODULE_NAME, 'task.dateCreated.after')}
value={filterValue('dateCreated_Gte')}
onChange={(v) => onChangeFilters([
{
id: 'dateCreated_Gte',
value: v,
filter: `dateCreated_Gte: "${toISODateTime(v)}"`,
},
])}
/>
</Grid>
<Grid item xs={3} className={classes.item}>
<PublishedComponent
pubRef="core.DatePicker"
module={MODULE_NAME}
label={formatMessage(intl, MODULE_NAME, 'task.dateCreated.before')}
value={filterValue('dateCreated_Lte')}
onChange={(v) => onChangeFilters([
{
id: 'dateCreated_Lte',
value: v,
filter: `dateCreated_Lte: "${toISODateTime(v)}"`,
},
])}
/>
</Grid>
</Grid>
);
}

export default injectIntl(withTheme(withStyles(defaultFilterStyles)(TaskAllFilter)));
142 changes: 142 additions & 0 deletions src/components/TaskAllSearcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
Searcher,
useHistory,
historyPush,
useModulesManager,
useTranslations,
} from '@openimis/fe-core';
import { IconButton, Tooltip } from '@material-ui/core';
import VisibilityIcon from '@material-ui/icons/Visibility';
import {
RIGHT_TASKS_MANAGEMENT_SEARCH, DEFAULT_PAGE_SIZE, ROWS_PER_PAGE_OPTIONS, TASK_STATUS, TASK_ROUTE,
} from '../constants';
import TaskAllFilter from './TaskAllFilter';
import { fetchTasks } from '../actions';
import trimBusinessEvent from '../utils/trimBusinessEvent';

function TaskAllSearcher({
rights, showFilters = true,
}) {
const history = useHistory();
const modulesManager = useModulesManager();
const dispatch = useDispatch();
const {
formatMessage,
formatMessageWithValues,
formatDateTimeFromISO,
} = useTranslations('tasksManagement', modulesManager);

const fetchingTasks = useSelector((state) => state?.tasksManagement?.fetchingTasks);
const fetchedTasks = useSelector((state) => state?.tasksManagement?.fetchedTasks);
const errorTasks = useSelector((state) => state?.tasksManagement?.errorTasks);
const tasks = useSelector((state) => state?.tasksManagement?.tasks);
const tasksPageInfo = useSelector((state) => state?.tasksManagement?.tasksPageInfo);
const tasksTotalCount = useSelector((state) => state?.tasksManagement?.tasksTotalCount);

const openTask = (task, newTab = false) => historyPush(
modulesManager,
history,
TASK_ROUTE,
[task?.id],
newTab,
);

const onDoubleClick = (task) => openTask(task);
const fetch = (params) => dispatch(fetchTasks(modulesManager, params));

const rowIdentifier = (task) => task.id;

const isRowDisabled = (_, task) => task.status !== TASK_STATUS.ACCEPTED;

const headers = () => {
const headers = [
'task.source',
'task.type',
'task.entity',
'task.assignee',
'task.dateCreated',
'task.status',
];
if (rights.includes(RIGHT_TASKS_MANAGEMENT_SEARCH)) {
headers.push('emptyLabel');
}
return headers;
};

const sorts = () => [
['source', true],
['type', true],
['entity', true],
['assignee', true],
['date_created', true],
['status', true],
];

const itemFormatters = () => [
(task) => task.source,
(task) => trimBusinessEvent(task.businessEvent),
(task) => task.entityString,
(task) => task?.taskGroup?.code,
(task) => formatDateTimeFromISO(task?.dateCreated),
(task) => task.status,
(task) => (
<Tooltip title={formatMessage('viewDetailsButton.tooltip')}>
<IconButton
onClick={() => openTask(task)}
>
<VisibilityIcon />
</IconButton>
</Tooltip>
),
];

const defaultFilters = () => {
const filters = {
isDeleted: {
value: false,
filter: 'isDeleted: false',
},
};
return filters;
};

const taskFilter = (props) => (
<TaskAllFilter
intl={props.intl}
classes={props.classes}
filters={props.filters}
onChangeFilters={props.onChangeFilters}
/>
);

return (
<Searcher
module="tasksManagement"
FilterPane={showFilters && taskFilter}
fetch={fetch}
items={tasks}
itemsPageInfo={tasksPageInfo}
fetchingItems={fetchingTasks}
fetchedItems={fetchedTasks}
errorItems={errorTasks}
tableTitle={formatMessageWithValues('task.searcherResultsTitle', {
tasksTotalCount,
})}
headers={headers}
itemFormatters={itemFormatters}
sorts={sorts}
rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS}
defaultPageSize={DEFAULT_PAGE_SIZE}
defaultOrderBy="-dateCreated"
rowIdentifier={rowIdentifier}
onDoubleClick={onDoubleClick}
defaultFilters={defaultFilters()}
rowDisabled={isRowDisabled}
rights={rights}
/>
);
}

export default TaskAllSearcher;
46 changes: 38 additions & 8 deletions src/components/TaskFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { Grid } from '@material-ui/core';
import { withTheme, withStyles } from '@material-ui/core/styles';
import _debounce from 'lodash/debounce';
import {
TextInput, PublishedComponent, formatMessage, decodeId,
TextInput, PublishedComponent, formatMessage, decodeId, toISODateTime,
} from '@openimis/fe-core';
import { defaultFilterStyles } from '../utils/styles';
import {
CONTAINS_LOOKUP, DEFAULT_DEBOUNCE_TIME, EMPTY_STRING,
CONTAINS_LOOKUP, DEFAULT_DEBOUNCE_TIME, EMPTY_STRING, MODULE_NAME,
} from '../constants';

function TaskFilter({
Expand Down Expand Up @@ -44,7 +44,7 @@ function TaskFilter({
<Grid container className={classes.form}>
<Grid item xs={3} className={classes.item}>
<TextInput
module="tasksManagement"
module={MODULE_NAME}
label="task.source"
value={filterTextFieldValue('source')}
onChange={onChangeStringFilter('source', CONTAINS_LOOKUP)}
Expand All @@ -53,15 +53,15 @@ function TaskFilter({
</Grid>
<Grid item xs={3} className={classes.item}>
<TextInput
module="tasksManagement"
module={MODULE_NAME}
label="task.type"
value={filterTextFieldValue('type')}
onChange={onChangeStringFilter('businessEvent', CONTAINS_LOOKUP)}
/>
</Grid>
<Grid item xs={3} className={classes.item}>
<TextInput
module="tasksManagement"
module={MODULE_NAME}
label="task.entity"
value={filterTextFieldValue('entity')}
onChange={onChangeStringFilter('entityString', CONTAINS_LOOKUP)}
Expand All @@ -70,7 +70,7 @@ function TaskFilter({
<Grid item xs={3} className={classes.item}>
<PublishedComponent
pubRef="tasksManagement.taskGroupPicker"
module="tasksManagement"
module={MODULE_NAME}
value={filterValue('taskGroupId')}
onChange={(value) => onChangeFilters([
{
Expand All @@ -84,9 +84,9 @@ function TaskFilter({
<Grid item xs={3} className={classes.item}>
<PublishedComponent
pubRef="tasksManagement.taskStatusPicker"
module="tasksManagement"
module={MODULE_NAME}
withLabel
nullLabel={formatMessage(intl, 'tasksManagement', 'any')}
nullLabel={formatMessage(intl, MODULE_NAME, 'any')}
withNull
value={filterValue('status')}
onChange={(value) => onChangeFilters([
Expand All @@ -98,6 +98,36 @@ function TaskFilter({
])}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<PublishedComponent
pubRef="core.DatePicker"
module={MODULE_NAME}
label={formatMessage(intl, MODULE_NAME, 'task.dateCreated.after')}
value={filterValue('dateCreated_Gte')}
onChange={(v) => onChangeFilters([
{
id: 'dateCreated_Gte',
value: v,
filter: `dateCreated_Gte: "${toISODateTime(v)}"`,
},
])}
/>
</Grid>
<Grid item xs={2} className={classes.item}>
<PublishedComponent
pubRef="core.DatePicker"
module={MODULE_NAME}
label={formatMessage(intl, MODULE_NAME, 'task.dateCreated.before')}
value={filterValue('dateCreated_Lte')}
onChange={(v) => onChangeFilters([
{
id: 'dateCreated_Lte',
value: v,
filter: `dateCreated_Lte: "${toISODateTime(v)}"`,
},
])}
/>
</Grid>
</Grid>
);
}
Expand Down
Loading

0 comments on commit 1cd31e4

Please sign in to comment.