Skip to content
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

Persistent filter feature #7276

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 58 additions & 33 deletions ui/src/components/filter/KestraFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@change="(value) => changeCallback(value)"
@keyup="(e) => handleInputChange(e.key)"
@keyup.enter="() => handleEnterKey(select?.hoverOption?.value)"
@remove-tag="(item) => removeItem(item)"
@visible-change="(visible) => dropdownToggleCallback(visible)"
@clear="handleClear"
:class="{
Expand All @@ -32,12 +31,16 @@
@focus="handleFocus"
data-test-id="KestraFilter__select"
>
<template #label="{value}">
<!--
TODO: Find a way to have persistent tags for el-select.
https://github.com/kestra-io/kestra/issues/6256
-->
<Label :option="value" :prefix="ITEMS_PREFIX" />
<template #tag>
<el-tag
v-for="(option, index) in currentFilters"
:key="index"
:closable="!option.persistent"
@close="() => removeItem(option)"
:class="{disabled: option.persistent}"
>
<Label :option :prefix="ITEMS_PREFIX" />
</el-tag>
</template>
<template #empty>
<span v-if="!isDatePickerShown">{{ emptyLabel }}</span>
Expand Down Expand Up @@ -239,9 +242,11 @@
if (prefixFilter.value === "") {
return valueOptions.value;
}
return valueOptions.value.filter((o) =>
o.label.toLowerCase().startsWith(prefixFilter.value),
) || [];
return (
valueOptions.value.filter((o) =>
o.label.toLowerCase().startsWith(prefixFilter.value),
) || []
);
});

const select = ref<InstanceType<typeof ElSelect> | null>(null);
Expand Down Expand Up @@ -305,7 +310,7 @@
};

const handleClear = () => {
currentFilters.value = [];
currentFilters.value = currentFilters.value.filter((item) => item.persistent);
triggerSearch();
};

Expand All @@ -328,9 +333,9 @@
};

// Check if parent filter already exists
const existingFilterIndex = currentFilters.value.filter((itm) => itm.label !== "labels").findIndex(
(item) => item.label === option.value.label,
);
const existingFilterIndex = currentFilters.value
.filter((itm) => itm.label !== "labels")
.findIndex((item) => item.label === option.value.label);
if (existingFilterIndex !== -1) {
// If it exists, update current filter index
dropdowns.value.second = {shown: true, index: existingFilterIndex};
Expand Down Expand Up @@ -395,9 +400,9 @@
const isOptionDisabled = () => {
if (!activeParentFilter.value) return false;

const parentIndex = currentFilters.value.filter((itm) => itm.label !== "labels").findIndex(
(item) => item.label === activeParentFilter.value,
);
const parentIndex = currentFilters.value
.filter((itm) => itm.label !== "labels")
.findIndex((item) => item.label === activeParentFilter.value);
if (parentIndex === -1) return false;
};
const valueCallback = (filter, isDate = false) => {
Expand Down Expand Up @@ -442,7 +447,9 @@
},
];
}
const index = currentFilters.value.findIndex((v) => v.label === "absolute_date");
const index = currentFilters.value.findIndex(
(v) => v.label === "absolute_date",
);

if (index !== -1) {
if (!filter || !filter.startDate || !filter.endDate) {
Expand Down Expand Up @@ -601,13 +608,16 @@
// Handling change of label filters from direct click events
if (
Object.keys(q).length === 0 ||
Object.keys(q).some(key => key.startsWith("filters[labels]"))
Object.keys(q).some((key) => key.startsWith("filters[labels]"))
) {
const routeFilters = decodeParams(route.name, q, props.include, OPTIONS);
const routeFilters = decodeParams(
route.name,
q,
props.include,
OPTIONS,
);
currentFilters.value = routeFilters;
}


},
{immediate: true},
);
Expand Down Expand Up @@ -639,12 +649,15 @@
["details"].includes(wholeSearchContent.at(-2)?.label) ||
wholeSearchContent.at(-2)?.value?.length === 0
) {
if(wholeSearchContent.at(-2)?.label === "child") {
if (typeof wholeSearchContent.at(-1) === "string") wholeSearchContent = [];
if (wholeSearchContent.at(-2)?.label === "child") {
if (typeof wholeSearchContent.at(-1) === "string")
wholeSearchContent = [];
} else {
// Adding value to preceding empty filter
// TODO Provide a way for user to escape infinite labels & details loop (you can never fallback to a new filter, any further text will be added as a value to the filter)
wholeSearchContent.at(-2)?.value?.push(wholeSearchContent.at(-1));
wholeSearchContent
.at(-2)
?.value?.push(wholeSearchContent.at(-1));
}
} else {
// Adding text search string
Expand Down Expand Up @@ -673,6 +686,7 @@
};

const removeItem = (value) => {
if (value.persistent) return;
currentFilters.value = currentFilters.value.filter(
(item) => JSON.stringify(item) !== JSON.stringify(value),
);
Expand All @@ -688,14 +702,21 @@
const triggerSearch = () => {
if (props.searchCallback) return;
else {
router.push({query: encodeParams(route.name, currentFilters.value, OPTIONS)});
router.push({
query: encodeParams(route.name, currentFilters.value, OPTIONS),
});
}
};

// Include parameters from URL directly to filter
onMounted(() => {
if (props.decode) {
const decodedParams = decodeParams(route.name, route.query, props.include, OPTIONS);
const decodedParams = decodeParams(
route.name,
route.query,
props.include,
OPTIONS,
);
currentFilters.value = decodedParams.map((item: any) => {
if (item.label === "absolute_date") {
return {
Expand Down Expand Up @@ -728,7 +749,7 @@
currentFilters.value.push({
label: "namespace",
value: [namespace],
comparator: COMPARATORS.STARTS_WITH,
comparator: COMPARATORS.EQUALS,
persistent: true,
});
};
Expand All @@ -750,16 +771,16 @@
// Single namespace page
addNamespaceFilter(params.id);
} else if (name === "admin/triggers") {
if(query.namespace) addNamespaceFilter(query.namespace);
if(query.flowId){
if (query.namespace) addNamespaceFilter(query.namespace);
if (query.flowId) {
currentFilters.value.push({
label: "flow",
value: [`${query.flowId}`],
comparator: COMPARATORS.EQUALS,
persistent: true,
});
}
if(query.q) {
if (query.q) {
currentFilters.value.push({
label: "text",
value: [`${query.q}`],
Expand Down Expand Up @@ -988,18 +1009,22 @@ $properties: v-bind('props.propertiesWidth + "px"');
& .el-tag {
overflow: hidden;
padding: 0 !important;
padding-right: 0.30rem !important;
padding-right: 0.3rem !important;
color: var(--ks-tag-content);
background: var(--ks-tag-background-active) !important;

&.disabled .el-tag__content {
cursor: not-allowed;
}

&:hover {
background: var(--ks-tag-background-hover) !important;
}

& .el-tag__close {
color: var(--ks-content-link);

&:hover{
&:hover {
background: none !important;
}
}
Expand Down