Skip to content

Commit e767e11

Browse files
emma-sgSuaYoo
andauthored
Apply changes from filter chip dropdowns immediately (#2877)
Co-authored-by: sua yoo <[email protected]>
1 parent c8c59dd commit e767e11

File tree

7 files changed

+171
-172
lines changed

7 files changed

+171
-172
lines changed

frontend/src/features/archived-items/archived-item-state-filter.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
state,
1616
} from "lit/decorators.js";
1717
import { repeat } from "lit/directives/repeat.js";
18+
import { isEqual } from "lodash";
1819
import { isFocusable } from "tabbable";
1920

2021
import { CrawlStatus } from "./crawl-status";
@@ -52,14 +53,8 @@ export class ArchivedItemStateFilter extends BtrixElement {
5253

5354
private readonly fuse = new Fuse<CrawlState>(finishedCrawlStates);
5455

55-
@state()
56-
private get selectedStates() {
57-
return Array.from(this.selected.entries())
58-
.filter(([_tag, selected]) => selected)
59-
.map(([tag]) => tag);
60-
}
61-
62-
private selected = new Map<CrawlState, boolean>();
56+
@state({ hasChanged: isEqual })
57+
selected = new Map<CrawlState, boolean>();
6358

6459
protected willUpdate(changedProperties: PropertyValues<this>): void {
6560
if (changedProperties.has("states")) {
@@ -71,6 +66,22 @@ export class ArchivedItemStateFilter extends BtrixElement {
7166
}
7267
}
7368

69+
protected updated(changedProperties: PropertyValues<this>): void {
70+
if (changedProperties.has("selected")) {
71+
this.dispatchEvent(
72+
new CustomEvent<
73+
BtrixChangeEvent<ChangeArchivedItemStateEventDetails>["detail"]
74+
>("btrix-change", {
75+
detail: {
76+
value: Array.from(this.selected.entries())
77+
.filter(([_tag, selected]) => selected)
78+
.map(([tag]) => tag),
79+
},
80+
}),
81+
);
82+
}
83+
}
84+
7485
render() {
7586
const options = this.searchString
7687
? this.fuse.search(this.searchString)
@@ -87,14 +98,6 @@ export class ArchivedItemStateFilter extends BtrixElement {
8798
}}
8899
@sl-after-hide=${() => {
89100
this.searchString = "";
90-
91-
this.dispatchEvent(
92-
new CustomEvent<
93-
BtrixChangeEvent<ChangeArchivedItemStateEventDetails>["detail"]
94-
>("btrix-change", {
95-
detail: { value: this.selectedStates },
96-
}),
97-
);
98101
}}
99102
>
100103
${this.states?.length
@@ -250,8 +253,9 @@ export class ArchivedItemStateFilter extends BtrixElement {
250253
@sl-change=${async (e: SlChangeEvent) => {
251254
const { checked, value } = e.target as SlCheckbox;
252255
253-
this.selected.set(value as CrawlState, checked);
254-
this.requestUpdate("selectedStates");
256+
this.selected = new Map(
257+
this.selected.set(value as CrawlState, checked),
258+
);
255259
}}
256260
>
257261
${repeat(

frontend/src/features/archived-items/archived-item-tag-filter.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
state,
1818
} from "lit/decorators.js";
1919
import { repeat } from "lit/directives/repeat.js";
20+
import { isEqual } from "lodash";
2021
import { isFocusable } from "tabbable";
2122

2223
import { BtrixElement } from "@/classes/BtrixElement";
@@ -56,17 +57,11 @@ export class ArchivedItemTagFilter extends BtrixElement {
5657
keys: ["tag"],
5758
});
5859

59-
@state()
60-
private get selectedTags() {
61-
return Array.from(this.selected.entries())
62-
.filter(([_tag, selected]) => selected)
63-
.map(([tag]) => tag);
64-
}
65-
66-
private selected = new Map<string, boolean>();
60+
@state({ hasChanged: isEqual })
61+
selected = new Map<string, boolean>();
6762

6863
@state()
69-
private type: "and" | "or" = "or";
64+
type: "and" | "or" = "or";
7065

7166
protected willUpdate(changedProperties: PropertyValues<this>): void {
7267
if (changedProperties.has("tags")) {
@@ -78,6 +73,25 @@ export class ArchivedItemTagFilter extends BtrixElement {
7873
}
7974
}
8075

76+
protected updated(changedProperties: PropertyValues<this>): void {
77+
if (changedProperties.has("selected") || changedProperties.has("type")) {
78+
const selectedTags = Array.from(this.selected.entries())
79+
.filter(([_tag, selected]) => selected)
80+
.map(([tag]) => tag);
81+
this.dispatchEvent(
82+
new CustomEvent<
83+
BtrixChangeEvent<ChangeArchivedItemTagEventDetails>["detail"]
84+
>("btrix-change", {
85+
detail: {
86+
value: selectedTags.length
87+
? { tags: selectedTags, type: this.type }
88+
: undefined,
89+
},
90+
}),
91+
);
92+
}
93+
}
94+
8195
private readonly orgTagsTask = new Task(this, {
8296
task: async () => {
8397
const { tags } = await this.api.fetch<WorkflowTags>(
@@ -105,18 +119,6 @@ export class ArchivedItemTagFilter extends BtrixElement {
105119
}}
106120
@sl-after-hide=${() => {
107121
this.searchString = "";
108-
109-
this.dispatchEvent(
110-
new CustomEvent<
111-
BtrixChangeEvent<ChangeArchivedItemTagEventDetails>["detail"]
112-
>("btrix-change", {
113-
detail: {
114-
value: this.selectedTags.length
115-
? { tags: this.selectedTags, type: this.type }
116-
: undefined,
117-
},
118-
}),
119-
);
120122
}}
121123
>
122124
${this.tags?.length
@@ -304,8 +306,7 @@ export class ArchivedItemTagFilter extends BtrixElement {
304306
@sl-change=${async (e: SlChangeEvent) => {
305307
const { checked, value } = e.target as SlCheckbox;
306308
307-
this.selected.set(value, checked);
308-
this.requestUpdate("selectedTags");
309+
this.selected = new Map(this.selected.set(value, checked));
309310
}}
310311
>
311312
${repeat(

frontend/src/features/crawl-workflows/workflow-profile-filter.ts

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
state,
1818
} from "lit/decorators.js";
1919
import { repeat } from "lit/directives/repeat.js";
20+
import { isEqual } from "lodash";
2021
import queryString from "query-string";
2122
import { isFocusable } from "tabbable";
2223

@@ -57,7 +58,8 @@ export class WorkflowProfileFilter extends BtrixElement {
5758
keys: ["id", "name", "description", "origins"],
5859
});
5960

60-
private selected = new Map<string, boolean>();
61+
@state({ hasChanged: isEqual })
62+
selected = new Map<string, boolean>();
6163

6264
protected willUpdate(changedProperties: PropertyValues<this>): void {
6365
if (changedProperties.has("profiles")) {
@@ -69,6 +71,26 @@ export class WorkflowProfileFilter extends BtrixElement {
6971
}
7072
}
7173

74+
protected updated(changedProperties: PropertyValues<this>): void {
75+
if (changedProperties.has("selected")) {
76+
const selectedProfiles = [];
77+
78+
for (const [profile, value] of this.selected) {
79+
if (value) {
80+
selectedProfiles.push(profile);
81+
}
82+
}
83+
84+
this.dispatchEvent(
85+
new CustomEvent<BtrixChangeEvent["detail"]>("btrix-change", {
86+
detail: {
87+
value: selectedProfiles.length ? selectedProfiles : undefined,
88+
},
89+
}),
90+
);
91+
}
92+
}
93+
7294
private readonly profilesTask = new Task(this, {
7395
task: async () => {
7496
const query = queryString.stringify(
@@ -105,22 +127,6 @@ export class WorkflowProfileFilter extends BtrixElement {
105127
}}
106128
@sl-after-hide=${() => {
107129
this.searchString = "";
108-
109-
const selectedProfiles = [];
110-
111-
for (const [profile, value] of this.selected) {
112-
if (value) {
113-
selectedProfiles.push(profile);
114-
}
115-
}
116-
117-
this.dispatchEvent(
118-
new CustomEvent<BtrixChangeEvent["detail"]>("btrix-change", {
119-
detail: {
120-
value: selectedProfiles.length ? selectedProfiles : undefined,
121-
},
122-
}),
123-
);
124130
}}
125131
>
126132
${this.profiles?.length
@@ -160,17 +166,7 @@ export class WorkflowProfileFilter extends BtrixElement {
160166
this.checkboxes.forEach((checkbox) => {
161167
checkbox.checked = false;
162168
});
163-
164-
this.dispatchEvent(
165-
new CustomEvent<BtrixChangeEvent["detail"]>(
166-
"btrix-change",
167-
{
168-
detail: {
169-
value: undefined,
170-
},
171-
},
172-
),
173-
);
169+
this.selected = new Map();
174170
}}
175171
>${msg("Clear")}</sl-button
176172
>`
@@ -343,7 +339,7 @@ export class WorkflowProfileFilter extends BtrixElement {
343339
@sl-change=${async (e: SlChangeEvent) => {
344340
const { checked, value } = e.target as SlCheckbox;
345341
346-
this.selected.set(value, checked);
342+
this.selected = new Map(this.selected.set(value, checked));
347343
}}
348344
>
349345
${repeat(

0 commit comments

Comments
 (0)