From ca6e5edcf853f204aba8995a00cde89f79f285d5 Mon Sep 17 00:00:00 2001 From: Denis Bunakalya Date: Tue, 11 Oct 2022 09:39:26 +0300 Subject: [PATCH] tsk-187 Duplicate issue from context menu (#2292) Signed-off-by: Denis Bunakalya --- models/tracker/src/index.ts | 26 +++++++ plugins/tracker-assets/assets/icons.svg | 3 + plugins/tracker-assets/lang/en.json | 1 + plugins/tracker-assets/lang/ru.json | 1 + plugins/tracker-assets/src/index.ts | 1 + .../src/components/CreateIssue.svelte | 72 +++++++++++++------ plugins/tracker-resources/src/plugin.ts | 1 + plugins/tracker/src/index.ts | 2 + 8 files changed, 86 insertions(+), 21 deletions(-) diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index 6402b40bae..f78ed37046 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -1230,6 +1230,32 @@ export function createModel (builder: Builder): void { }, tracker.action.Relations ) + createAction( + builder, + { + action: view.actionImpl.ShowPopup, + actionProps: { + component: tracker.component.CreateIssue, + element: 'top', + fillProps: { + _object: 'originalIssue', + space: 'space' + } + }, + label: tracker.string.Duplicate, + icon: tracker.icon.Duplicate, + keyBinding: [], + input: 'none', + category: tracker.category.Tracker, + target: tracker.class.Issue, + context: { + mode: ['context', 'browser'], + application: tracker.app.Tracker, + group: 'associate' + } + }, + tracker.action.Duplicate + ) classPresenter( builder, diff --git a/plugins/tracker-assets/assets/icons.svg b/plugins/tracker-assets/assets/icons.svg index 796f2217d8..6c6793dc66 100644 --- a/plugins/tracker-assets/assets/icons.svg +++ b/plugins/tracker-assets/assets/icons.svg @@ -157,6 +157,9 @@ + + + diff --git a/plugins/tracker-assets/lang/en.json b/plugins/tracker-assets/lang/en.json index b730873fa0..1f59733f48 100644 --- a/plugins/tracker-assets/lang/en.json +++ b/plugins/tracker-assets/lang/en.json @@ -127,6 +127,7 @@ "ProjectMembersSearchPlaceholder": "Change project members\u2026", "Roadmap": "Roadmap", "MoveToTeam": "Move to team", + "Duplicate": "Duplicate", "GotoIssues": "Go to issues", "GotoActive": "Go to active issues", diff --git a/plugins/tracker-assets/lang/ru.json b/plugins/tracker-assets/lang/ru.json index 81dd13ad9c..4e66270a13 100644 --- a/plugins/tracker-assets/lang/ru.json +++ b/plugins/tracker-assets/lang/ru.json @@ -127,6 +127,7 @@ "ProjectMembersSearchPlaceholder": "Измененить участников проекта\u2026", "Roadmap": "Планирование", "MoveToTeam": "Изменить команду", + "Duplicate": "Дублировать", "GotoIssues": "Перейти к задачам", "GotoActive": "Перейти к активным задачам", diff --git a/plugins/tracker-assets/src/index.ts b/plugins/tracker-assets/src/index.ts index e99531cad1..c3be3fc500 100644 --- a/plugins/tracker-assets/src/index.ts +++ b/plugins/tracker-assets/src/index.ts @@ -67,6 +67,7 @@ loadMetadata(tracker.icon, { CopyID: `${icons}#copyID`, CopyURL: `${icons}#copyURL`, CopyBranch: `${icons}#copyBranch`, + Duplicate: `${icons}#duplicate`, TimeReport: `${icons}#timeReport`, Estimation: `${icons}#timeReport` }) diff --git a/plugins/tracker-resources/src/components/CreateIssue.svelte b/plugins/tracker-resources/src/components/CreateIssue.svelte index eebae157d3..3e25f014bb 100644 --- a/plugins/tracker-resources/src/components/CreateIssue.svelte +++ b/plugins/tracker-resources/src/components/CreateIssue.svelte @@ -70,28 +70,40 @@ let issueStatuses: WithLookup[] | undefined export let parentIssue: Issue | undefined + export let originalIssue: Issue | undefined let labels: TagReference[] = [] let objectId: Ref = generateId() - let object: AttachedData = { - title: '', - description: '', - assignee: assignee, - project: project, - sprint: sprint, - number: 0, - rank: '', - status: '' as Ref, - priority: priority, - dueDate: null, - comments: 0, - subIssues: 0, - parents: [], - reportedTime: 0, - estimation: 0, - reports: 0, - childInfo: [] - } + + let object: AttachedData = originalIssue + ? { + ...originalIssue, + title: `${originalIssue.title} (copy)`, + subIssues: 0, + attachments: 0, + reportedTime: 0, + reports: 0, + childInfo: [] + } + : { + title: '', + description: '', + assignee: assignee, + project: project, + sprint: sprint, + number: 0, + rank: '', + status: '' as Ref, + priority: priority, + dueDate: null, + comments: 0, + subIssues: 0, + parents: [], + reportedTime: 0, + estimation: 0, + reports: 0, + childInfo: [] + } function resetObject (): void { templateId = undefined @@ -187,7 +199,7 @@ } $: _space = space - $: updateIssueStatusId(_space, status) + $: !originalIssue && updateIssueStatusId(_space, status) $: canSave = getTitle(object.title ?? '').length > 0 $: statusesQuery.query( @@ -202,6 +214,24 @@ } ) + async function setPropsFromOriginalIssue () { + if (!originalIssue) { + return + } + const { _id, relations, parents } = originalIssue + + if (relations?.[0]) { + relatedTo = await client.findOne(tracker.class.Issue, { _id: relations[0]._id as Ref }) + } + if (parents?.[0]) { + parentIssue = await client.findOne(tracker.class.Issue, { _id: parents[0].parentId }) + } + if (originalIssue.labels) { + labels = await client.findAll(tags.class.TagReference, { attachedTo: _id }) + } + } + $: originalIssue && setPropsFromOriginalIssue() + async function updateIssueStatusId (teamId: Ref, issueStatusId?: Ref) { if (issueStatusId !== undefined) { object.status = issueStatusId @@ -571,7 +601,7 @@ {#if object.dueDate !== null} diff --git a/plugins/tracker-resources/src/plugin.ts b/plugins/tracker-resources/src/plugin.ts index fca4e5f01e..900a4bc0cb 100644 --- a/plugins/tracker-resources/src/plugin.ts +++ b/plugins/tracker-resources/src/plugin.ts @@ -153,6 +153,7 @@ export default mergeIds(trackerId, tracker, { NumberLabels: '' as IntlString, Roadmap: '' as IntlString, MoveToTeam: '' as IntlString, + Duplicate: '' as IntlString, IssueTitlePlaceholder: '' as IntlString, IssueDescriptionPlaceholder: '' as IntlString, diff --git a/plugins/tracker/src/index.ts b/plugins/tracker/src/index.ts index a6d5def902..207fa5f991 100644 --- a/plugins/tracker/src/index.ts +++ b/plugins/tracker/src/index.ts @@ -405,6 +405,7 @@ export default plugin(trackerId, { CopyID: '' as Asset, CopyURL: '' as Asset, CopyBranch: '' as Asset, + Duplicate: '' as Asset, TimeReport: '' as Asset, Estimation: '' as Asset @@ -424,6 +425,7 @@ export default plugin(trackerId, { CopyIssueTitle: '' as Ref, CopyIssueLink: '' as Ref, MoveToTeam: '' as Ref, + Duplicate: '' as Ref, Relations: '' as Ref, NewSubIssue: '' as Ref, EditWorkflowStatuses: '' as Ref,