-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the Datetime field filter (#703)
* added the advanced mode toggler * added the PQL block * added styles files * added handlers for PQL Query textarea value * updated addOrUpdatePQLQuery method * updated the ListDataProviding by adding the errorData field * added the Alert component * updated the Alert stories * updated the Alert component * deleted unused code * refactoring * updated the PQL info icon style and behaviour * added hook for PQL Query logic * added hook for includeDescedants logic * updated behaviour for PQL error case * updated the Alert component * fixed bug when the filter should be resetted * added the datetime component to the DynamicTypesFieldFilters * deleted unused code after conflicts merging * added the setting switcher * added styles and updated types using * added DatePicker and DateRangePicker components * updated the addOrUpdateFieldFilter by handling case when the data are equal * updated logic for using DateRangePicker * refactoring * fixed types * deleted unused code * updated types and comments in the useFilters hook * updated the handleChangeDate methods * Automatic frontend build --------- Co-authored-by: ValeriaMaltseva <[email protected]>
- Loading branch information
1 parent
9ee0fa7
commit c86e78b
Showing
28 changed files
with
2,320 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
.../defintinitions/field-filters/components/dynamic-type-field-filter-datetime-component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import React, { useState, useMemo } from 'react' | ||
import { Select } from '@Pimcore/components/select/select' | ||
import { Flex } from '@Pimcore/components/flex/flex' | ||
import { DatePicker } from '@Pimcore/components/date-picker/date-picker' | ||
import { DateRangePicker, type DateRangeTargetValue } from '@Pimcore/components/date-picker/date-range-picker' | ||
import type { AbstractFieldFilterDefinition } from '@Pimcore/modules/element/dynamic-types/defintinitions/field-filters/dynamic-type-field-filter-abstract' | ||
import { useFilters } from '@Pimcore/modules/asset/editor/types/folder/tab-manager/tabs/list/sidebar/filters/hooks/use-filters' | ||
|
||
enum DatePickerSettingValue { | ||
ON = 'on', | ||
BETWEEN = 'between' | ||
} | ||
|
||
interface FieldFilterDatetimeON { | ||
on: number | ||
} | ||
|
||
interface FieldFilterDatetimeBetween { | ||
from: number | ||
to: number | ||
} | ||
|
||
interface FieldFilterDatetime { | ||
filterValue?: FieldFilterDatetimeON | FieldFilterDatetimeBetween | ||
} | ||
|
||
const SETTING_OPTIONS = [ | ||
{ label: 'On', value: DatePickerSettingValue.ON }, | ||
{ label: 'Between', value: DatePickerSettingValue.BETWEEN } | ||
] | ||
|
||
const DATE_FORMAT = 'YYYY-MM-DD' | ||
|
||
export interface DynamicTypeFieldFilterDatetimeProps extends AbstractFieldFilterDefinition {} | ||
|
||
export const DynamicTypeFieldFilterDatetimeComponent = ({ column }: DynamicTypeFieldFilterDatetimeProps): React.JSX.Element => { | ||
const [settingValue, setSettingValue] = useState<DatePickerSettingValue>(DatePickerSettingValue.ON) | ||
|
||
const { getFieldFilter, addOrUpdateFieldFilter } = useFilters() | ||
|
||
const fieldFilter = getFieldFilter(column) as FieldFilterDatetime | ||
|
||
const getDateValue = (datetimeType: DatePickerSettingValue): null | number | number[] => { | ||
const currentFilterValue = fieldFilter?.filterValue | ||
|
||
if (currentFilterValue == null) return null | ||
|
||
if (datetimeType === DatePickerSettingValue.ON && 'on' in currentFilterValue) { | ||
setSettingValue(DatePickerSettingValue.ON) | ||
|
||
return currentFilterValue.on | ||
} | ||
|
||
if ( | ||
datetimeType === DatePickerSettingValue.BETWEEN && | ||
'from' in currentFilterValue && | ||
'to' in currentFilterValue | ||
) { | ||
setSettingValue(DatePickerSettingValue.BETWEEN) | ||
|
||
return [currentFilterValue.from, currentFilterValue.to] | ||
} | ||
|
||
return null | ||
} | ||
|
||
const valueOn = useMemo(() => getDateValue(DatePickerSettingValue.ON) as number | null, [fieldFilter]) | ||
const valueBetween = useMemo(() => getDateValue(DatePickerSettingValue.BETWEEN) as DateRangeTargetValue | null, [fieldFilter]) | ||
|
||
const [dateOnValue, setDateOnValue] = useState<null | number>(valueOn) | ||
const [dateBetweenValue, setDateBetweenValue] = useState<null | DateRangeTargetValue>(valueBetween) | ||
|
||
const handleChangeDateOnValue = (date: number): void => { | ||
setDateOnValue(date) | ||
setDateBetweenValue(null) | ||
|
||
addOrUpdateFieldFilter(column, { on: date }) | ||
} | ||
|
||
const handleChangeDateBetweenValue = (dates: DateRangeTargetValue): void => { | ||
setDateBetweenValue(dates) | ||
setDateOnValue(null) | ||
|
||
addOrUpdateFieldFilter(column, { from: dates?.[0], to: dates?.[1] }) | ||
} | ||
|
||
return ( | ||
<Flex | ||
align="center" | ||
gap="extra-small" | ||
> | ||
<Select | ||
onChange={ (value: DatePickerSettingValue) => { setSettingValue(value) } } | ||
options={ SETTING_OPTIONS } | ||
value={ settingValue } | ||
width={ 90 } | ||
/> | ||
|
||
{settingValue === DatePickerSettingValue.ON && ( | ||
<DatePicker | ||
format={ DATE_FORMAT } | ||
onChange={ handleChangeDateOnValue } | ||
outputType='timestamp' | ||
value={ dateOnValue } | ||
/> | ||
)} | ||
|
||
{settingValue === DatePickerSettingValue.BETWEEN && ( | ||
<DateRangePicker | ||
format={ DATE_FORMAT } | ||
onChange={ handleChangeDateBetweenValue } | ||
outputType='timestamp' | ||
value={ dateBetweenValue } | ||
/> | ||
)} | ||
</Flex> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...-types/defintinitions/field-filters/types/datetime/dynamic-type-field-filter-datetime.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import React, { type ReactElement } from 'react' | ||
import { type DynamicTypeFieldFilterAbstract } from '../../dynamic-type-field-filter-abstract' | ||
import { DynamicTypeFieldFilterDatetimeComponent, type DynamicTypeFieldFilterDatetimeProps } from '../../components/dynamic-type-field-filter-datetime-component' | ||
import { injectable } from 'inversify' | ||
|
||
@injectable() | ||
export class DynamicTypeFieldFilterDatetime implements DynamicTypeFieldFilterAbstract { | ||
id = 'datetime' | ||
|
||
getFieldFilterComponent (props: DynamicTypeFieldFilterDatetimeProps): ReactElement<DynamicTypeFieldFilterDatetimeProps> { | ||
return ( | ||
<DynamicTypeFieldFilterDatetimeComponent { ...props } /> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
public/build/1b057f34-a8bd-44af-a50e-3ef79387fa8b/entrypoints.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"entrypoints": { | ||
"vendor": { | ||
"js": [ | ||
"/bundles/pimcorestudioui/build/1b057f34-a8bd-44af-a50e-3ef79387fa8b/vendor.js" | ||
] | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
public/build/1b057f34-a8bd-44af-a50e-3ef79387fa8b/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"bundles/pimcorestudioui/build/1b057f34-a8bd-44af-a50e-3ef79387fa8b/vendor.js": "/bundles/pimcorestudioui/build/1b057f34-a8bd-44af-a50e-3ef79387fa8b/vendor.js" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.