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(web): create an initiative from the issue's initiative picker (#322)

Croff0f128e7f4165
diff --git a/apps/web/messages/ar/initiatives.json b/apps/web/messages/ar/initiatives.json
index 05701983..6994cb33 100644
--- a/apps/web/messages/ar/initiatives.json
+++ b/apps/web/messages/ar/initiatives.json
@@ -109,7 +109,8 @@
"label": "المبادرة",
"search": "الربط بمبادرة…",
"empty": "لا توجد مبادرات.",
- "none": "بلا مبادرة"
+ "none": "بلا مبادرة",
+ "create": "إنشاء مبادرة"
},
"feed": {
"system": "النظام",
diff --git a/apps/web/messages/en/initiatives.json b/apps/web/messages/en/initiatives.json
index b18ef5a5..1326af62 100644
--- a/apps/web/messages/en/initiatives.json
+++ b/apps/web/messages/en/initiatives.json
@@ -109,7 +109,8 @@
"label": "Initiative",
"search": "Link to initiative…",
"empty": "No initiatives.",
- "none": "No initiative"
+ "none": "No initiative",
+ "create": "Create initiative"
},
"feed": {
"system": "System",
diff --git a/apps/web/messages/fr/initiatives.json b/apps/web/messages/fr/initiatives.json
index 3cc36f43..5c393a0a 100644
--- a/apps/web/messages/fr/initiatives.json
+++ b/apps/web/messages/fr/initiatives.json
@@ -109,7 +109,8 @@
"label": "Initiative",
"search": "Lier à une initiative…",
"empty": "Aucune initiative.",
- "none": "Aucune initiative"
+ "none": "Aucune initiative",
+ "create": "Créer une initiative"
},
"feed": {
"system": "Système",
diff --git a/apps/web/messages/ru/initiatives.json b/apps/web/messages/ru/initiatives.json
index 0f06cbfc..85147bb5 100644
--- a/apps/web/messages/ru/initiatives.json
+++ b/apps/web/messages/ru/initiatives.json
@@ -109,7 +109,8 @@
"label": "Инициатива",
"search": "Привязать к инициативе…",
"empty": "Инициатив нет.",
- "none": "Без инициативы"
+ "none": "Без инициативы",
+ "create": "Создать инициативу"
},
"feed": {
"system": "Система",
diff --git a/apps/web/messages/uk/initiatives.json b/apps/web/messages/uk/initiatives.json
index 638d6852..b4aa5dfd 100644
--- a/apps/web/messages/uk/initiatives.json
+++ b/apps/web/messages/uk/initiatives.json
@@ -109,7 +109,8 @@
"label": "Ініціатива",
"search": "Прив'язати до ініціативи…",
"empty": "Ініціатив немає.",
- "none": "Без ініціативи"
+ "none": "Без ініціативи",
+ "create": "Створити ініціативу"
},
"feed": {
"system": "Система",
diff --git a/apps/web/messages/zh-CN/initiatives.json b/apps/web/messages/zh-CN/initiatives.json
index d5fe184e..ee252042 100644
--- a/apps/web/messages/zh-CN/initiatives.json
+++ b/apps/web/messages/zh-CN/initiatives.json
@@ -109,7 +109,8 @@
"label": "计划",
"search": "关联计划…",
"empty": "暂无计划。",
- "none": "无计划"
+ "none": "无计划",
+ "create": "新建计划"
},
"feed": {
"system": "系统",
diff --git a/apps/web/src/features/initiatives/components/list/CreateInitiativeDialog.tsx b/apps/web/src/components/common/overlay/CreateInitiativeDialog.tsx
similarity index 85%
rename from apps/web/src/features/initiatives/components/list/CreateInitiativeDialog.tsx
rename to apps/web/src/components/common/overlay/CreateInitiativeDialog.tsx
index b22b8085..5d7c7592 100644
--- a/apps/web/src/features/initiatives/components/list/CreateInitiativeDialog.tsx
+++ b/apps/web/src/components/common/overlay/CreateInitiativeDialog.tsx
@@ -3,21 +3,23 @@ import { useRouter } from 'next/navigation';
import { useTranslations } from 'next-intl';
import { initiativePath } from '@/utils/paths';
import { useCreateInitiative } from '@/services/initiatives.service';
-import Modal from '@/components/common/overlay/Modal';
+import Modal from './Modal';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
-// Creates an initiative from a title and optional description, then opens its
-// detail page. The remaining fields (owner, priority, target date, labels) are
-// set there.
+// Creates an initiative from a title and optional description; the remaining fields
+// (owner, priority, target date, labels) are set on its detail page. Without
+// onCreated the dialog navigates there.
export default function CreateInitiativeDialog({
projectKey,
onClose,
+ onCreated,
}: {
projectKey: string;
onClose: () => void;
+ onCreated?: (id: number) => void;
}) {
const t = useTranslations('initiatives');
const tCommon = useTranslations('common');
@@ -31,7 +33,8 @@ export default function CreateInitiativeDialog({
if (!name) return;
const created = await create.mutateAsync({ title: name, description: description.trim() });
onClose();
- router.push(initiativePath(projectKey, created.id));
+ if (onCreated) onCreated(created.id);
+ else router.push(initiativePath(projectKey, created.id));
};
return (
diff --git a/apps/web/src/features/initiatives/InitiativesPage.tsx b/apps/web/src/features/initiatives/InitiativesPage.tsx
index d356463e..0b3e199c 100644
--- a/apps/web/src/features/initiatives/InitiativesPage.tsx
+++ b/apps/web/src/features/initiatives/InitiativesPage.tsx
@@ -16,7 +16,7 @@ import { Button } from '@/components/ui/button';
import { Tabs, TabsList } from '@/components/ui/tabs';
import InitiativesList from './components/list/InitiativesList';
import InitiativesPagination from './components/list/InitiativesPagination';
-import CreateInitiativeDialog from './components/list/CreateInitiativeDialog';
+import CreateInitiativeDialog from '@/components/common/overlay/CreateInitiativeDialog';
import InitiativeTabTrigger from './components/list/InitiativeTabTrigger';
import { useInitiativeTabOrder } from './hooks/useInitiativeTabOrder';
import { INITIATIVE_TABS, tabCount } from './utils/tabs';
diff --git a/apps/web/src/features/issue/components/fields/InitiativeSelect.tsx b/apps/web/src/features/issue/components/fields/InitiativeSelect.tsx
index 6eff34eb..6eceeb03 100644
--- a/apps/web/src/features/issue/components/fields/InitiativeSelect.tsx
+++ b/apps/web/src/features/issue/components/fields/InitiativeSelect.tsx
@@ -1,7 +1,9 @@
import { useState } from 'react';
-import { Check, CircleDashed, Target } from 'lucide-react';
+import { Check, CircleDashed, Plus, Target } from 'lucide-react';
import { useTranslations } from 'next-intl';
+import { usePermissions } from '@/hooks/usePermissions';
import { useInitiativeOptionsQuery } from '@/services/initiatives.service';
+import CreateInitiativeDialog from '@/components/common/overlay/CreateInitiativeDialog';
import { colorDot } from '@/components/common/fields/colorDot';
import { STATUS_META } from '@/utils/initiativeMeta';
import {
@@ -16,8 +18,7 @@ import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover
import { Pill } from '@/components/common/fields/Pill';
// A Pill trigger opening the project's initiatives, for linking an issue to one.
-// Lives in the shared layer so the issue detail can use it without depending on
-// the initiatives feature. Value is the initiative id or null.
+// Value is the initiative id or null.
export default function InitiativeSelect({
projectKey,
value,
@@ -28,7 +29,9 @@ export default function InitiativeSelect({
onChange: (id: number | null) => void;
}) {
const t = useTranslations('initiatives.select');
+ const { can } = usePermissions();
const [open, setOpen] = useState(false);
+ const [creating, setCreating] = useState(false);
const [query, setQuery] = useState('');
// The linked initiative is asked for by id alongside the search, so it labels the
@@ -46,43 +49,68 @@ export default function InitiativeSelect({
};
return (
- <Popover
- open={open}
- onOpenChange={(next) => {
- setOpen(next);
- if (!next) setQuery('');
- }}
- >
- <PopoverTrigger asChild>
- <Pill active={value != null}>
- {value != null ? <Target /> : <CircleDashed />}
- <span className="truncate">{current?.title ?? t('label')}</span>
- </Pill>
- </PopoverTrigger>
- <PopoverContent className="w-56 p-0" align="start">
- <Command shouldFilter={false}>
- <CommandInput placeholder={t('search')} value={query} onValueChange={setQuery} />
- <CommandList>
- <CommandEmpty>{t('empty')}</CommandEmpty>
- <CommandGroup>
- {!query && (
- <CommandItem value={t('none')} onSelect={() => select(null)}>
- <CircleDashed />
- <span className="flex-1">{t('none')}</span>
- {value == null && <Check className="ml-auto" />}
- </CommandItem>
- )}
- {options.map((it) => (
- <CommandItem key={it.id} value={it.title} onSelect={() => select(it.id)}>
- {colorDot(STATUS_META[it.status].color)}
- <span className="flex-1 truncate">{it.title}</span>
- {it.id === value && <Check className="ml-auto" />}
- </CommandItem>
- ))}
- </CommandGroup>
- </CommandList>
- </Command>
- </PopoverContent>
- </Popover>
+ <>
+ <Popover
+ open={open}
+ onOpenChange={(next) => {
+ setOpen(next);
+ if (!next) setQuery('');
+ }}
+ >
+ <PopoverTrigger asChild>
+ <Pill active={value != null}>
+ {value != null ? <Target /> : <CircleDashed />}
+ <span className="truncate">{current?.title ?? t('label')}</span>
+ </Pill>
+ </PopoverTrigger>
+ <PopoverContent className="w-56 p-0" align="start">
+ <Command shouldFilter={false}>
+ <CommandInput placeholder={t('search')} value={query} onValueChange={setQuery} />
+ {/* Outside CommandList: cmdk counts every rendered item, so an
+ always-present row would keep CommandEmpty from ever showing. */}
+ {can('initiatives', 'create') && (
+ <button
+ type="button"
+ className="flex w-full items-center gap-2 border-b px-3 py-2 text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground"
+ onClick={() => {
+ setOpen(false);
+ setCreating(true);
+ }}
+ >
+ <Plus className="size-4" />
+ {t('create')}
+ </button>
+ )}
+ <CommandList>
+ <CommandEmpty>{t('empty')}</CommandEmpty>
+ <CommandGroup>
+ {!query && (
+ <CommandItem value={t('none')} onSelect={() => select(null)}>
+ <CircleDashed />
+ <span className="flex-1">{t('none')}</span>
+ {value == null && <Check className="ml-auto" />}
+ </CommandItem>
+ )}
+ {options.map((it) => (
+ <CommandItem key={it.id} value={it.title} onSelect={() => select(it.id)}>
+ {colorDot(STATUS_META[it.status].color)}
+ <span className="flex-1 truncate">{it.title}</span>
+ {it.id === value && <Check className="ml-auto" />}
+ </CommandItem>
+ ))}
+ </CommandGroup>
+ </CommandList>
+ </Command>
+ </PopoverContent>
+ </Popover>
+
+ {creating && (
+ <CreateInitiativeDialog
+ projectKey={projectKey}
+ onClose={() => setCreating(false)}
+ onCreated={onChange}
+ />
+ )}
+ </>
);
}