chore(createFilter): change format
This commit is contained in:
@@ -37,41 +37,43 @@ export function createFilter<TValue extends string>(initialState: FilterModel<TV
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Helper to find a property by ID
|
||||||
|
const findProp = (id: string) => properties.find(p => p.id === id);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get properties() {
|
get properties() {
|
||||||
return properties;
|
return properties;
|
||||||
},
|
},
|
||||||
|
|
||||||
get selectedProperties() {
|
get selectedProperties() {
|
||||||
return properties.filter(p => p.selected);
|
return properties.filter(p => p.selected);
|
||||||
},
|
},
|
||||||
|
|
||||||
get selectedCount() {
|
get selectedCount() {
|
||||||
return this.selectedProperties.length;
|
return properties.filter(p => p.selected)?.length;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 3. Methods mutate the reactive state directly
|
|
||||||
toggleProperty(id: string) {
|
toggleProperty(id: string) {
|
||||||
const prop = properties.find(p => p.id === id);
|
const property = findProp(id);
|
||||||
if (prop) prop.selected = !prop.selected;
|
if (property) {
|
||||||
|
property.selected = !property.selected;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
selectProperty(id: string) {
|
selectProperty(id: string) {
|
||||||
const prop = properties.find(p => p.id === id);
|
const property = findProp(id);
|
||||||
if (prop) prop.selected = true;
|
if (property) {
|
||||||
|
property.selected = true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
deselectProperty(id: string) {
|
deselectProperty(id: string) {
|
||||||
const prop = properties.find(p => p.id === id);
|
const property = findProp(id);
|
||||||
if (prop) prop.selected = false;
|
if (property) {
|
||||||
|
property.selected = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
selectAll() {
|
selectAll() {
|
||||||
properties.forEach(p => p.selected = true);
|
properties.forEach(property => property.selected = true);
|
||||||
},
|
},
|
||||||
|
|
||||||
deselectAll() {
|
deselectAll() {
|
||||||
properties.forEach(p => p.selected = false);
|
properties.forEach(property => property.selected = false);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user