Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date filter improvements (#5917) #7196

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5635983
Add new operands, draft relative date picker header
ad-elias Sep 15, 2024
80c608c
Generate query filters for new view filter operands
ad-elias Sep 16, 2024
0953394
Disable relative date picker calendar clicking
ad-elias Sep 16, 2024
fa1cae9
Change date filter value to JSON
ad-elias Sep 17, 2024
74cd021
Resolve variable filter values, pick relative dates
ad-elias Sep 19, 2024
e0d2701
Merge branch 'main' into feat/date-filter-improvements-5917
ad-elias Sep 19, 2024
d2bc804
Temporarily disable all new date operands, fix view filter workspace …
ad-elias Sep 20, 2024
146df05
Past and future date filters work
ad-elias Sep 20, 2024
f5a1b14
Add isToday filter operand to date: and query does not work, otherwis…
ad-elias Sep 20, 2024
7462f63
Fix checkForDeletedAtFilter this binding
ad-elias Sep 20, 2024
09bf125
Simplify filter value resolution
ad-elias Sep 21, 2024
7855ba6
Add 'is' filter operand to date. And query does not work.
ad-elias Sep 21, 2024
031ea27
Rename 'greater than' and 'less than' date filters
ad-elias Sep 21, 2024
5c5b5f0
Enable relative date filtering. And query does not work, date range h…
ad-elias Sep 22, 2024
7e1eafe
Highlight selected relative dates
ad-elias Sep 23, 2024
577f83d
Merge branch 'main' into feat/date-filter-improvements-5917
ad-elias Sep 23, 2024
10f4f87
Remove unused code
ad-elias Sep 23, 2024
3b9c891
Fix broken date selection
ad-elias Sep 23, 2024
3fc73c5
Refactor
ad-elias Sep 23, 2024
b8dc5e6
Remove comments
ad-elias Sep 24, 2024
20d652f
Improve naming
ad-elias Sep 24, 2024
c2dcef5
Default to ViewFilterValueType.STATIC
ad-elias Sep 24, 2024
26d03e7
Improve readability
ad-elias Sep 24, 2024
82c7537
Disable relative date picker header dropdown blur
ad-elias Sep 24, 2024
80adc22
List configurable view filter operands
ad-elias Sep 24, 2024
75f9ddd
Refactor & make 'valueType' required in frontend
ad-elias Sep 24, 2024
6a4789f
Reset value on value type change
ad-elias Sep 25, 2024
0548fc6
Fix number & currency filter operands
ad-elias Sep 26, 2024
c78fdb0
Remove default relative date unit
ad-elias Sep 26, 2024
f915833
Fix date operands test
ad-elias Sep 26, 2024
ef7eba1
Remove filter valueType
ad-elias Sep 27, 2024
36eccfd
Fix date filter default values
ad-elias Sep 27, 2024
9ec65de
Initialize filter value on operand change to immediately show results…
ad-elias Sep 27, 2024
f8d767b
Merge
FelixMalfait Sep 27, 2024
8ad4774
Fix merge
FelixMalfait Sep 27, 2024
34f8e9b
Is this used?
FelixMalfait Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Disable relative date picker calendar clicking
  • Loading branch information
ad-elias committed Sep 16, 2024
commit 0953394c538f64474e41ebe91c7db97477e183ec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { isDefined } from '~/utils/isDefined';

import { DatePickerHeader } from '@/ui/input/components/internal/date/components/DatePickerHeader';
import { RelativeDatePickerHeader } from '@/ui/input/components/internal/date/components/RelativePickerHeader';
import { RelativeDateDirection } from '@/ui/input/components/internal/date/types/RelativeDateDirection';
import { RelativeDateUnit } from '@/ui/input/components/internal/date/types/RelativeDateUnit';
import { UserContext } from '@/users/contexts/UserContext';
import { useContext } from 'react';
import 'react-datepicker/dist/react-datepicker.css';
Expand All @@ -22,7 +24,7 @@ export const MONTH_AND_YEAR_DROPDOWN_MONTH_SELECT_ID =
export const MONTH_AND_YEAR_DROPDOWN_YEAR_SELECT_ID =
'date-picker-month-and-year-dropdown-year-select';

const StyledContainer = styled.div`
const StyledContainer = styled.div<{ calendarDisabled?: boolean }>`
& .react-datepicker {
border-color: ${({ theme }) => theme.border.color.light};
background: transparent;
Expand Down Expand Up @@ -182,6 +184,10 @@ const StyledContainer = styled.div`

& .react-datepicker__month {
margin-top: 0;

pointer-events: ${({ calendarDisabled }) =>
calendarDisabled ? 'none' : 'auto'};
opacity: ${({ calendarDisabled }) => (calendarDisabled ? '0.5' : '1')};
}

& .react-datepicker__day {
Expand Down Expand Up @@ -434,9 +440,11 @@ export const InternalDatePicker = ({
const endOfDayInLocalTimezone = endOfDayDateTimeInLocalTimezone.toJSDate();

const dateToUse = isDateTimeInput ? endOfDayInLocalTimezone : dateWithoutTime;

return (
<StyledContainer onKeyDown={handleKeyDown}>
<StyledContainer
onKeyDown={handleKeyDown}
calendarDisabled={isRelativeToNow}
>
<div className={clearable ? 'clearable ' : ''}>
<ReactDatePicker
open={true}
Expand All @@ -458,12 +466,9 @@ export const InternalDatePicker = ({
}) =>
isRelativeToNow ? (
<RelativeDatePickerHeader
direction=""
value=""
unit=""
onDirectionChange={() => {}}
onValueChange={() => {}}
onUnitChange={() => {}}
direction={RelativeDateDirection.Past}
value={1}
unit={RelativeDateUnit.Day}
onChange={() => {}}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Select } from '@/ui/input/components/Select';
import { TextInput } from '@/ui/input/components/TextInput';
import { RelativeDateUnit } from '../types/RelativeDateUnit';

import { RELATIVE_DATE_DIRECTIONS } from '@/ui/input/components/internal/date/constants/RelativeDateDirectionOptions';
import { RELATIVE_DATE_UNITS } from '@/ui/input/components/internal/date/constants/RelativeDateUnits';
import { RelativeDateDirection } from '@/ui/input/components/internal/date/types/RelativeDateDirection';
import styled from '@emotion/styled';

const StyledContainer = styled.div`
Expand All @@ -12,50 +16,63 @@ const StyledContainer = styled.div`
`;

type RelativeDatePickerHeaderProps = {
direction: string;
value: string;
unit: string;
onDirectionChange: (value: string) => void;
onValueChange: (value: string) => void;
onUnitChange: (value: string) => void;
onChange: (value: { direction: string; value: string; unit: string }) => void;
direction?: RelativeDateDirection;
value?: number;
unit?: RelativeDateUnit;
onChange: (value: {
direction?: RelativeDateDirection;
value?: number;
unit?: RelativeDateUnit;
}) => void;
};

export const RelativeDatePickerHeader = ({
direction,
value,
unit,
onDirectionChange,
onValueChange,
onUnitChange,
onChange,
}: RelativeDatePickerHeaderProps) => {
return (
<StyledContainer>
<Select
dropdownId="direction-select"
value={direction}
onChange={onDirectionChange}
options={[
{ value: 'Past', label: 'Past' },
{ value: 'Next', label: 'Next' },
{ value: 'This', label: 'This' },
]}
onChange={(newDirection) =>
onChange({
direction: newDirection,
value: value,
unit: unit,
})
}
options={RELATIVE_DATE_DIRECTIONS}
/>
<TextInput
value={value}
onChange={(value) => onValueChange(value?.toString() ?? '')}
value={value?.toString() ?? ''}
onChange={(newValue) => {
const newNumericValue = newValue.replace(/[^0-9]/g, '');
const value = newNumericValue
? parseInt(newNumericValue, 10)
: undefined;

onChange({
direction,
value,
unit,
});
}}
placeholder="Number"
/>
<Select
dropdownId="unit-select"
value={unit}
onChange={onUnitChange}
options={[
{ value: 'Day', label: 'Day' },
{ value: 'Week', label: 'Week' },
{ value: 'Month', label: 'Month' },
{ value: 'Year', label: 'Year' },
]}
onChange={(newUnit) =>
onChange({
direction: direction,
value: value,
unit: newUnit,
})
}
options={RELATIVE_DATE_UNITS}
/>
</StyledContainer>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RelativeDateDirection } from '../types/RelativeDateDirection';

export const RELATIVE_DATE_DIRECTIONS: {
value: RelativeDateDirection;
label: string;
}[] = [
{ value: RelativeDateDirection.Past, label: 'Past' },
{ value: RelativeDateDirection.Next, label: 'Next' },
{ value: RelativeDateDirection.This, label: 'This' },
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RelativeDateUnit } from '../types/RelativeDateUnit';

export const RELATIVE_DATE_UNITS: { value: RelativeDateUnit; label: string }[] =
[
{ value: RelativeDateUnit.Day, label: 'Day' },
{ value: RelativeDateUnit.Week, label: 'Week' },
{ value: RelativeDateUnit.Month, label: 'Month' },
{ value: RelativeDateUnit.Year, label: 'Year' },
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum RelativeDateDirection {
Past = 'past',
Next = 'next',
This = 'this',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum RelativeDateUnit {
Day = 'day',
Week = 'week',
Month = 'month',
Year = 'year',
}