diff --git a/packages/common/src/components/Filter/DateRangeFilter.tsx b/packages/common/src/components/Filter/DateRangeFilter.tsx
index 6bd04c22b..d756fa1b9 100644
--- a/packages/common/src/components/Filter/DateRangeFilter.tsx
+++ b/packages/common/src/components/Filter/DateRangeFilter.tsx
@@ -6,9 +6,11 @@ import {
InputGroup,
isValidDate as isValidJSDate,
ToolbarFilter,
+ Tooltip,
} from '@patternfly/react-core';
import {
+ abbreviateInterval,
isValidDate,
isValidInterval,
parseISOtoJSDate,
@@ -23,7 +25,7 @@ import { FilterTypeProps } from './types';
* Precisely given range [A,B) a date X in the range if A <= X < B.
*
* **FilterTypeProps are interpreted as follows**:
- * 1) selectedFilters - date range encoded as ISO 8601 time interval string ("dateFrom/dateTo").
+ * 1) selectedFilters - date range encoded as ISO 8601 time interval string ("dateFrom/dateTo"). Only date part is used (no time).
* 2) onFilterUpdate - accepts the list of ranges.
*
* [
@@ -42,8 +44,18 @@ export const DateRangeFilter = ({
const [from, setFrom] = useState();
const [to, setTo] = useState();
- const rangeToOption = (range: string): string => range.replace('/', ' - ');
- const optionToRange = (option: string): string => option.replace(' - ', '/');
+ const rangeToOption = (range: string) => {
+ const abbr = abbreviateInterval(range);
+ return {
+ key: range,
+ node: (
+
+ {abbr ?? ''}
+
+ ),
+ };
+ };
+ const optionToRange = (option): string => option?.key;
const clearSingleRange = (option) => {
const target = optionToRange(option);
@@ -51,6 +63,7 @@ export const DateRangeFilter = ({
};
const onFromDateChange = (even: FormEvent, value: string) => {
+ //see DateFilter onDateChange
if (value?.length === 10 && isValidDate(value)) {
setFrom(parseISOtoJSDate(value));
setTo(undefined);
@@ -58,6 +71,7 @@ export const DateRangeFilter = ({
};
const onToDateChange = (even: FormEvent, value: string) => {
+ //see DateFilter onDateChange
if (value?.length === 10 && isValidDate(value)) {
const newTo = parseISOtoJSDate(value);
setTo(newTo);
@@ -82,7 +96,7 @@ export const DateRangeFilter = ({
dateFormat={(date) => DateTime.fromJSDate(date).toISODate()}
dateParse={(str) => DateTime.fromISO(str).toJSDate()}
onChange={onFromDateChange}
- aria-label={'Interval start'}
+ aria-label="Interval start"
placeholder={placeholderLabel}
invalidFormatText={placeholderLabel}
// default value ("parent") creates collision with sticky table header
@@ -91,7 +105,7 @@ export const DateRangeFilter = ({
{
const target = Interval.fromDateTimes(DateTime.fromJSDate(from), DateTime.fromJSDate(to));
return target.isValid ? target.toISODate() : undefined;
};
+
+export const abbreviateInterval = (isoInterval: string): string | undefined => {
+ const interval = Interval.fromISO(isoInterval);
+ if (!interval.isValid) {
+ return undefined;
+ }
+ return `${interval.start.toFormat('MM-dd')} - ${interval.end.toFormat('MM-dd')}`;
+};