fix(grid): improve filter rule actions
This commit is contained in:
4 files changed
+62
-7
No files matched your search
@@ -3,6 +3,7 @@ import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";
|
|||||||
import { Check, Eye, EyeOff, Focus, GripVertical, Plus, Search, Trash2, X } from "@lucide/vue";
|
import { Check, Eye, EyeOff, Focus, GripVertical, Plus, Search, Trash2, X } from "@lucide/vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import LightTooltip from "@/components/ui/LightTooltip.vue";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||||
import { filterModeNeedsValue, filterModeUsesList, filterModeUsesRange } from "@/lib/dataGrid/dataGridColumnFilter";
|
import { filterModeNeedsValue, filterModeUsesList, filterModeUsesRange } from "@/lib/dataGrid/dataGridColumnFilter";
|
||||||
@@ -710,16 +711,25 @@ function blurValueRule(id: string) {
|
|||||||
{{ t("grid.filterBuilderValueShortcutHint") }}
|
{{ t("grid.filterBuilderValueShortcutHint") }}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-0.5" :class="props.layout === 'text' ? 'col-start-6 row-start-1' : usesExpandedLayout(rule.mode) ? 'col-start-5 row-start-1 row-span-2' : 'col-start-5 row-start-1'">
|
<div class="flex items-center gap-0.5" :class="props.layout === 'text' ? 'col-start-6 row-start-1' : usesExpandedLayout(rule.mode) ? 'col-start-5 row-start-1 row-span-2' : 'col-start-5 row-start-1'">
|
||||||
<Button v-if="props.showApplyOnly" variant="ghost" size="icon" class="h-7 w-7" :disabled="props.disabled || props.applyOnlyBusy" :title="t('grid.filterBuilderApplyOnly')" :aria-label="t('grid.filterBuilderApplyOnly')" @click="emit('applyOnly', rule.id)"
|
<LightTooltip v-if="props.showApplyOnly" :text="t('grid.filterBuilderApplyOnly')" side="top" :side-offset="4">
|
||||||
><Focus class="h-3.5 w-3.5" />
|
<Button variant="ghost" size="icon" class="h-7 w-7" :disabled="props.disabled || props.applyOnlyBusy" :aria-label="t('grid.filterBuilderApplyOnly')" @click="emit('applyOnly', rule.id)">
|
||||||
</Button>
|
<Focus class="h-3.5 w-3.5" />
|
||||||
|
</Button>
|
||||||
|
</LightTooltip>
|
||||||
<template v-if="props.layout === 'text'">
|
<template v-if="props.layout === 'text'">
|
||||||
<Button variant="ghost" size="icon" class="h-6 w-6" :aria-label="t('grid.filterBuilderAddRule')" @click="emit('add')"><Plus class="h-3.5 w-3.5" /></Button>
|
<Button variant="ghost" size="icon" class="h-6 w-6" :aria-label="t('grid.filterBuilderAddRule')" @click="emit('add')"><Plus class="h-3.5 w-3.5" /></Button>
|
||||||
<Button variant="ghost" size="icon" class="h-6 w-6" :disabled="props.rules.length === 1" @click="emit('remove', rule.id)"><X class="h-3.5 w-3.5" /></Button>
|
<Button variant="ghost" size="icon" class="h-6 w-6" :disabled="props.disabled" :aria-label="t('common.remove')" @click="emit('remove', rule.id)"><X class="h-3.5 w-3.5" /></Button>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<Button variant="ghost" size="icon" class="h-7 w-7" @click="emit('updateRule', rule.id, { disabled: !rule.disabled })"><EyeOff v-if="rule.disabled" class="h-3.5 w-3.5" /><Eye v-else class="h-3.5 w-3.5" /></Button>
|
<LightTooltip :text="t(rule.disabled ? 'grid.filterBuilderEnableRule' : 'grid.filterBuilderDisableRule')" side="top" :side-offset="4">
|
||||||
<Button variant="ghost" size="icon" class="h-7 w-7" :disabled="props.rules.length === 1" @click="emit('remove', rule.id)"><X class="h-3.5 w-3.5" /></Button>
|
<Button variant="ghost" size="icon" class="h-7 w-7" :disabled="props.disabled" :aria-label="t(rule.disabled ? 'grid.filterBuilderEnableRule' : 'grid.filterBuilderDisableRule')" @click="emit('updateRule', rule.id, { disabled: !rule.disabled })">
|
||||||
|
<EyeOff v-if="rule.disabled" class="h-3.5 w-3.5" />
|
||||||
|
<Eye v-else class="h-3.5 w-3.5" />
|
||||||
|
</Button>
|
||||||
|
</LightTooltip>
|
||||||
|
<LightTooltip :text="t('common.remove')" side="top" :side-offset="4">
|
||||||
|
<Button variant="ghost" size="icon" class="h-7 w-7" :disabled="props.disabled" :aria-label="t('common.remove')" @click="emit('remove', rule.id)"><X class="h-3.5 w-3.5" /></Button>
|
||||||
|
</LightTooltip>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -621,6 +621,41 @@ describe("DataGridFilterBuilder", () => {
|
|||||||
expect(buttons()[0].props.disabled).toBe(true);
|
expect(buttons()[0].props.disabled).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("labels panel rule actions and allows removing the final rule", async () => {
|
||||||
|
const updateRule = vi.fn();
|
||||||
|
const remove = vi.fn();
|
||||||
|
const mounted = mountComponent(DataGridFilterBuilder, {
|
||||||
|
rules: [{ id: "r1", columnName: "id", mode: "equals", rawValue: "7", rawEndValue: "", conjunction: "AND" }],
|
||||||
|
columns: ["id"],
|
||||||
|
filteredColumns: ["id"],
|
||||||
|
modeOptions: [{ value: "equals", labelKey: "equals" }],
|
||||||
|
columnSearch: "",
|
||||||
|
layout: "panel",
|
||||||
|
showApplyOnly: true,
|
||||||
|
onUpdateRule: updateRule,
|
||||||
|
onRemove: remove,
|
||||||
|
});
|
||||||
|
|
||||||
|
const tooltips = () => findAll(mounted.root, (node) => node.props["data-stub"] === "LightTooltip");
|
||||||
|
const tooltipTexts = () => tooltips().map((node) => node.props.text);
|
||||||
|
const applyOnlyButton = findOne(mounted.root, (node) => node.props["aria-label"] === "grid.filterBuilderApplyOnly");
|
||||||
|
const toggleButton = findOne(mounted.root, (node) => node.props["aria-label"] === "grid.filterBuilderDisableRule");
|
||||||
|
const removeButton = findOne(mounted.root, (node) => node.props["aria-label"] === "common.remove");
|
||||||
|
|
||||||
|
expect(tooltipTexts()).toEqual(["grid.filterBuilderApplyOnly", "grid.filterBuilderDisableRule", "common.remove"]);
|
||||||
|
expect(tooltips().every((tooltip) => tooltip.props.side === "top")).toBe(true);
|
||||||
|
expect(removeButton.props.disabled).toBeFalsy();
|
||||||
|
dispatch(toggleButton, "click");
|
||||||
|
dispatch(removeButton, "click");
|
||||||
|
expect(updateRule).toHaveBeenCalledWith("r1", { disabled: true });
|
||||||
|
expect(remove).toHaveBeenCalledWith("r1");
|
||||||
|
|
||||||
|
await mounted.setProps({ rules: [{ id: "r1", columnName: "id", mode: "equals", rawValue: "7", rawEndValue: "", conjunction: "AND", disabled: true }] });
|
||||||
|
expect(findOne(mounted.root, (node) => node.props["aria-label"] === "grid.filterBuilderEnableRule")).toBeTruthy();
|
||||||
|
expect(tooltipTexts()).toEqual(["grid.filterBuilderApplyOnly", "grid.filterBuilderEnableRule", "common.remove"]);
|
||||||
|
expect(applyOnlyButton.props["aria-label"]).toBe("grid.filterBuilderApplyOnly");
|
||||||
|
});
|
||||||
|
|
||||||
it("renders a compact text rule without framed form controls", async () => {
|
it("renders a compact text rule without framed form controls", async () => {
|
||||||
const updateRule = vi.fn();
|
const updateRule = vi.fn();
|
||||||
const add = vi.fn();
|
const add = vi.fn();
|
||||||
|
|||||||
@@ -27,6 +27,17 @@ describe("useDataGridFilterBuilder", () => {
|
|||||||
expect(builder.rules.value[0]?.columnName).toBe("");
|
expect(builder.rules.value[0]?.columnName).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("adds one rule after the final rule is removed", () => {
|
||||||
|
let nextId = 0;
|
||||||
|
const builder = useDataGridFilterBuilder({ columns: ["id"], createId: () => `rule-${++nextId}`, isComplete: () => true, buildCondition: async () => "" });
|
||||||
|
|
||||||
|
builder.ensureRule();
|
||||||
|
builder.removeRule("rule-1");
|
||||||
|
builder.addRule();
|
||||||
|
|
||||||
|
expect(builder.rules.value.map((rule) => rule.id)).toEqual(["rule-2"]);
|
||||||
|
});
|
||||||
|
|
||||||
it("skips disabled rules and applies conjunctions", async () => {
|
it("skips disabled rules and applies conjunctions", async () => {
|
||||||
let nextId = 0;
|
let nextId = 0;
|
||||||
const builder = useDataGridFilterBuilder({
|
const builder = useDataGridFilterBuilder({
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ export function useDataGridFilterBuilder(options: UseDataGridFilterBuilderOption
|
|||||||
if (!rules.value.length && toValue(options.columns).length) rules.value = [defaultRule()];
|
if (!rules.value.length && toValue(options.columns).length) rules.value = [defaultRule()];
|
||||||
}
|
}
|
||||||
function addRule() {
|
function addRule() {
|
||||||
ensureRule();
|
|
||||||
rules.value = [...rules.value, defaultRule()];
|
rules.value = [...rules.value, defaultRule()];
|
||||||
}
|
}
|
||||||
function removeRule(id: string) {
|
function removeRule(id: string) {
|
||||||
|
|||||||
Reference in new issue
Block a user