Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): keep saved label filters matching new assignments (#2064)

Markus Sagen840074c3994c
diff --git a/apps/web/src/components/gantt/gantt-window.test.tsx b/apps/web/src/components/gantt/gantt-window.test.tsx
index c80cbe3ab..88a92a63b 100644
--- a/apps/web/src/components/gantt/gantt-window.test.tsx
+++ b/apps/web/src/components/gantt/gantt-window.test.tsx
@@ -74,6 +74,9 @@ vi.mock("@/components/project/task-filters/use-task-filter-options", () => ({
}),
}));
const noCustomFieldValues = () => [];
+vi.mock("@/hooks/queries/label/use-get-labels-by-workspace", () => ({
+ default: () => ({ data: undefined }),
+}));
vi.mock(
"@/hooks/queries/custom-field/use-get-all-custom-field-values-by-project",
() => ({
diff --git a/apps/web/src/components/project/task-filters/use-filter-subjects.tsx b/apps/web/src/components/project/task-filters/use-filter-subjects.tsx
index ab78a666c..5c3c9a9a2 100644
--- a/apps/web/src/components/project/task-filters/use-filter-subjects.tsx
+++ b/apps/web/src/components/project/task-filters/use-filter-subjects.tsx
@@ -9,6 +9,7 @@ import { customFieldSubjectId } from "@/lib/task-filters/filter-subject-id";
import {
groupLabels,
isLabelGroupSelected,
+ labelGroupKey,
toggleLabelGroup,
} from "@/lib/task-filters/label-groups";
import type { ProjectWithTasks } from "@/types/project";
@@ -74,7 +75,7 @@ export function useFilterSubjects({
const labelGroups = groupLabels(options.labels);
const groupIdByLabel = new Map(
- labelGroups.map((group) => [`${group.name}|${group.color}`, group.id]),
+ labelGroups.map((group) => [labelGroupKey(group), group.id]),
);
const counts = {
status: countValues(tasks, (task) => [task.status]),
@@ -82,7 +83,7 @@ export function useFilterSubjects({
priority: countValues(tasks, (task) => [task.priority]),
labels: countValues(tasks, (task) =>
(task.labels ?? []).map((label) =>
- groupIdByLabel.get(`${label.name}|${label.color}`),
+ groupIdByLabel.get(labelGroupKey(label)),
),
),
};
diff --git a/apps/web/src/hooks/filter-storage-failure.test.tsx b/apps/web/src/hooks/filter-storage-failure.test.tsx
index 3dc282551..0c8ac3fdc 100644
--- a/apps/web/src/hooks/filter-storage-failure.test.tsx
+++ b/apps/web/src/hooks/filter-storage-failure.test.tsx
@@ -5,6 +5,10 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
import { useTaskFilters } from "./use-task-filters";
import { useTaskFiltersWithLabelsSupport } from "./use-task-filters-with-labels-support";
+vi.mock("./queries/label/use-get-labels-by-workspace", () => ({
+ default: () => ({ data: undefined }),
+}));
+
afterEach(() => {
cleanup();
vi.restoreAllMocks();
diff --git a/apps/web/src/hooks/use-custom-field-filters.test.tsx b/apps/web/src/hooks/use-custom-field-filters.test.tsx
index e4ecc4b01..da488b629 100644
--- a/apps/web/src/hooks/use-custom-field-filters.test.tsx
+++ b/apps/web/src/hooks/use-custom-field-filters.test.tsx
@@ -18,6 +18,13 @@ import { useTaskFiltersWithLabelsSupport } from "./use-task-filters-with-labels-
vi.mock("@/fetchers/custom-field/get-custom-field-values-by-project");
vi.mock("@/fetchers/custom-field/set-custom-field-value");
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({
+ t: (key: string) => key,
+ i18n: { language: "en-US", resolvedLanguage: "en-US" },
+ }),
+ initReactI18next: { type: "3rdParty", init: () => {} },
+}));
type ProjectValue = Awaited<
ReturnType<typeof getCustomFieldValuesByProject>
diff --git a/apps/web/src/hooks/use-live-label-filter.test.tsx b/apps/web/src/hooks/use-live-label-filter.test.tsx
new file mode 100644
index 000000000..e606da6f5
--- /dev/null
+++ b/apps/web/src/hooks/use-live-label-filter.test.tsx
@@ -0,0 +1,202 @@
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { act, renderHook, waitFor } from "@testing-library/react";
+import type { ReactNode } from "react";
+import { afterEach, describe, expect, it } from "vite-plus/test";
+import { useFilterSubjects } from "@/components/project/task-filters/use-filter-subjects";
+import type { ProjectWithTasks } from "@/types/project";
+import type Task from "@/types/task";
+import { useTaskFiltersWithLabelsSupport } from "./use-task-filters-with-labels-support";
+
+const root = {
+ id: "root-label",
+ name: "Bug",
+ color: "red",
+ createdAt: "2026-10-01T00:00:00Z",
+ updatedAt: "2026-10-01T00:00:00Z",
+ taskId: null,
+ workspaceId: "workspace-1",
+};
+const task: Task = {
+ id: "task-1",
+ title: "A new bug",
+ number: 1,
+ description: null,
+ status: "to-do",
+ priority: "low",
+ startDate: null,
+ dueDate: null,
+ position: 0,
+ createdAt: "2026-10-01T00:00:00Z",
+ userId: null,
+ assigneeId: null,
+ assigneeName: null,
+ projectId: "project-1",
+ labels: [],
+};
+const project: ProjectWithTasks = {
+ id: "project-1",
+ workspaceId: "workspace-1",
+ slug: "TEST",
+ name: "Test",
+ description: null,
+ icon: null,
+ isPublic: false,
+ plannedTasks: [],
+ archivedTasks: [],
+ columns: [
+ {
+ id: "to-do",
+ slug: "to-do",
+ name: "To do",
+ icon: null,
+ isFinal: false,
+ tasks: [task],
+ },
+ ],
+};
+
+afterEach(() => window.localStorage.clear());
+
+describe("saved label filters", () => {
+ it.each([false, true])(
+ "updates new assignments with negation=%s",
+ async (negated) => {
+ const client = new QueryClient({
+ defaultOptions: { queries: { retry: false, staleTime: Infinity } },
+ });
+ client.setQueryData(["labels", "workspace-1"], [root]);
+ window.localStorage.setItem(
+ "kaneo:board-filters:project-1",
+ JSON.stringify({
+ labels: [root.id],
+ negated: negated ? ["labels"] : null,
+ }),
+ );
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <QueryClientProvider client={client}>{children}</QueryClientProvider>
+ );
+ const { result, rerender } = renderHook(
+ ({ current }) => useTaskFiltersWithLabelsSupport(current, current.id),
+ { wrapper, initialProps: { current: project } },
+ );
+ await waitFor(() => {
+ expect(result.current.filterTasks([task])).toHaveLength(
+ negated ? 1 : 0,
+ );
+ });
+
+ const attached = { ...root, id: "new-task-label" };
+ const updatedTask = { ...task, labels: [attached] };
+ // Remote assignments patch the task before workspace label options refresh.
+ rerender({
+ current: {
+ ...project,
+ columns: [{ ...project.columns[0], tasks: [updatedTask] }],
+ },
+ });
+ await waitFor(() => {
+ expect(result.current.filterTasks([updatedTask])).toHaveLength(
+ negated ? 0 : 1,
+ );
+ });
+ expect(
+ JSON.parse(
+ window.localStorage.getItem("kaneo:board-filters:project-1") ?? "{}",
+ ).labels,
+ ).toEqual([root.id]);
+
+ rerender({ current: project });
+ expect(result.current.filterTasks([task])).toHaveLength(negated ? 1 : 0);
+ },
+ );
+
+ it.each([
+ ["red", "red"],
+ ["#bb87fc", "#BB87FC"],
+ ])(
+ "can uncheck a remote %s/%s group with stale workspace options",
+ (color, assignedColor) => {
+ const label = { ...root, color };
+ const client = new QueryClient({
+ defaultOptions: { queries: { retry: false, staleTime: Infinity } },
+ });
+ client.setQueryData(["labels", "workspace-1"], [label]);
+ window.localStorage.setItem(
+ "kaneo:board-filters:project-1",
+ JSON.stringify({ labels: [root.id] }),
+ );
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <QueryClientProvider client={client}>{children}</QueryClientProvider>
+ );
+ const updatedTask = {
+ ...task,
+ labels: [{ ...label, color: assignedColor, id: "remote-copy" }],
+ };
+ const current = {
+ ...project,
+ columns: [{ ...project.columns[0], tasks: [updatedTask] }],
+ };
+ const { result } = renderHook(
+ () => {
+ const controls = useTaskFiltersWithLabelsSupport(current, current.id);
+ const subjects = useFilterSubjects({
+ controls,
+ options: {
+ labels: [label],
+ members: [],
+ customFields: [],
+ usedCustomFieldValues: {},
+ },
+ tasks: [updatedTask],
+ showStatus: false,
+ });
+ return {
+ controls,
+ labels: subjects.find((subject) => subject.id === "labels")!,
+ };
+ },
+ { wrapper },
+ );
+
+ expect(result.current.controls.filterTasks([updatedTask])).toHaveLength(
+ 1,
+ );
+ expect(result.current.labels.options[0]?.count).toBe(1);
+ act(() => result.current.labels.onToggle(root.id));
+ expect(result.current.labels.selected).toEqual([]);
+ expect(result.current.controls.filters.labels).toBeNull();
+ expect(result.current.controls.hasActiveFilters).toBe(false);
+ },
+ );
+
+ it("uses the current task metadata when a saved assignment is renamed", () => {
+ const client = new QueryClient({
+ defaultOptions: { queries: { retry: false, staleTime: Infinity } },
+ });
+ client.setQueryData(["labels", "workspace-1"], [root]);
+ window.localStorage.setItem(
+ "kaneo:board-filters:project-1",
+ JSON.stringify({ labels: [root.id] }),
+ );
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <QueryClientProvider client={client}>{children}</QueryClientProvider>
+ );
+ const renamedTask = { ...task, labels: [{ ...root, name: "Renamed" }] };
+ const otherTask = {
+ ...task,
+ id: "other",
+ labels: [{ ...root, id: "other-label" }],
+ };
+ const current = {
+ ...project,
+ columns: [{ ...project.columns[0], tasks: [renamedTask, otherTask] }],
+ };
+ const { result } = renderHook(
+ () => useTaskFiltersWithLabelsSupport(current, current.id),
+ { wrapper },
+ );
+ expect(result.current.filterTasks([renamedTask, otherTask])).toEqual([
+ renamedTask,
+ ]);
+ });
+});
diff --git a/apps/web/src/hooks/use-task-filters-with-labels-support.ts b/apps/web/src/hooks/use-task-filters-with-labels-support.ts
index 3230e2a85..4f0fbc579 100644
--- a/apps/web/src/hooks/use-task-filters-with-labels-support.ts
+++ b/apps/web/src/hooks/use-task-filters-with-labels-support.ts
@@ -1,6 +1,10 @@
import { useCallback, useMemo } from "react";
import { countActiveFilters } from "@/lib/task-filters/count-active-filters";
import { filterProjectTasks } from "@/lib/task-filters/filter-project-tasks";
+import {
+ expandLabelFilter,
+ type FilterLabel,
+} from "@/lib/task-filters/label-groups";
import { customFieldSubjectId } from "@/lib/task-filters/filter-subject-id";
import { setSubjectNegated } from "@/lib/task-filters/set-subject-negated";
import { taskMatchesFilters } from "@/lib/task-filters/task-matches-filters";
@@ -9,6 +13,7 @@ import { useUserPreferencesStore } from "@/store/user-preferences";
import type { ProjectWithTasks } from "@/types/project";
import type Task from "@/types/task";
import useGetCachedCustomFieldValues from "./queries/custom-field/use-get-all-custom-field-values-by-project";
+import useGetLabelsByWorkspace from "./queries/label/use-get-labels-by-workspace";
import type { BoardFilters } from "./use-task-filters";
import { useStoredState } from "./use-stored-state";
@@ -84,6 +89,26 @@ export function useTaskFiltersWithLabelsSupport(
normalizeFilters,
DEFAULT_FILTERS,
);
+ const { data: workspaceLabels } = useGetLabelsByWorkspace(
+ project?.workspaceId ?? "",
+ );
+ const labels = useMemo(() => {
+ if (!filters.labels?.length) return [];
+ const byId = new Map<string, FilterLabel>(
+ (workspaceLabels ?? []).map((label) => [label.id, label]),
+ );
+ const tasks = [
+ ...(project?.columns.flatMap((column) => column.tasks) ?? []),
+ ...(project?.plannedTasks ?? []),
+ ...(project?.archivedTasks ?? []),
+ ];
+ for (const task of tasks) {
+ // A live task update may be newer than the workspace-label query.
+ for (const label of task.labels ?? []) byId.set(label.id, label);
+ }
+ return [...byId.values()];
+ }, [workspaceLabels, project, filters.labels]);
+
const effectiveFilters = useMemo(
() =>
ignore.length === 0
@@ -94,6 +119,11 @@ export function useTaskFiltersWithLabelsSupport(
} as BoardFilters),
[filters, ignore],
);
+ // Expansion is matching-only: controls must edit the saved selection.
+ const matchingLabelIds = useMemo(
+ () => new Set(expandLabelFilter(labels, effectiveFilters.labels)),
+ [labels, effectiveFilters.labels],
+ );
const customFieldValues = useGetCachedCustomFieldValues(
effectiveFilters.customFields ? projectId : undefined,
);
@@ -107,6 +137,7 @@ export function useTaskFiltersWithLabelsSupport(
weekStartsOn,
today: new Date(),
getCustomFieldValues: getValuesForTask,
+ labelIds: matchingLabelIds,
};
// Missing query data is unknown, rather than an empty value on every task.
const readyFilters = !hasData
@@ -121,6 +152,7 @@ export function useTaskFiltersWithLabelsSupport(
getValuesForTask,
hasData,
descriptionMatches,
+ matchingLabelIds,
]);
const filterTasks = useCallback(
diff --git a/apps/web/src/lib/task-filters/label-groups.test.ts b/apps/web/src/lib/task-filters/label-groups.test.ts
index ef68720d4..ab8986be5 100644
--- a/apps/web/src/lib/task-filters/label-groups.test.ts
+++ b/apps/web/src/lib/task-filters/label-groups.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vite-plus/test";
import {
groupLabels,
+ expandLabelFilter,
isLabelGroupSelected,
toggleLabelGroup,
} from "./label-groups";
@@ -24,4 +25,50 @@ describe("label groups", () => {
expect(toggleLabelGroup(labels, design, selected)).toEqual(["b1"]);
expect(toggleLabelGroup(labels, design, ["a2"])).toBeNull();
});
+
+ it("includes label assignments added after the filter was saved", () => {
+ const attached = { ...design, id: "new-assignment" };
+ expect(expandLabelFilter([...labels, attached], ["a1"])).toEqual([
+ "a1",
+ "a2",
+ "new-assignment",
+ ]);
+ });
+
+ it("keeps differently named or colored groups separate", () => {
+ const other = { ...design, id: "different-color", color: "red" };
+ expect(expandLabelFilter([...labels, other], ["a1"])).toEqual(["a1", "a2"]);
+ });
+
+ it("follows current metadata after a selected label is renamed", () => {
+ const renamed = labels.map((label) => ({ ...label, name: "Renamed" }));
+ expect(expandLabelFilter(renamed, ["a1"])).toEqual(["a1", "a2"]);
+ });
+
+ it("does not broaden a filter whose selected labels no longer exist", () => {
+ expect(expandLabelFilter(labels, ["deleted"])).toEqual(["deleted"]);
+ expect(expandLabelFilter(labels, null)).toBeNull();
+ });
+
+ it("groups, selects, expands and clears mixed-case colors consistently", () => {
+ const lower = { ...design, id: "lower", color: "#bb87fc" };
+ const upper = { ...lower, id: "upper", color: "#BB87FC" };
+ const mixed = [lower, upper, labels[2]];
+ expect(groupLabels(mixed)).toEqual([lower, labels[2]]);
+ for (const selected of [lower, upper]) {
+ expect(isLabelGroupSelected(mixed, lower, [selected.id])).toBe(true);
+ expect(expandLabelFilter(mixed, [selected.id])).toEqual(
+ expect.arrayContaining([lower.id, upper.id]),
+ );
+ expect(toggleLabelGroup(mixed, upper, [selected.id])).toBeNull();
+ }
+ });
+
+ it("retains a legacy snapshot when some assignments have been deleted", () => {
+ expect(expandLabelFilter(labels, ["deleted", "a2"])).toEqual([
+ "deleted",
+ "a2",
+ "a1",
+ ]);
+ });
});
diff --git a/apps/web/src/lib/task-filters/label-groups.ts b/apps/web/src/lib/task-filters/label-groups.ts
index fb618b074..d319ff978 100644
--- a/apps/web/src/lib/task-filters/label-groups.ts
+++ b/apps/web/src/lib/task-filters/label-groups.ts
@@ -1,13 +1,16 @@
export type FilterLabel = { id: string; name: string; color: string };
-const sameGroup = (left: FilterLabel, right: FilterLabel) =>
- left.name === right.name && left.color === right.color;
+export const labelGroupKey = (label: FilterLabel) =>
+ JSON.stringify([label.name, label.color.toLowerCase()]);
export function groupLabels(labels: FilterLabel[]): FilterLabel[] {
- return labels.filter(
- (label, index) =>
- labels.findIndex((other) => sameGroup(other, label)) === index,
- );
+ const seen = new Set<string>();
+ return labels.filter((label) => {
+ const key = labelGroupKey(label);
+ if (seen.has(key)) return false;
+ seen.add(key);
+ return true;
+ });
}
export function isLabelGroupSelected(
@@ -15,8 +18,10 @@ export function isLabelGroupSelected(
group: FilterLabel,
selected: string[] | null | undefined,
) {
+ const key = labelGroupKey(group);
+ const selectedIds = new Set(selected);
return labels.some(
- (label) => sameGroup(label, group) && (selected ?? []).includes(label.id),
+ (label) => selectedIds.has(label.id) && labelGroupKey(label) === key,
);
}
@@ -25,12 +30,31 @@ export function toggleLabelGroup(
group: FilterLabel,
selected: string[] | null | undefined,
): string[] | null {
- const groupIds = labels
- .filter((label) => sameGroup(label, group))
- .map((label) => label.id);
+ const key = labelGroupKey(group);
+ const groupIds = new Set(
+ labels
+ .filter((label) => labelGroupKey(label) === key)
+ .map((label) => label.id),
+ );
const current = selected ?? [];
- const next = isLabelGroupSelected(labels, group, current)
- ? current.filter((id) => !groupIds.includes(id))
- : [...current, ...groupIds.filter((id) => !current.includes(id))];
+ const selectedIds = new Set(current);
+ const next = current.some((id) => groupIds.has(id))
+ ? current.filter((id) => !groupIds.has(id))
+ : [...current, ...[...groupIds].filter((id) => !selectedIds.has(id))];
return next.length > 0 ? next : null;
}
+
+export function expandLabelFilter(
+ labels: FilterLabel[],
+ selected: string[] | null,
+): string[] | null {
+ if (!selected?.length) return selected;
+ const selectedIds = new Set(selected);
+ const selectedGroups = new Set(
+ labels.filter((label) => selectedIds.has(label.id)).map(labelGroupKey),
+ );
+ for (const label of labels) {
+ if (selectedGroups.has(labelGroupKey(label))) selectedIds.add(label.id);
+ }
+ return [...selectedIds];
+}
diff --git a/apps/web/src/lib/task-filters/task-matches-filters.test.ts b/apps/web/src/lib/task-filters/task-matches-filters.test.ts
index f1eb4c88a..c95195075 100644
--- a/apps/web/src/lib/task-filters/task-matches-filters.test.ts
+++ b/apps/web/src/lib/task-filters/task-matches-filters.test.ts
@@ -113,6 +113,23 @@ describe("taskMatchesFilters", () => {
).toBe(false);
});
+ it.each([false, true])(
+ "uses current label IDs with negation=%s",
+ (negated) => {
+ expect(
+ taskMatchesFilters(
+ task({}),
+ {
+ ...noFilters,
+ labels: ["saved-label"],
+ negated: negated ? ["labels"] : null,
+ },
+ { ...context, labelIds: new Set(["saved-label", "l1"]) },
+ ),
+ ).toBe(!negated);
+ },
+ );
+
it.each([
[{ priority: ["high"], negated: ["priority"] }, false],
[{ priority: ["low"], negated: ["priority"] }, true],
diff --git a/apps/web/src/lib/task-filters/task-matches-filters.ts b/apps/web/src/lib/task-filters/task-matches-filters.ts
index dd77e61ae..71a6437a7 100644
--- a/apps/web/src/lib/task-filters/task-matches-filters.ts
+++ b/apps/web/src/lib/task-filters/task-matches-filters.ts
@@ -18,6 +18,7 @@ export type TaskFilterContext = {
descriptionMatches?: ReadonlySet<string>;
weekStartsOn: Day;
today: Date;
+ labelIds?: ReadonlySet<string>;
getCustomFieldValues: (
taskId: string,
) => Array<{ fieldId: string; value: string | null }>;
@@ -76,7 +77,6 @@ export function taskMatchesFilters(
const negated = new Set(filters.negated ?? []);
const passes = (subject: string, matches: boolean) =>
negated.has(subject) ? !matches : matches;
- const labelIds = (task.labels ?? []).map((label) => label.id);
const checks: Array<[string, string[] | null | undefined, () => boolean]> = [
[
"status",
@@ -104,7 +104,12 @@ export function taskMatchesFilters(
[
"labels",
filters.labels,
- () => filters.labels?.some((id) => labelIds.includes(id)) ?? false,
+ () =>
+ (task.labels ?? []).some((label) =>
+ context.labelIds
+ ? context.labelIds.has(label.id)
+ : filters.labels?.includes(label.id),
+ ),
],
];
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/gantt.test.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/gantt.test.tsx
index a6ad76be2..9d97fa1cd 100644
--- a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/gantt.test.tsx
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/gantt.test.tsx
@@ -91,6 +91,9 @@ vi.mock("@/components/project/task-filters/use-task-filter-options", () => ({
}));
const noCustomFieldValues = () => [];
+vi.mock("@/hooks/queries/label/use-get-labels-by-workspace", () => ({
+ default: () => ({ data: undefined }),
+}));
vi.mock(
"@/hooks/queries/custom-field/use-get-all-custom-field-values-by-project",
() => ({
diff --git a/scripts/ci/upgrade.sh b/scripts/ci/upgrade.sh
index 9cd2ac865..2e6c8da8d 100644
--- a/scripts/ci/upgrade.sh
+++ b/scripts/ci/upgrade.sh
@@ -11,7 +11,19 @@ if [[ "$tag" != "v$version" ]]; then
fi
owner=$(printf '%s' "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')
image="ghcr.io/$owner/kaneo:$version"
-docker pull "$image"
+# GHCR can time out before returning headers even when the image is available.
+# Retry only acquisition; the upgrade and its assertions still run once.
+for attempt in 1 2 3; do
+ if docker pull "$image"; then
+ break
+ fi
+ if [[ "$attempt" == 3 ]]; then
+ echo "Unable to pull the stable upgrade image after $attempt attempts" >&2
+ exit 1
+ fi
+ echo "Retrying stable image pull (attempt $((attempt + 1))/3)" >&2
+ sleep "$((attempt * 5))"
+done
# Record and use the pulled digest so a mutable tag cannot change the baseline mid-test.
export KANEO_UPGRADE_IMAGE
authoritative_ref=$(docker image inspect "$image" --format '{{index .RepoDigests 0}}')