Skip to content

Commit

Permalink
hotfix: fix group details page, improve worker picker (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
olewandowski1 authored Oct 31, 2024
1 parent d7ed8f1 commit 7d66d1a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
6 changes: 5 additions & 1 deletion src/pages/GroupDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function GroupDetailsPage({ match }) {
const groupUuid = match?.params?.group_uuid;
const { formatMessage, formatMessageWithValues } = useTranslations(MODULE_NAME, modulesManager);
const [reset, setReset] = useState(0);
const [isGroupSaving, setIsGroupSaving] = useState(false);

const titleParams = (group) => ({
name: group?.name ?? EMPTY_STRING,
Expand Down Expand Up @@ -82,6 +83,7 @@ function GroupDetailsPage({ match }) {
const canSave = () => !!(edited?.name && edited?.workers?.length);

const onSave = () => {
setIsGroupSaving(true);
try {
if (groupUuid) {
dispatch(updateGroup(economicUnit, edited, 'Update Group'));
Expand All @@ -94,6 +96,8 @@ function GroupDetailsPage({ match }) {
detail: error,
}),
);
} finally {
setIsGroupSaving(false);
}
};

Expand Down Expand Up @@ -134,7 +138,7 @@ function GroupDetailsPage({ match }) {
edited={edited}
back={() => history.goBack()}
Panels={[GroupMasterPanel]}
isSaving={submittingMutation}
isSaving={isGroupSaving}
formatMessage={formatMessage}
rights={rights}
onEditedChanged={setEdited}
Expand Down
36 changes: 2 additions & 34 deletions src/pickers/WorkerMultiplePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ import {
WORKER_IMPORT_GROUP_OF_WORKERS,
WORKER_IMPORT_PREVIOUS_DAY,
WORKER_IMPORT_PREVIOUS_WORKERS,
WORKER_THRESHOLD,
} from '../constants';
import { getYesterdaysDate } from '../utils/utils';
import { fetchAllAvailableWorkers } from '../actions';

function WorkerMultiplePicker({
readOnly, value, onChange, required, filterSelectedOptions,
readOnly, value, onChange, required,
}) {
const modulesManager = useModulesManager();
const { formatMessage } = useTranslations(MODULE_NAME, modulesManager);
Expand All @@ -38,7 +37,6 @@ function WorkerMultiplePicker({
const [previousDayWorkers, setPreviousDayWorkers] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(null);
const [searchString, setSearchString] = useState('');
const isDisabled = readOnly || isLoading;
const [configurationDialogOpen, setConfigurationDialogOpen] = useState(false);
const [importPlan, setImportPlan] = useState(undefined);
Expand Down Expand Up @@ -74,27 +72,6 @@ function WorkerMultiplePicker({
loadData();
}, [dispatch, economicUnitCode, yesterday]);

const filterOptionsBySearchString = (options) => {
const splitByWhitespaceRegex = /\s+/;
const filterableSearchString = searchString.toLowerCase().trim();
const searchTerms = filterableSearchString.split(splitByWhitespaceRegex);

return options.filter((option) => {
const chfId = option?.chfId?.toLowerCase() || '';
const lastName = option?.lastName?.toLowerCase() || '';
const otherNames = option?.otherNames?.toLowerCase() || '';

return searchTerms.every((term) => chfId.includes(term) || lastName.includes(term) || otherNames.includes(term));
});
};

const filterOptions = (options) => {
if (searchString.length < WORKER_THRESHOLD || isLoading) {
return [];
}
return filterOptionsBySearchString(options);
};

const handleImportDialogOpen = () => {
setConfigurationDialogOpen((prevState) => !prevState);
};
Expand Down Expand Up @@ -151,15 +128,7 @@ function WorkerMultiplePicker({
onChange={onChange}
value={value}
getOptionSelected={(option, value) => option.uuid === value.uuid}
filterOptions={filterOptions}
noOptionsText={
searchString.length < WORKER_THRESHOLD
? formatMessage('workerVoucher.WorkerMultiplePicker.underThreshold')
: formatMessage('workerVoucher.WorkerMultiplePicker.noOptions')
}
filterSelectedOptions={filterSelectedOptions}
onInputChange={(_, newInputValue) => setSearchString(newInputValue)}
setCurrentString={setSearchString}
noOptionsText={formatMessage('workerVoucher.WorkerMultiplePicker.noOptions')}
disableCloseOnSelect
getOptionLabel={({ chfId, lastName, otherNames }) => `${chfId} ${lastName} ${otherNames}`}
renderOption={(option, { selected }) => (
Expand Down Expand Up @@ -196,7 +165,6 @@ function WorkerMultiplePicker({
style={{
zIndex: 1300,
maxHeight: dropdownMaxHeight,
overflowY: 'auto',
}}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"workerVoucher.acquire.confirmation": "I confirm the voucher acquirement, acknowledging that I have read and agree to the terms and policies.",
"workerVoucher.assign.confirmation": "I confirm the voucher assignment, acknowledging that I have read and agree to the terms and policies.",
"workerVoucher.vouchers.required": "You need to fill out all required fields to continue",
"workerVoucher.WorkerMultiplePicker.placeholder": "Search for Worker",
"workerVoucher.WorkerMultiplePicker.placeholder": "Search by IDNP, Worker First Name or Last Name",
"workerVoucher.WorkerMultiplePicker.underThreshold": "Enter at least 3 characters: IDNP, Worker First Name or Last Name",
"workerVoucher.WorkerMultiplePicker.noOptions": "No results",
"workerVoucher.WorkerDateRangePicker.selectDate": "Select Date",
Expand Down

0 comments on commit 7d66d1a

Please sign in to comment.