-
Notifications
You must be signed in to change notification settings - Fork 2
feat(DataGrid): Add button in the side panel to reset all filters #90
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
Draft
avorobiov-unicrew
wants to merge
10
commits into
main
Choose a base branch
from
fix/DEV-8460-sidebar-reset-all-filters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c00ec28
feat(DataGrid): Make it possible to reset all filters by clicking but…
86b3a85
fix: Update 3mo/data-grid in 3mo/fetchable-data-grid
5ef26f2
fix: Overwrite sidePanelTemplate into FetchableDataGrid
4e4683d
fix: Revert DataGrid package changes
1e5791e
fix: Add ts-ignore for sidePanelTemplate visibility
f61e1b8
fix: Fix cloning and restoring parameters
d479754
fix: Button should be disabled if parameters has not changed
18b885c
fix: Get rid of all empty parameters
f231cc7
fix: Fix parameters comparing
ed54b75
fix: Use protected visibility for sidePanelTemplate
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { Binder, component, css, event, html, property } from '@a11d/lit' | ||
| import { Binder, component, css, event, html, ifDefined, property } from '@a11d/lit' | ||
| import { tooltip } from '@3mo/tooltip' | ||
| import { Localizer } from '@3mo/localization' | ||
| import { FetcherController } from '@3mo/fetcher-controller' | ||
|
|
@@ -21,8 +21,20 @@ type Result<TData> = PaginatedResult<TData> | NonPaginatedResult<TData> | |
| Localizer.dictionaries.add('de', { | ||
| 'Make a filter selection': 'Filterauswahl vornehmen', | ||
| 'Refetch': 'Neu laden', | ||
| 'Reset all filters': 'Alle Filter zurücksetzen', | ||
| }) | ||
|
|
||
| const deepCloneKeepingClasses = <T = {}>(origin: T) => { | ||
| const clonedObject = structuredClone(origin) | ||
| for (const keyName in origin) { | ||
| const value = origin[keyName] | ||
| if (value instanceof DateTimeRange) { | ||
| clonedObject[keyName] = new DateTimeRange(value.start, value.end) as T[Extract<keyof T, string>] | ||
| } | ||
| } | ||
| return clonedObject | ||
| } | ||
|
|
||
| /** | ||
| * @element mo-fetchable-data-grid | ||
| * | ||
|
|
@@ -67,6 +79,8 @@ export class FetchableDataGrid<TData, TDataFetcherParameters extends FetchableDa | |
| @property({ type: Object }) sortParameters?: () => Partial<TDataFetcherParameters> | ||
| // protected filterParameters?: () => TDataFetcherParameters | ||
|
|
||
| initialParameters!: TDataFetcherParameters | ||
|
|
||
| protected readonly parametersBinder = new Binder<TDataFetcherParameters>(this, 'parameters') | ||
|
|
||
| protected fetchDirty?(parameters: TDataFetcherParameters): Array<TData> | undefined | ||
|
|
@@ -77,7 +91,9 @@ export class FetchableDataGrid<TData, TDataFetcherParameters extends FetchableDa | |
| if (!this.parameters) { | ||
| return undefined | ||
| } | ||
|
|
||
| if (!this.initialParameters) { | ||
| this.initialParameters = deepCloneKeepingClasses(this.parameters) | ||
| } | ||
| const paginationParameters = this.paginationParameters?.({ page: this.page, pageSize: this.pageSize }) ?? {} | ||
| const sortParameters = this.sortParameters?.() ?? {} | ||
| const data = await this.fetch({ | ||
|
|
@@ -299,6 +315,41 @@ export class FetchableDataGrid<TData, TDataFetcherParameters extends FetchableDa | |
| </slot> | ||
| ` | ||
| } | ||
|
|
||
| protected override get sidePanelTemplate() { | ||
| return html` | ||
| <mo-data-grid-side-panel | ||
| .dataGrid=${this as any} | ||
| tab=${ifDefined(this.sidePanelTab)} | ||
| > | ||
| <slot slot='settings' name='settings'>${this.settingsDefaultTemplate}</slot> | ||
| <slot slot='filter' name='filter'> | ||
| ${this.filtersDefaultTemplate} | ||
|
|
||
| ${[html.nothing, undefined].includes(this.filtersDefaultTemplate) || !this.hasFilters ? html.nothing : html` | ||
| <mo-button type='raised' | ||
| ?disabled=${!this.hasParametersChanged} | ||
| @click=${() => this.restoreDefaultParameters()} | ||
| > | ||
| ${t('Reset all filters')} | ||
| </mo-button> | ||
| `} | ||
| </slot> | ||
| </mo-data-grid-side-panel> | ||
| ` | ||
| } | ||
|
|
||
| private get hasParametersChanged() { | ||
| return Object.entries(this.parameters ?? {}) | ||
| .filter(([_, value]) => value !== undefined | ||
| && value !== '' | ||
| && (!(value instanceof Array) || value.length > 0)) | ||
| .some(([key, value]) => JSON.stringify(this.initialParameters[key]) !== JSON.stringify(value)) | ||
| } | ||
|
|
||
| private restoreDefaultParameters = () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| this.parameters = deepCloneKeepingClasses(this.initialParameters) | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have similar stuff in
ModdableDataGrid(seedefinedParameters) but I am unsure if we need to install@a11d/equalshere. Maybe we should somehow make this package global? (likestructuredClonepolyfill)