-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fix(files): File type filter UI sync with filter state #49259
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ | |||||
*/ | ||||||
import type { IFileListFilterChip, INode } from '@nextcloud/files' | ||||||
|
||||||
import { subscribe } from '@nextcloud/event-bus' | ||||||
import { FileListFilter, registerFileListFilter } from '@nextcloud/files' | ||||||
import { t } from '@nextcloud/l10n' | ||||||
import Vue from 'vue' | ||||||
|
@@ -89,12 +89,12 @@ | |||||
class TypeFilter extends FileListFilter { | ||||||
|
||||||
private currentInstance?: Vue | ||||||
private currentPresets?: ITypePreset[] | ||||||
private currentPresets: ITypePreset[] | ||||||
private allPresets?: ITypePreset[] | ||||||
|
||||||
constructor() { | ||||||
super('files:type', 10) | ||||||
subscribe('files:navigation:changed', () => this.setPreset()) | ||||||
this.currentPresets = [] | ||||||
} | ||||||
|
||||||
public async mount(el: HTMLElement) { | ||||||
|
@@ -103,13 +103,16 @@ | |||||
this.allPresets = await getTypePresets() | ||||||
} | ||||||
|
||||||
// Already mounted | ||||||
if (this.currentInstance) { | ||||||
this.currentInstance.$destroy() | ||||||
delete this.currentInstance | ||||||
} | ||||||
|
||||||
const View = Vue.extend(FileListFilterType as never) | ||||||
this.currentInstance = new View({ | ||||||
propsData: { | ||||||
preset: this.currentPresets, | ||||||
typePresets: this.allPresets!, | ||||||
}, | ||||||
el, | ||||||
|
@@ -142,7 +145,8 @@ | |||||
} | ||||||
|
||||||
public setPreset(presets?: ITypePreset[]) { | ||||||
this.currentPresets = presets | ||||||
this.currentPresets = presets ?? [] | ||||||
this.currentInstance!.$props.preset = presets | ||||||
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.
Suggested change
The proptype is an array so we could do this and remove the |
||||||
this.filterUpdated() | ||||||
|
||||||
const chips: IFileListFilterChip[] = [] | ||||||
|
@@ -151,7 +155,7 @@ | |||||
chips.push({ | ||||||
icon: preset.icon, | ||||||
text: preset.label, | ||||||
onclick: () => this.setPreset(presets.filter(({ id }) => id !== preset.id)), | ||||||
onclick: () => this.removeFilterPreset(preset.id), | ||||||
}) | ||||||
} | ||||||
} else { | ||||||
|
@@ -160,6 +164,15 @@ | |||||
this.updateChips(chips) | ||||||
} | ||||||
|
||||||
/** | ||||||
Check warning on line 167 in apps/files/src/filters/TypeFilter.ts GitHub Actions / NPM lint
|
||||||
* Helper callback that removed a preset from selected. | ||||||
* This is used when clicking on "remove" on a filter-chip. | ||||||
*/ | ||||||
private removeFilterPreset(presetId: string) { | ||||||
const filtered = this.currentPresets.filter(({ id }) => id !== presetId) | ||||||
this.setPreset(filtered) | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
/** | ||||||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
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 should use either singular or plural everywhere to minimize confusion