Skip to content

Commit

Permalink
Fix date picker value selection in inventory filters (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbbyB97 authored Aug 28, 2024
1 parent f86e5c1 commit a6aa4bf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/components/FilterWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import {
SearchFilterRequestDto,
} from 'types/openapi';
import { getFormTypeFromAttributeContentType, getFormTypeFromFilterFieldType, getStepValue } from 'utils/common-utils';
import { checkIfFieldAttributeTypeIsDate, getFormattedDate, getFormattedDateTime, getFormattedUtc } from 'utils/dateUtil';
import {
checkIfFieldAttributeTypeIsDate,
checkIfFieldTypeIsDate,
getFormattedDate,
getFormattedDateTime,
getFormattedUtc,
} from 'utils/dateUtil';
import styles from './FilterWidget.module.scss';

const noValue: { [condition in FilterConditionOperator]: boolean } = {
Expand Down Expand Up @@ -88,12 +94,6 @@ export default function FilterWidget({ onFilterUpdate, title, entity, getAvailab
[],
);

const checkIfFieldTypeIsDate = useCallback((type: FilterFieldType) => {
if (type === FilterFieldType.Date || type === FilterFieldType.Datetime) {
return true;
}
}, []);

useEffect(() => {
dispatch(actions.getAvailableFilters({ entity, getAvailableFiltersApi }));
}, [dispatch, entity, getAvailableFiltersApi]);
Expand Down Expand Up @@ -278,7 +278,6 @@ export default function FilterWidget({ onFilterUpdate, title, entity, getAvailab
dispatch,
entity,
onFilterUpdate,
checkIfFieldTypeIsDate,
]);

const onRemoveFilterClick = useCallback(
Expand Down Expand Up @@ -483,10 +482,24 @@ export default function FilterWidget({ onFilterUpdate, title, entity, getAvailab
onChange={(e) => {
if (
(currentField?.attributeContentType && checkIfFieldAttributeTypeIsDate(currentField)) ||
(currentField?.type && getFormTypeFromFilterFieldType(currentField?.type))
(currentField?.type && checkIfFieldTypeIsDate(currentField?.type))
) {
const dateTimeVal = getFormattedDateTime(e.target.value);
setFilterValue(JSON.parse(JSON.stringify(dateTimeVal)));
if (
currentField?.attributeContentType === AttributeContentType.Date ||
currentField?.type === FilterFieldType.Date
) {
const dateVal = getFormattedDate(e.target.value);
setFilterValue(JSON.parse(JSON.stringify(dateVal)));
return;
}
if (
currentField?.attributeContentType === AttributeContentType.Datetime ||
currentField?.type === FilterFieldType.Datetime
) {
const dateTimeVal = getFormattedDateTime(e.target.value);
setFilterValue(JSON.parse(JSON.stringify(dateTimeVal)));
return;
}
return;
}
setFilterValue(JSON.parse(JSON.stringify(e.target.value)));
Expand Down Expand Up @@ -564,7 +577,8 @@ export default function FilterWidget({ onFilterUpdate, title, entity, getAvailab
field?.platformEnum
? platformEnums[field.platformEnum][f.value as unknown as string]?.label
: (field && field?.attributeContentType === AttributeContentType.Date) ||
field?.type === FilterFieldType.Date
(field?.type === FilterFieldType.Date &&
field?.attributeContentType !== AttributeContentType.Datetime)
? getFormattedDate(f.value as unknown as string)
: (field && field?.attributeContentType === AttributeContentType.Datetime) ||
field?.type === FilterFieldType.Datetime
Expand Down
6 changes: 6 additions & 0 deletions src/utils/dateUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,9 @@ export const checkIfFieldAttributeTypeIsDate = (field: SearchFieldDataDto) => {
return false;
}
};

export const checkIfFieldTypeIsDate = (type: FilterFieldType) => {
if (type === FilterFieldType.Date || type === FilterFieldType.Datetime) {
return true;
}
};

0 comments on commit a6aa4bf

Please sign in to comment.