Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

feat: filter issues by cycle and initiative (#140)

Croffa4d574d34e1c
diff --git a/apps/api/src/issues/routes.ts b/apps/api/src/issues/routes.ts
index a3e6f068..f3a97e3d 100644
--- a/apps/api/src/issues/routes.ts
+++ b/apps/api/src/issues/routes.ts
@@ -112,9 +112,10 @@ const IssueResponse = t.Object({
// ordering the lanes of a board grouped by initiative, or null. Set through
// create/update by initiativeId.
initiative: t.Nullable(t.Object({ id: t.Number(), title: t.String(), status: t.String() })),
- // The cycle this issue is planned into, expanded to id + name, or null. Set
- // through create/update by cycleId.
- cycle: t.Nullable(t.Object({ id: t.Number(), name: t.String() })),
+ // The cycle this issue is planned into, expanded to id + name for rendering and
+ // status for filtering by the running or the upcoming ones, or null. Set through
+ // create/update by cycleId.
+ cycle: t.Nullable(t.Object({ id: t.Number(), name: t.String(), status: t.String() })),
assigneeUserId: t.Nullable(t.String()),
delegateUserId: t.Nullable(t.String()),
columnId: t.Number(),
diff --git a/apps/api/src/issues/store.ts b/apps/api/src/issues/store.ts
index 73a8da8e..078590f6 100644
--- a/apps/api/src/issues/store.ts
+++ b/apps/api/src/issues/store.ts
@@ -51,7 +51,7 @@ import { emitWebhookEvent } from '../webhooks/emit';
import { getAssignTriggerAgent, isProjectAgent } from '#modules/agents/core/service';
import { deleteThreadsWhere } from '#modules/agents/core/runtime/memory';
import { getInitiativeProjectId } from '#modules/initiatives/service';
-import { getCycleRef } from '#modules/cycles/service';
+import { cycleStatus, getCycleRef, type CycleStatus } from '#modules/cycles/service';
import { getMembership } from '../members/store';
import { enqueueAgentRun } from '#modules/agents/core/run-queue';
import { applySubtaskAutomation } from './automation';
@@ -82,9 +82,10 @@ export interface IssueRow {
// and status for ordering the lanes of a board grouped by initiative, or null.
// Filled by attachGroupings; mapIssue alone leaves it null.
initiative: { id: number; title: string; status: string } | null;
- // The cycle this issue is planned into, expanded to id + name for rendering, or
- // null. Filled by attachGroupings; mapIssue alone leaves it null.
- cycle: { id: number; name: string } | null;
+ // The cycle this issue is planned into, expanded to id + name for rendering and
+ // status for filtering by the running or the upcoming ones, or null. Filled by
+ // attachGroupings; mapIssue alone leaves it null.
+ cycle: { id: number; name: string; status: CycleStatus } | null;
assigneeUserId: string | null;
delegateUserId: string | null;
columnId: number;
@@ -454,7 +455,7 @@ export async function restoreIssue(
}
// Expands what an issue is planned under — its initiative and its cycle — to
-// { id, title, status } / { id, name } in place. Both hang off the same issue rows, so one
+// { id, title, status } / { id, name, status } in place. Both hang off the same issue rows, so one
// query carries them; an issue linked to neither keeps the nulls mapIssue set.
// Rendering those names on a board card needs no separate scaffold lookup this way.
async function attachGroupings(issues: IssueRow[]): Promise<void> {
@@ -467,6 +468,8 @@ async function attachGroupings(issues: IssueRow[]): Promise<void> {
initiativeStatus: initiative.status,
cycleId: cycle.id,
cycleName: cycle.name,
+ cycleStart: cycle.startDate,
+ cycleEnd: cycle.endDate,
})
.from(issue)
.leftJoin(initiative, eq(initiative.id, issue.initiativeId))
@@ -487,7 +490,14 @@ async function attachGroupings(issues: IssueRow[]): Promise<void> {
r && r.initiativeId != null
? { id: r.initiativeId, title: r.initiativeTitle!, status: r.initiativeStatus! }
: null;
- i.cycle = r && r.cycleId != null ? { id: r.cycleId, name: r.cycleName! } : null;
+ i.cycle =
+ r && r.cycleId != null
+ ? {
+ id: r.cycleId,
+ name: r.cycleName!,
+ status: cycleStatus(r.cycleStart!, r.cycleEnd!),
+ }
+ : null;
}
}
diff --git a/apps/api/src/modules/cycles/service.ts b/apps/api/src/modules/cycles/service.ts
index 66bf784c..1e43d69b 100644
--- a/apps/api/src/modules/cycles/service.ts
+++ b/apps/api/src/modules/cycles/service.ts
@@ -29,7 +29,7 @@ export interface CycleRow {
// Compared in UTC against the date columns, so a cycle turns active and completed on
// its own boundary days regardless of the reader's zone.
-function cycleStatus(startDate: string, endDate: string): CycleStatus {
+export function cycleStatus(startDate: string, endDate: string): CycleStatus {
const today = new Date().toISOString().slice(0, 10);
if (today < startDate) return 'upcoming';
if (today > endDate) return 'completed';
diff --git a/apps/api/src/share/__tests__/integration/share.test.ts b/apps/api/src/share/__tests__/integration/share.test.ts
index 69c6cfb9..0305bed2 100644
--- a/apps/api/src/share/__tests__/integration/share.test.ts
+++ b/apps/api/src/share/__tests__/integration/share.test.ts
@@ -219,6 +219,45 @@ describe('share', () => {
expect(opened.status).toBe(404);
});
+ it('excludes issues a cycle or initiative filter hides, by id and by status', async () => {
+ const { asOwner, issueId, columnId } = await setup();
+ const project = asOwner.projects({ projectKey: 'MKT' });
+ // Dates around today, so the cycle is the running one.
+ const cycle = await project.cycles.post({
+ name: 'Sprint 1',
+ startDate: '2000-01-01',
+ endDate: '2099-01-14',
+ });
+ const initiative = await project.initiatives.post({ title: 'Q3' });
+ await asOwner
+ .issues({ issueId })
+ .patch({ cycleId: cycle.data!.id, initiativeId: initiative.data!.id });
+ const outside = await project.issues.post({ columnId, title: 'Unplanned' });
+
+ for (const condition of [
+ { id: 'c1', field: 'cycle', op: 'is' as const, values: [cycle.data!.id] },
+ { id: 'c1', field: 'initiative', op: 'is' as const, values: [initiative.data!.id] },
+ { id: 'c1', field: 'cycle', op: 'is' as const, values: ['status:active'] },
+ {
+ id: 'c1',
+ field: 'initiative',
+ op: 'is' as const,
+ values: [`status:${initiative.data!.status}`],
+ },
+ ]) {
+ const view = await project.views.post({
+ name: 'Filtered',
+ filters: { conditions: [condition] },
+ });
+ const token = (await asOwner.views({ viewId: view.data!.id }).share.post()).data!.token;
+
+ const shared = await api.share.view({ token }).get();
+ const ids = shared.data.issues.map((i: { id: number }) => i.id);
+ expect(ids).toContain(issueId);
+ expect(ids).not.toContain(outside.data!.id);
+ }
+ });
+
it('leaves relations to issues the view filter hides out of the board and the opened issue', async () => {
const { asOwner, issueId, columnId } = await setup();
const board = await asOwner.projects({ projectKey: 'MKT' }).get();
diff --git a/apps/api/src/views/filters.ts b/apps/api/src/views/filters.ts
index 167fc665..de546310 100644
--- a/apps/api/src/views/filters.ts
+++ b/apps/api/src/views/filters.ts
@@ -14,6 +14,8 @@ type FilterField =
| 'delegate'
| 'priority'
| 'type'
+ | 'initiative'
+ | 'cycle'
| 'labels'
| 'dueDate'
| 'startDate'
@@ -37,6 +39,13 @@ interface FilterSet {
const DATE_FIELDS: FilterField[] = ['dueDate', 'startDate', 'created', 'updated'];
+// A condition on the initiative or the cycle names either one of them by id or a
+// whole status this way ("the running cycle"), so an issue matches both its own id
+// and the status it is planned under.
+function statusValue(status: string): string {
+ return `status:${status}`;
+}
+
function parseCustomFieldKey(field: string): number | null {
return field.startsWith('cf:') ? Number(field.slice(3)) : null;
}
@@ -82,6 +91,12 @@ function builtinSetValues(
return [issue.priority];
case 'type':
return [issue.typeId];
+ case 'initiative':
+ return issue.initiative
+ ? [issue.initiative.id, statusValue(issue.initiative.status)]
+ : [null];
+ case 'cycle':
+ return issue.cycle ? [issue.cycle.id, statusValue(issue.cycle.status)] : [null];
case 'labels':
return issue.labelIds.length ? issue.labelIds : [null];
default:
diff --git a/apps/web/messages/en/filters.json b/apps/web/messages/en/filters.json
index 3bc272b0..84ff3ba9 100644
--- a/apps/web/messages/en/filters.json
+++ b/apps/web/messages/en/filters.json
@@ -18,6 +18,15 @@
"true": "True",
"false": "False"
},
+ "cycleStatus": {
+ "active": "Active cycle",
+ "upcoming": "Upcoming cycles"
+ },
+ "initiativeStatus": {
+ "active": "Active initiatives",
+ "planned": "Planned initiatives",
+ "proposed": "Proposed initiatives"
+ },
"fields": {
"status": "State",
"statusType": "State type",
@@ -25,6 +34,8 @@
"delegate": "Delegate",
"priority": "Priority",
"type": "Type",
+ "initiative": "Initiative",
+ "cycle": "Cycle",
"labels": "Labels",
"dueDate": "Due date",
"startDate": "Start date",
@@ -34,6 +45,8 @@
"unset": {
"assignee": "No assignee",
"delegate": "No delegate",
- "type": "No type"
+ "type": "No type",
+ "initiative": "No initiative",
+ "cycle": "No cycle"
}
}
diff --git a/apps/web/messages/ru/filters.json b/apps/web/messages/ru/filters.json
index e24d8325..f631db52 100644
--- a/apps/web/messages/ru/filters.json
+++ b/apps/web/messages/ru/filters.json
@@ -18,6 +18,15 @@
"true": "Да",
"false": "Нет"
},
+ "cycleStatus": {
+ "active": "Активный цикл",
+ "upcoming": "Запланированные циклы"
+ },
+ "initiativeStatus": {
+ "active": "Активные инициативы",
+ "planned": "Запланированные инициативы",
+ "proposed": "Предложенные инициативы"
+ },
"fields": {
"status": "Статус",
"statusType": "Тип статуса",
@@ -25,6 +34,8 @@
"delegate": "Делегат",
"priority": "Приоритет",
"type": "Тип",
+ "initiative": "Инициатива",
+ "cycle": "Цикл",
"labels": "Метки",
"dueDate": "Дедлайн",
"startDate": "Дата начала",
@@ -34,6 +45,8 @@
"unset": {
"assignee": "Без исполнителя",
"delegate": "Без делегата",
- "type": "Без типа"
+ "type": "Без типа",
+ "initiative": "Без инициативы",
+ "cycle": "Без цикла"
}
}
diff --git a/apps/web/messages/uk/filters.json b/apps/web/messages/uk/filters.json
index f002861c..16606884 100644
--- a/apps/web/messages/uk/filters.json
+++ b/apps/web/messages/uk/filters.json
@@ -18,6 +18,15 @@
"true": "Так",
"false": "Ні"
},
+ "cycleStatus": {
+ "active": "Активний цикл",
+ "upcoming": "Заплановані цикли"
+ },
+ "initiativeStatus": {
+ "active": "Активні ініціативи",
+ "planned": "Заплановані ініціативи",
+ "proposed": "Запропоновані ініціативи"
+ },
"fields": {
"status": "Статус",
"statusType": "Тип статусу",
@@ -25,6 +34,8 @@
"delegate": "Делегат",
"priority": "Пріоритет",
"type": "Тип",
+ "initiative": "Ініціатива",
+ "cycle": "Цикл",
"labels": "Мітки",
"dueDate": "Дедлайн",
"startDate": "Дата початку",
@@ -34,6 +45,8 @@
"unset": {
"assignee": "Без виконавця",
"delegate": "Без делегата",
- "type": "Без типу"
+ "type": "Без типу",
+ "initiative": "Без ініціативи",
+ "cycle": "Без циклу"
}
}
diff --git a/apps/web/messages/zh-CN/filters.json b/apps/web/messages/zh-CN/filters.json
index 407b920a..afc2bdc7 100644
--- a/apps/web/messages/zh-CN/filters.json
+++ b/apps/web/messages/zh-CN/filters.json
@@ -18,6 +18,15 @@
"true": "是",
"false": "否"
},
+ "cycleStatus": {
+ "active": "进行中的周期",
+ "upcoming": "即将开始的周期"
+ },
+ "initiativeStatus": {
+ "active": "进行中的计划",
+ "planned": "已规划的计划",
+ "proposed": "提议中的计划"
+ },
"fields": {
"status": "状态",
"statusType": "状态类型",
@@ -25,6 +34,8 @@
"delegate": "执行代理",
"priority": "优先级",
"type": "类型",
+ "initiative": "计划",
+ "cycle": "周期",
"labels": "标签",
"dueDate": "截止日期",
"startDate": "开始日期",
@@ -34,6 +45,8 @@
"unset": {
"assignee": "无负责人",
"delegate": "无执行代理",
- "type": "无类型"
+ "type": "无类型",
+ "initiative": "无计划",
+ "cycle": "无周期"
}
}
diff --git a/apps/web/src/components/layout/FilterBar.tsx b/apps/web/src/components/layout/FilterBar.tsx
index fab7869f..1038ea5c 100644
--- a/apps/web/src/components/layout/FilterBar.tsx
+++ b/apps/web/src/components/layout/FilterBar.tsx
@@ -23,10 +23,13 @@ export default function FilterBar({
customFields: CustomField[];
}) {
const t = useTranslations('filters');
- const { fieldSpecs } = useFilterFields();
+ const { fieldSpecs } = useFilterFields(project.project.key);
const [addOpen, setAddOpen] = useState(false);
const specs = fieldSpecs(project, customFields);
- const specByField = new Map(specs.map((s) => [s.field, s]));
+ // The pills read a catalog that also carries the fields only the current
+ // conditions still name, so a condition on a switched-off section stays visible
+ // and removable while the add menu no longer offers it.
+ const specByField = new Map(fieldSpecs(project, customFields, filters).map((s) => [s.field, s]));
const update = (id: string, patch: Partial<FilterCondition>) =>
onChange({ conditions: filters.conditions.map((c) => (c.id === id ? { ...c, ...patch } : c)) });
diff --git a/apps/web/src/components/layout/FilterValueEditor.tsx b/apps/web/src/components/layout/FilterValueEditor.tsx
index 3621032d..e993dbc5 100644
--- a/apps/web/src/components/layout/FilterValueEditor.tsx
+++ b/apps/web/src/components/layout/FilterValueEditor.tsx
@@ -91,30 +91,32 @@ export default function FilterValueEditor({
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>{trigger}</PopoverTrigger>
- <PopoverContent align="start" className="max-h-72 w-56 overflow-auto p-1">
+ <PopoverContent align="start" className="max-h-72 w-72 overflow-auto p-1">
{options.map((o) => {
const checked = cond.values.some((v) => v === o.value);
return (
- <button
- key={String(o.value)}
- type="button"
- onClick={() => toggle(o.value)}
- className={cn(
- 'flex w-full items-center gap-2 rounded px-2 py-1 text-left text-sm hover:bg-accent',
- checked && 'font-medium',
- )}
- >
- <span
+ <div key={String(o.value)}>
+ {o.dividerBefore && <div className="my-1 h-px bg-border" />}
+ <button
+ type="button"
+ onClick={() => toggle(o.value)}
className={cn(
- 'size-3 rounded-full border',
- checked ? 'border-primary bg-primary' : 'border-muted-foreground',
+ 'flex w-full items-center gap-2 rounded px-2 py-1 text-left text-sm hover:bg-accent',
+ checked && 'font-medium',
)}
- />
- {o.color && (
- <span className="size-2.5 rounded-full" style={{ backgroundColor: o.color }} />
- )}
- <span className="truncate">{o.label}</span>
- </button>
+ >
+ <span
+ className={cn(
+ 'size-3 rounded-full border',
+ checked ? 'border-primary bg-primary' : 'border-muted-foreground',
+ )}
+ />
+ {o.color && (
+ <span className="size-2.5 rounded-full" style={{ backgroundColor: o.color }} />
+ )}
+ <span className="truncate">{o.label}</span>
+ </button>
+ </div>
);
})}
{options.length === 0 && (
diff --git a/apps/web/src/features/cycles/components/detail/CycleIssuesBoard.tsx b/apps/web/src/features/cycles/components/detail/CycleIssuesBoard.tsx
index 131b88ac..90ecf5c4 100644
--- a/apps/web/src/features/cycles/components/detail/CycleIssuesBoard.tsx
+++ b/apps/web/src/features/cycles/components/detail/CycleIssuesBoard.tsx
@@ -35,6 +35,7 @@ export default function CycleIssuesBoard({ cycle }: { cycle: Cycle }) {
const viewProps = {
project: viewProject,
+ filters: board.filters,
customFields,
settings: board.settings,
onSettingsChange: board.changeSettings,
diff --git a/apps/web/src/features/initiatives/components/detail/InitiativeIssuesBoard.tsx b/apps/web/src/features/initiatives/components/detail/InitiativeIssuesBoard.tsx
index 8cc0f338..1233177a 100644
--- a/apps/web/src/features/initiatives/components/detail/InitiativeIssuesBoard.tsx
+++ b/apps/web/src/features/initiatives/components/detail/InitiativeIssuesBoard.tsx
@@ -32,6 +32,7 @@ export default function InitiativeIssuesBoard({ initiativeId }: { initiativeId:
const viewProps = {
project: viewProject,
+ filters: board.filters,
customFields,
settings: board.settings,
onSettingsChange: board.changeSettings,
diff --git a/apps/web/src/features/settings/components/actions/SettingsActionRow.tsx b/apps/web/src/features/settings/components/actions/SettingsActionRow.tsx
index 68eff823..b9bdeaef 100644
--- a/apps/web/src/features/settings/components/actions/SettingsActionRow.tsx
+++ b/apps/web/src/features/settings/components/actions/SettingsActionRow.tsx
@@ -27,7 +27,7 @@ export function SettingsActionRow({
}) {
const t = useTranslations('settings.actions');
const can = useSettingsCan();
- const { describeConditions } = useFilterFields();
+ const { describeConditions } = useFilterFields(project.project.key);
const effectText = useEffectText();
const conditions = describeConditions(action.condition, project, customFields);
const effects = describeEffect(action.effect, project, effectText);
diff --git a/apps/web/src/features/work-items/WorkItemsPage.tsx b/apps/web/src/features/work-items/WorkItemsPage.tsx
index 6235f646..f2e28ec1 100644
--- a/apps/web/src/features/work-items/WorkItemsPage.tsx
+++ b/apps/web/src/features/work-items/WorkItemsPage.tsx
@@ -72,7 +72,12 @@ export default function WorkItemsPage() {
const changeSettings = (next: ViewSettings) =>
editor.changeSettings(restoreHiddenSections(next, editor.settings, features));
- const timelineGroups = buildGroups(filteredProject, settings.group, groupLabels);
+ const timelineGroups = buildGroups(
+ filteredProject,
+ settings.group,
+ groupLabels,
+ editor.effectiveFilters,
+ );
const timelineIssuesByGroup = groupIssues(timelineGroups, filteredProject.issues, settings.group);
const visibleTimelineGroupKeys = timelineGroups
.filter(
@@ -109,6 +114,7 @@ export default function WorkItemsPage() {
const viewProps = {
project: filteredProject,
+ filters: editor.effectiveFilters,
customFields,
settings,
onSettingsChange: changeSettings,
diff --git a/apps/web/src/features/work-items/components/kanban/FlatBoard.tsx b/apps/web/src/features/work-items/components/kanban/FlatBoard.tsx
index e1694376..54e4ab93 100644
--- a/apps/web/src/features/work-items/components/kanban/FlatBoard.tsx
+++ b/apps/web/src/features/work-items/components/kanban/FlatBoard.tsx
@@ -26,6 +26,7 @@ import { CollapsedColumn } from './CollapsedColumn';
// with a trailing "Hidden" panel for manually-hidden columns.
export default function FlatBoard({
project,
+ filters,
settings,
onSettingsChange,
onOpenIssue,
@@ -62,7 +63,7 @@ export default function FlatBoard({
: settings.collapsedGroups.filter((k) => k !== key),
});
- const groups = buildGroups(project, settings.group, groupLabels);
+ const groups = buildGroups(project, settings.group, groupLabels, filters);
const sorted = sortIssues(project.issues, settings.sort, project);
const issuesByGroup = groupIssues(groups, sorted, settings.group);
const maps = buildMaps(project);
diff --git a/apps/web/src/features/work-items/components/kanban/SwimlaneBoard.tsx b/apps/web/src/features/work-items/components/kanban/SwimlaneBoard.tsx
index 16d90cab..4dc25329 100644
--- a/apps/web/src/features/work-items/components/kanban/SwimlaneBoard.tsx
+++ b/apps/web/src/features/work-items/components/kanban/SwimlaneBoard.tsx
@@ -46,6 +46,7 @@ interface SwimlaneRow {
// with the sticky column header row.
export default function SwimlaneBoard({
project,
+ filters,
settings,
onOpenIssue,
readOnly,
@@ -57,8 +58,8 @@ export default function SwimlaneBoard({
const collapsed = usePersistedSet(collapsedSwimlanesKey(project.project.id, settings.subgroup));
const maps = buildMaps(project);
- const columnGroups = buildGroups(project, settings.group, groupLabels);
- const swimlaneGroups = buildGroups(project, settings.subgroup, groupLabels);
+ const columnGroups = buildGroups(project, settings.group, groupLabels, filters);
+ const swimlaneGroups = buildGroups(project, settings.subgroup, groupLabels, filters);
const sorted = sortIssues(project.issues, settings.sort, project);
const nested = nestIssues(
swimlaneGroups,
diff --git a/apps/web/src/features/work-items/components/public/ReadOnlyBoard.tsx b/apps/web/src/features/work-items/components/public/ReadOnlyBoard.tsx
index b3c2a367..1adef899 100644
--- a/apps/web/src/features/work-items/components/public/ReadOnlyBoard.tsx
+++ b/apps/web/src/features/work-items/components/public/ReadOnlyBoard.tsx
@@ -1,5 +1,6 @@
import { type SharedViewBundle } from '@/lib/api';
import { defaultViewSettings } from '@/utils/viewSettings';
+import { EMPTY_FILTER_SET } from '@/utils/filters';
import { type WorkItemsViewProps } from '@/utils/project';
import { toPublicProjectDetail } from '@/utils/publicProject';
import { withoutShownSubtasks } from '@/utils/subtasks';
@@ -43,6 +44,8 @@ export default function ReadOnlyBoard({
const viewProps: WorkItemsViewProps = {
project: boardProject,
+ // The view's filters stay on the server, which sends only the issues they match.
+ filters: EMPTY_FILTER_SET,
customFields: project.customFields,
settings,
onSettingsChange: noop,
diff --git a/apps/web/src/features/work-items/components/table/TableView.tsx b/apps/web/src/features/work-items/components/table/TableView.tsx
index 565297ee..d3381278 100644
--- a/apps/web/src/features/work-items/components/table/TableView.tsx
+++ b/apps/web/src/features/work-items/components/table/TableView.tsx
@@ -39,6 +39,7 @@ interface TableViewProps extends WorkItemsViewProps {
export default function TableView({
project,
+ filters,
customFields,
settings,
onOpenIssue,
@@ -61,8 +62,8 @@ export default function TableView({
const grouped = settings.group !== 'none';
const subgrouped = grouped && settings.subgroup !== 'none';
const sorted = sortIssues(project.issues, settings.sort, project);
- const groups = buildGroups(project, settings.group, groupLabels);
- const subGroups = subgrouped ? buildGroups(project, settings.subgroup, groupLabels) : [];
+ const groups = buildGroups(project, settings.group, groupLabels, filters);
+ const subGroups = subgrouped ? buildGroups(project, settings.subgroup, groupLabels, filters) : [];
const maps = buildMaps(project);
const { columns, gridTemplate, minWidth, alignTop } = resolveColumns(
diff --git a/apps/web/src/features/work-items/components/timeline/TimelineView.tsx b/apps/web/src/features/work-items/components/timeline/TimelineView.tsx
index eef79404..2d1def2a 100644
--- a/apps/web/src/features/work-items/components/timeline/TimelineView.tsx
+++ b/apps/web/src/features/work-items/components/timeline/TimelineView.tsx
@@ -26,6 +26,7 @@ interface TimelineViewProps extends WorkItemsViewProps {
export default function TimelineView({
project,
+ filters,
settings,
onOpenIssue,
collapsedGroups,
@@ -57,6 +58,7 @@ export default function TimelineView({
const scrollRef = useRef<HTMLDivElement>(null);
const { preview, dropGroupKey, beginDrag } = useTimelineDrag({
project,
+ filters,
group: settings.group,
subgroup: settings.subgroup,
dayW: DAY_W,
@@ -74,6 +76,7 @@ export default function TimelineView({
const { rows, days, months, trackWidth, todayLeft, todayInRange, dayLines, spanToRect } =
buildTimeline({
project,
+ filters,
group: settings.group,
subgroup: settings.subgroup,
groupLabels,
diff --git a/apps/web/src/features/work-items/hooks/useTimelineDrag.ts b/apps/web/src/features/work-items/hooks/useTimelineDrag.ts
index e57e615d..cd0577cc 100644
--- a/apps/web/src/features/work-items/hooks/useTimelineDrag.ts
+++ b/apps/web/src/features/work-items/hooks/useTimelineDrag.ts
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { type Issue, type IssuePatch, type ProjectDetail } from '@/lib/api';
+import type { FilterSet } from '@/utils/filters';
import { addDays, toDateStr } from '@/utils/dates';
import { buildGroups, groupKeyOf, mergeAssign, subgroupKey } from '@/utils/project';
import { useGroupLabels } from '@/hooks/useGroupLabels';
@@ -29,12 +30,14 @@ interface DragSession {
// to highlight the target.
export function useTimelineDrag({
project,
+ filters,
group,
subgroup,
dayW,
onOpenIssue,
}: {
project: ProjectDetail;
+ filters: FilterSet;
group: GroupField;
subgroup: GroupField;
dayW: number;
@@ -43,11 +46,11 @@ export function useTimelineDrag({
const groupLabels = useGroupLabels();
const updateIssue = useUpdateIssue(project.project.key);
const subgrouped = group !== 'none' && subgroup !== 'none';
- const subGroups = subgrouped ? buildGroups(project, subgroup, groupLabels) : [];
+ const subGroups = subgrouped ? buildGroups(project, subgroup, groupLabels, filters) : [];
// The patch each drop target applies: the group's own, and — when sub-grouped —
// the two grouping fields combined for every sub-section.
const assignByKey = new Map<string, IssuePatch | null>();
- for (const issueGroup of buildGroups(project, group, groupLabels)) {
+ for (const issueGroup of buildGroups(project, group, groupLabels, filters)) {
assignByKey.set(issueGroup.key, issueGroup.assign);
for (const sub of subGroups) {
assignByKey.set(
diff --git a/apps/web/src/features/work-items/utils/timeline.ts b/apps/web/src/features/work-items/utils/timeline.ts
index 06bf6feb..55721ebc 100644
--- a/apps/web/src/features/work-items/utils/timeline.ts
+++ b/apps/web/src/features/work-items/utils/timeline.ts
@@ -1,6 +1,7 @@
import { startOfDay } from 'date-fns';
import { type BoardIssue, type Issue, type ProjectDetail } from '@/lib/api';
import { parseDate } from '@/utils/dates';
+import type { FilterSet } from '@/utils/filters';
import { buildDayTrack, type DayTrack } from '@/utils/timelineTrack';
import {
buildGroups,
@@ -90,6 +91,7 @@ export interface TimelineModel extends DayTrack {
export function buildTimeline({
project,
+ filters,
group,
subgroup,
groupLabels,
@@ -100,6 +102,7 @@ export function buildTimeline({
dayW,
}: {
project: ProjectDetail;
+ filters: FilterSet;
group: GroupField;
subgroup: GroupField;
groupLabels: GroupLabels;
@@ -109,9 +112,9 @@ export function buildTimeline({
labelW: number;
dayW: number;
}): TimelineModel {
- const groups = buildGroups(project, group, groupLabels);
+ const groups = buildGroups(project, group, groupLabels, filters);
const subgrouped = group !== 'none' && subgroup !== 'none';
- const subGroups = subgrouped ? buildGroups(project, subgroup, groupLabels) : [];
+ const subGroups = subgrouped ? buildGroups(project, subgroup, groupLabels, filters) : [];
const rows: TimelineRow[] = [];
const spanned = (issues: BoardIssue[]) =>
diff --git a/apps/web/src/hooks/useFilterFields.ts b/apps/web/src/hooks/useFilterFields.ts
index b4e7fab7..3c018c57 100644
--- a/apps/web/src/hooks/useFilterFields.ts
+++ b/apps/web/src/hooks/useFilterFields.ts
@@ -1,17 +1,31 @@
'use client';
import { useTranslations } from 'next-intl';
-import type { CustomField, ProjectDetail } from '@/lib/api';
+import type { CustomField, InitiativeOption, InitiativeRef, ProjectDetail } from '@/lib/api';
+import { useInitiativeOptionsQuery } from '@/services/initiatives.service';
+import { CYCLE_STATUS_META } from '@/utils/cycleMeta';
import { formatDate } from '@/utils/dates';
-import { PRIORITY_FILTER_VALUES, STATE_TYPES } from '@/utils/fieldOptions';
-import type { FilterCondition, FilterSet, FilterValue } from '@/utils/filters';
+import {
+ CYCLE_FILTER_STATUSES,
+ INITIATIVE_FILTER_STATUSES,
+ PRIORITY_FILTER_VALUES,
+ STATE_TYPES,
+} from '@/utils/fieldOptions';
+import { compareByGroupOrder } from '@/utils/initiativeMeta';
+import { projectFeatures } from '@/utils/projectFeatures';
+import {
+ statusValue,
+ type FilterCondition,
+ type FilterSet,
+ type FilterValue,
+} from '@/utils/filters';
import {
OPERATORS_BY_KIND,
type FieldKind,
type FieldOption,
type FieldSpec,
} from '@/utils/filterFields';
-import { customFieldKey } from '@/utils/viewSettings';
+import { customFieldKey, isFieldEnabled, type GroupField } from '@/utils/viewSettings';
import { usePriorityLabel } from '@/hooks/usePriorityLabel';
import { byKey } from '@/utils/messageKey';
@@ -35,6 +49,47 @@ function customFieldKind(field: CustomField): FieldKind {
}
}
+// The initiatives to offer: the ones an issue can be linked to, so a view can be
+// set up for an initiative that carries no issue yet, then the closed ones only the
+// issues name, ordered by status and title, so the work under them stays filterable.
+function initiativeOptions(project: ProjectDetail, linkable: InitiativeOption[]): FieldOption[] {
+ const namedByIssues = new Map<number, InitiativeRef>();
+ for (const issue of project.issues)
+ if (issue.initiative) namedByIssues.set(issue.initiative.id, issue.initiative);
+ for (const i of linkable) namedByIssues.delete(i.id);
+ return [
+ ...linkable.map((i) => ({ value: i.id, label: i.title })),
+ ...[...namedByIssues.values()]
+ .sort(compareByGroupOrder)
+ .map((i) => ({ value: i.id, label: i.title })),
+ ];
+}
+
+// The cycles to offer: the ones the project plans into, then the finished ones
+// only the issues name, so work planned into them stays reachable.
+function cycleOptions(project: ProjectDetail): FieldOption[] {
+ const namedByIssues = new Map<number, string>();
+ for (const issue of project.issues)
+ if (issue.cycle) namedByIssues.set(issue.cycle.id, issue.cycle.name);
+ for (const c of project.plannedCycles) namedByIssues.delete(c.id);
+ return [
+ ...project.plannedCycles.map((c) => ({
+ value: c.id,
+ label: c.name,
+ color: CYCLE_STATUS_META[c.status].color,
+ })),
+ ...[...namedByIssues.entries()]
+ .sort((a, b) => a[1].localeCompare(b[1]))
+ .map(([id, name]) => ({ value: id, label: name })),
+ ];
+}
+
+// Marks the first option, so a rule separates the ones naming a single cycle or
+// initiative from the values that stand for a whole status.
+function withDivider(options: FieldOption[]): FieldOption[] {
+ return options.map((o, i) => (i === 0 ? { ...o, dividerBefore: true } : o));
+}
+
// A fresh condition for a newly picked field, with the kind's first operator and
// no values, so it is inert (see isEffectiveCondition) until the user fills it in.
export function newCondition(spec: FieldSpec): FilterCondition {
@@ -48,11 +103,15 @@ export function newCondition(spec: FieldSpec): FilterCondition {
// The filter vocabulary in the reader's language: the field catalog of a project,
// the operator names, the boolean choices, and the short renderings a pill and a
-// saved action show.
-export function useFilterFields() {
+// saved action show. `projectKey` is what the initiative options are read under —
+// pass it wherever the catalog or a description is built.
+export function useFilterFields(projectKey?: string) {
const t = useTranslations('filters');
+ const initiatives = useInitiativeOptionsQuery(projectKey ?? null).data ?? [];
const operator = byKey(useTranslations('filters.operators'));
const stateType = byKey(useTranslations('display.stateTypes'));
+ const cycleStatus = byKey(useTranslations('filters.cycleStatus'));
+ const initiativeStatus = byKey(useTranslations('filters.initiativeStatus'));
const priorityLabel = usePriorityLabel();
const booleanOptions: FieldOption[] = [
@@ -63,8 +122,14 @@ export function useFilterFields() {
const operatorLabel = (op: FilterCondition['op']) => operator(op);
// The full catalog of filterable fields for a project: builtins plus every
- // custom field.
- const fieldSpecs = (project: ProjectDetail, customFields: CustomField[]): FieldSpec[] => {
+ // custom field. `kept` is a filter set whose fields stay in the catalog even
+ // when their section is off, so a condition saved earlier still renders as a
+ // removable pill instead of filtering invisibly.
+ const fieldSpecs = (
+ project: ProjectDetail,
+ customFields: CustomField[],
+ kept?: FilterSet | null,
+ ): FieldSpec[] => {
const specs: FieldSpec[] = [
{
field: 'status',
@@ -118,6 +183,33 @@ export function useFilterFields() {
{ value: null, label: t('unset.type') },
],
},
+ {
+ field: 'initiative',
+ label: t('fields.initiative'),
+ kind: 'set',
+ options: [
+ ...INITIATIVE_FILTER_STATUSES.map((s) => ({
+ value: statusValue(s),
+ label: initiativeStatus(s),
+ })),
+ { value: null, label: t('unset.initiative') },
+ ...withDivider(initiativeOptions(project, initiatives)),
+ ],
+ },
+ {
+ field: 'cycle',
+ label: t('fields.cycle'),
+ kind: 'set',
+ options: [
+ ...CYCLE_FILTER_STATUSES.map((s) => ({
+ value: statusValue(s),
+ label: cycleStatus(s),
+ color: CYCLE_STATUS_META[s].color,
+ })),
+ { value: null, label: t('unset.cycle') },
+ ...withDivider(cycleOptions(project)),
+ ],
+ },
{
field: 'labels',
label: t('fields.labels'),
@@ -141,7 +233,13 @@ export function useFilterFields() {
: undefined,
});
}
- return specs;
+ // The fields of an optional section are offered only while it is on, as the
+ // grouping fields and display properties are.
+ const features = projectFeatures(project.project);
+ const used = new Set((kept?.conditions ?? []).map((c) => c.field));
+ return specs.filter(
+ (s) => isFieldEnabled(s.field as GroupField, features) || used.has(s.field),
+ );
};
// Short display of a condition's chosen values for the pill.
@@ -170,7 +268,7 @@ export function useFilterFields() {
customFields: CustomField[],
): string[] => {
if (!filters) return [];
- const byField = new Map(fieldSpecs(project, customFields).map((s) => [s.field, s]));
+ const byField = new Map(fieldSpecs(project, customFields, filters).map((s) => [s.field, s]));
const out: string[] = [];
for (const cond of filters.conditions) {
const spec = byField.get(cond.field);
diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts
index 2416ce1c..ddfa4273 100644
--- a/apps/web/src/lib/api.ts
+++ b/apps/web/src/lib/api.ts
@@ -1483,6 +1483,7 @@ export interface InitiativeRef {
export interface CycleRef {
id: number;
name: string;
+ status: CycleStatus;
}
// The board scaffold, returned by getProject: everything the work-items UI needs
diff --git a/apps/web/src/utils/fieldOptions.ts b/apps/web/src/utils/fieldOptions.ts
index adfebc98..9752ac49 100644
--- a/apps/web/src/utils/fieldOptions.ts
+++ b/apps/web/src/utils/fieldOptions.ts
@@ -3,7 +3,7 @@
// keeping its own copy. Adding a priority/state is a single edit in this file
// (plus its icon in the two icon renderers and its message).
-import type { StateType } from '@/lib/api';
+import type { CycleStatus, InitiativeStatus, StateType } from '@/lib/api';
export type Priority = 'urgent' | 'high' | 'medium' | 'low';
@@ -21,6 +21,15 @@ export const PRIORITY_RANK: Record<string, number> = Object.fromEntries(
// Filter-builder values: the priorities plus an explicit "unset" choice (null).
export const PRIORITY_FILTER_VALUES: (Priority | null)[] = [...PRIORITY_ORDER, null];
+// The cycle and initiative statuses a filter can name instead of one of them by
+// id, so a saved view follows the cycles as they roll over and the initiatives as
+// they start. The closed ones are left out: they are picked by name, and a filter
+// on "completed" would keep growing. Their labels are messages under
+// `filters.cycleStatus` / `filters.initiativeStatus`.
+export const CYCLE_FILTER_STATUSES: CycleStatus[] = ['active', 'upcoming'];
+
+export const INITIATIVE_FILTER_STATUSES: InitiativeStatus[] = ['active', 'planned', 'proposed'];
+
// State types in workflow order. The label of a state type is a message under
// `display.stateTypes`.
export const STATE_TYPES: StateType[] = [
diff --git a/apps/web/src/utils/filterFields.ts b/apps/web/src/utils/filterFields.ts
index fd881c71..8ea331f0 100644
--- a/apps/web/src/utils/filterFields.ts
+++ b/apps/web/src/utils/filterFields.ts
@@ -7,11 +7,15 @@ export interface FieldOption {
value: FilterValue;
label: string;
color?: string;
+ // Draws a rule above this option, which splits a list into groups — the values
+ // that stand for a whole status of the cycle or the initiative, then the ones
+ // that name a single one.
+ dividerBefore?: boolean;
}
// One filterable field: how it is labeled, what kind of value it holds, and (for
// set fields) the choices. `field` is the persisted key (a builtin name or
-// `cf:<id>`). Built by useFieldSpecs, which names the builtins in the reader's
+// `cf:<id>`). Built by useFilterFields, which names the builtins in the reader's
// language.
export interface FieldSpec {
field: string;
@@ -31,7 +35,7 @@ export const OPERATORS_BY_KIND: Record<FieldKind, FilterOperator[]> = {
};
// The builtin filterable fields, in menu order. Their options come from the
-// project (see useFieldSpecs); the custom fields follow them.
+// project (see useFilterFields); the custom fields follow them.
export const BUILTIN_FILTER_FIELDS = [
'status',
'statusType',
@@ -39,6 +43,8 @@ export const BUILTIN_FILTER_FIELDS = [
'delegate',
'priority',
'type',
+ 'initiative',
+ 'cycle',
'labels',
'dueDate',
'startDate',
diff --git a/apps/web/src/utils/filters.ts b/apps/web/src/utils/filters.ts
index 39c7fa19..f6d9311f 100644
--- a/apps/web/src/utils/filters.ts
+++ b/apps/web/src/utils/filters.ts
@@ -15,6 +15,8 @@ export type BuiltinFilterField =
| 'delegate' // delegate agent id, or null for "no delegate"
| 'priority' // priority string, or null for "no priority"
| 'type' // issue type id, or null for "no type"
+ | 'initiative' // initiative id or `status:<status>`, or null for "no initiative"
+ | 'cycle' // cycle id or `status:<status>`, or null for "no cycle"
| 'labels' // label ids (a issue has any/none of the chosen ones)
| 'dueDate'
| 'startDate'
@@ -47,6 +49,14 @@ export interface FilterSet {
export const EMPTY_FILTER_SET: FilterSet = { conditions: [] };
+// The value that stands for a whole status of the initiative or the cycle an issue
+// is planned under, instead of one of them by id: "the running cycle", "the active
+// initiatives". A saved view built on it follows the cycles as they roll over. An
+// issue matches both its own id and the status it is in.
+export function statusValue(status: string): string {
+ return `status:${status}`;
+}
+
export function parseCustomFieldKey(field: string): number | null {
return field.startsWith('cf:') ? Number(field.slice(3)) : null;
}
@@ -60,7 +70,7 @@ export function isActiveFilterSet(filters: FilterSet | null | undefined): boolea
// Whether a condition actually constrains the result. Presence operators
// (is_set/is_not_set) need no value; every other operator needs at least one.
-function isEffectiveCondition(cond: FilterCondition): boolean {
+export function isEffectiveCondition(cond: FilterCondition): boolean {
if (cond.op === 'is_set' || cond.op === 'is_not_set') return true;
return cond.values.length > 0;
}
@@ -96,6 +106,12 @@ function builtinSetValues(
return [issue.priority];
case 'type':
return [issue.typeId];
+ case 'initiative':
+ return issue.initiative
+ ? [issue.initiative.id, statusValue(issue.initiative.status)]
+ : [null];
+ case 'cycle':
+ return issue.cycle ? [issue.cycle.id, statusValue(issue.cycle.status)] : [null];
case 'labels':
return issue.labelIds.length ? issue.labelIds : [null];
default:
@@ -136,7 +152,9 @@ function customFieldScalar(issue: Issue, fieldId: number): FilterValue {
return entry ? entry.value : null;
}
-function hasValue(values: FilterValue[]): boolean {
+// Whether a set of values counts as present for is_set/is_not_set: a null or an
+// empty string is what an unset field reads as.
+export function hasValue(values: FilterValue[]): boolean {
return values.some((v) => v !== null && v !== '');
}
diff --git a/apps/web/src/utils/initiativeMeta.ts b/apps/web/src/utils/initiativeMeta.ts
index 28db3d93..f4a610d0 100644
--- a/apps/web/src/utils/initiativeMeta.ts
+++ b/apps/web/src/utils/initiativeMeta.ts
@@ -33,6 +33,18 @@ export const GROUP_STATUS_ORDER: InitiativeStatus[] = [
'canceled',
];
+// Orders the initiatives a board lists as lanes and a filter offers as values: by
+// GROUP_STATUS_ORDER, by title within one status.
+export function compareByGroupOrder(
+ a: { status: InitiativeStatus; title: string },
+ b: { status: InitiativeStatus; title: string },
+): number {
+ return (
+ GROUP_STATUS_ORDER.indexOf(a.status) - GROUP_STATUS_ORDER.indexOf(b.status) ||
+ a.title.localeCompare(b.title)
+ );
+}
+
// Health (computed server-side). null means there is nothing to judge yet, and
// carries the muted color of an unknown value.
export const HEALTH_META: Record<InitiativeHealth, { color: string }> = {
diff --git a/apps/web/src/utils/project.ts b/apps/web/src/utils/project.ts
index 85611bdb..6aaec4c0 100644
--- a/apps/web/src/utils/project.ts
+++ b/apps/web/src/utils/project.ts
@@ -17,7 +17,15 @@ import type {
} from '@/lib/api';
import { CYCLE_STATUS_META } from '@/utils/cycleMeta';
import { PRIORITY_ORDER, PRIORITY_RANK } from '@/utils/fieldOptions';
-import { GROUP_STATUS_ORDER } from '@/utils/initiativeMeta';
+import {
+ hasValue,
+ isEffectiveCondition,
+ statusValue,
+ type FilterCondition,
+ type FilterSet,
+ type FilterValue,
+} from '@/utils/filters';
+import { compareByGroupOrder } from '@/utils/initiativeMeta';
import type { GroupField, ViewSettings } from '@/utils/viewSettings';
import type { Sort } from '@/utils/viewTypes';
@@ -43,6 +51,9 @@ export const DEFAULT_COLOR = '#6b7280';
// are the active project+view's display settings (see lib/viewSettings).
export interface WorkItemsViewProps {
project: ProjectDetail;
+ // The conditions the project's issues were filtered by. The layouts re-read them
+ // to leave out the groups those conditions exclude (see buildGroups).
+ filters: FilterSet;
// Custom field definitions applicable to this project (global + the project's
// type-scoped fields). The Table view renders enabled ones as columns.
customFields: CustomField[];
@@ -184,6 +195,10 @@ export interface IssueGroup {
color?: string;
stateType?: StateType; // status groups, for the state icon
assign: IssuePatch | null;
+ // What a filter condition on the grouping field matches this group by: the
+ // field's value, plus the status an initiative or a cycle is in. Read by
+ // buildGroups to drop the groups an active filter makes unreachable.
+ values: FilterValue[];
}
// The names a grouping needs beyond the project's own entities: the "No …" group
@@ -201,12 +216,19 @@ export interface GroupLabels {
// The groups for a project under the chosen grouping field, in display order.
// Every nullable field gets a "No …" group so an unset issue still has a home
-// (and a drop target that clears the field).
+// (and a drop target that clears the field). `filters` drops the groups its own
+// conditions exclude: a filter on the grouping field makes those unreachable — no
+// issue can show there and a drop into one would hide the card it moved.
export function buildGroups(
project: ProjectDetail,
group: GroupField,
labels: GroupLabels,
+ filters: FilterSet,
): IssueGroup[] {
+ return allowedGroups(allGroups(project, group, labels), group, filters);
+}
+
+function allGroups(project: ProjectDetail, group: GroupField, labels: GroupLabels): IssueGroup[] {
switch (group) {
case 'status':
return project.columns.map((c) => ({
@@ -215,6 +237,7 @@ export function buildGroups(
color: c.color,
stateType: c.stateType,
assign: { columnId: c.id },
+ values: [c.id],
}));
case 'assignee':
return [
@@ -224,8 +247,14 @@ export function buildGroups(
key: `a${a.userId}`,
name: a.name,
assign: { assigneeUserId: a.userId },
+ values: [a.userId],
})),
- { key: 'a-none', name: labels.noAssignee, assign: { assigneeUserId: null } },
+ {
+ key: 'a-none',
+ name: labels.noAssignee,
+ assign: { assigneeUserId: null },
+ values: [null],
+ },
];
case 'delegate':
return [
@@ -235,8 +264,14 @@ export function buildGroups(
key: `d${a.userId}`,
name: a.name,
assign: { delegateUserId: a.userId },
+ values: [a.userId],
})),
- { key: 'd-none', name: labels.noDelegate, assign: { delegateUserId: null } },
+ {
+ key: 'd-none',
+ name: labels.noDelegate,
+ assign: { delegateUserId: null },
+ values: [null],
+ },
];
case 'priority':
return [
@@ -244,8 +279,9 @@ export function buildGroups(
key: `p${value}`,
name: labels.priority(value),
assign: { priority: value },
+ values: [value],
})),
- { key: 'p-none', name: labels.noPriority, assign: { priority: null } },
+ { key: 'p-none', name: labels.noPriority, assign: { priority: null }, values: [null] },
];
case 'type':
return [
@@ -254,8 +290,9 @@ export function buildGroups(
name: t.name,
color: t.color,
assign: { typeId: t.id },
+ values: [t.id],
})),
- { key: 't-none', name: labels.noType, assign: { typeId: null } },
+ { key: 't-none', name: labels.noType, assign: { typeId: null }, values: [null] },
];
case 'initiative': {
// Lanes come from the initiatives the loaded issues are linked to (each issue
@@ -265,15 +302,19 @@ export function buildGroups(
const seen = new Map<number, InitiativeRef>();
for (const issue of project.issues)
if (issue.initiative) seen.set(issue.initiative.id, issue.initiative);
- const options = [...seen.values()]
- .sort(
- (a, b) =>
- GROUP_STATUS_ORDER.indexOf(a.status) - GROUP_STATUS_ORDER.indexOf(b.status) ||
- a.title.localeCompare(b.title),
- )
- .map((i) => ({ key: `i${i.id}`, name: i.title, assign: { initiativeId: i.id } }));
+ const options = [...seen.values()].sort(compareByGroupOrder).map((i) => ({
+ key: `i${i.id}`,
+ name: i.title,
+ assign: { initiativeId: i.id },
+ values: [i.id, statusValue(i.status)],
+ }));
return [
- { key: 'i-none', name: labels.noInitiative, assign: { initiativeId: null } },
+ {
+ key: 'i-none',
+ name: labels.noInitiative,
+ assign: { initiativeId: null },
+ values: [null],
+ },
...options,
];
}
@@ -294,20 +335,51 @@ export function buildGroups(
...project.plannedCycles.filter((c) => c.status !== 'upcoming'),
];
return [
- { key: 'y-none', name: labels.noCycle, assign: { cycleId: null } },
+ { key: 'y-none', name: labels.noCycle, assign: { cycleId: null }, values: [null] },
...upcomingFirst.map((c) => ({
key: `y${c.id}`,
name: c.name,
color: CYCLE_STATUS_META[c.status].color,
assign: { cycleId: c.id },
+ values: [c.id, statusValue(c.status)],
})),
...[...namedByIssues.entries()]
.sort((a, b) => a[1].localeCompare(b[1]))
- .map(([id, name]) => ({ key: `y${id}`, name, assign: null })),
+ .map(([id, name]) => ({
+ key: `y${id}`,
+ name,
+ assign: null,
+ values: [id, statusValue('completed')],
+ })),
];
}
case 'none':
- return [{ key: 'all', name: '', assign: null }];
+ return [{ key: 'all', name: '', assign: null, values: [] }];
+ }
+}
+
+// The groups an active filter still lets an issue reach. Only the conditions on
+// the grouping field itself narrow it: the rest decide which issues show, not
+// which groups exist. Operators that read a date or a text never apply to a
+// grouping field, so they leave the groups alone.
+function allowedGroups(groups: IssueGroup[], group: GroupField, filters: FilterSet): IssueGroup[] {
+ const conditions = filters.conditions.filter((c) => c.field === group && isEffectiveCondition(c));
+ if (conditions.length === 0) return groups;
+ return groups.filter((g) => conditions.every((c) => groupMatches(g, c)));
+}
+
+function groupMatches(group: IssueGroup, cond: FilterCondition): boolean {
+ switch (cond.op) {
+ case 'is':
+ return group.values.some((v) => cond.values.includes(v));
+ case 'is_not':
+ return !group.values.some((v) => cond.values.includes(v));
+ case 'is_set':
+ return hasValue(group.values);
+ case 'is_not_set':
+ return !hasValue(group.values);
+ default:
+ return true;
}
}
@@ -335,8 +407,9 @@ export function groupKeyOf(issue: Issue, group: GroupField): string {
}
// Issues bucketed by group key, preserving order. The map always has an (empty)
-// entry for every group in `groups`; a issue whose key is not among them (only
-// possible if the project data is inconsistent) is dropped.
+// entry for every group in `groups`; a issue whose key is not among them is
+// dropped — `groups` comes from buildGroups under the same filters the issues
+// passed, so that means a group the filter excludes.
export function groupIssues<T extends Issue>(
groups: IssueGroup[],
issues: T[],