From 2d5a38eed5ac984c9921b047a26174b8c85ffba1 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Fri, 8 Sep 2023 11:33:23 +0700 Subject: [PATCH] UBER-807: Allow to customize create issue dialog (#3669) Signed-off-by: Andrey Sobolev --- models/tracker/src/index.ts | 19 +++++- packages/core/src/hierarchy.ts | 18 ++++++ packages/core/src/operations.ts | 2 +- .../src/components/MergePersons.svelte | 2 +- .../src/components/CreateIssue.svelte | 62 +++++++++++++++++-- .../issues/edit/ControlPanel.svelte | 10 ++- plugins/tracker/src/index.ts | 33 ++++++++++ .../src/components/HyperlinkEditor.svelte | 9 ++- .../components/HyperlinkEditorPopup.svelte | 27 ++++---- plugins/view-resources/src/index.ts | 3 +- 10 files changed, 158 insertions(+), 27 deletions(-) diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index 25e07f175e..1ab8837b14 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -34,6 +34,7 @@ import { Collection, Hidden, Index, + Mixin, Model, Prop, ReadOnly, @@ -46,12 +47,12 @@ import { } from '@hcengineering/model' import attachment from '@hcengineering/model-attachment' import chunter from '@hcengineering/model-chunter' -import core, { TAttachedDoc, TDoc, TStatus, TType } from '@hcengineering/model-core' +import core, { TAttachedDoc, TClass, TDoc, TStatus, TType } from '@hcengineering/model-core' import task, { TSpaceWithStates, TTask } from '@hcengineering/model-task' import view, { actionTemplates, classPresenter, createAction, showColorsViewOption } from '@hcengineering/model-view' import workbench, { createNavigateAction } from '@hcengineering/model-workbench' import notification from '@hcengineering/notification' -import { IntlString } from '@hcengineering/platform' +import { IntlString, Resource } from '@hcengineering/platform' import setting from '@hcengineering/setting' import tags, { TagElement } from '@hcengineering/tags' import { DoneState } from '@hcengineering/task' @@ -64,9 +65,11 @@ import { IssueStatus, IssueTemplate, IssueTemplateChild, + IssueUpdateFunction, Milestone, MilestoneStatus, Project, + ProjectIssueTargetOptions, TimeReportDayType, TimeSpendReport, trackerId @@ -77,6 +80,7 @@ import tracker from './plugin' import { generateClassNotificationTypes } from '@hcengineering/model-notification' import presentation from '@hcengineering/model-presentation' import { defaultPriorities, issuePriorities } from '@hcengineering/tracker-resources/src/types' +import { AnyComponent } from '@hcengineering/ui' import { PaletteColorIndexes } from '@hcengineering/ui/src/colors' export { trackerId } from '@hcengineering/tracker' @@ -336,6 +340,14 @@ export class TComponent extends TDoc implements Component { declare space: Ref } +@Mixin(tracker.mixin.ProjectIssueTargetOptions, core.class.Class) +export class TProjectIssueTargetOptions extends TClass implements ProjectIssueTargetOptions { + headerComponent!: AnyComponent + bodyComponent!: AnyComponent + footerComponent!: AnyComponent + + update!: Resource +} /** * @public */ @@ -410,7 +422,8 @@ export function createModel (builder: Builder): void { TMilestone, TTypeMilestoneStatus, TTimeSpendReport, - TTypeReportedTime + TTypeReportedTime, + TProjectIssueTargetOptions ) builder.createDoc( diff --git a/packages/core/src/hierarchy.ts b/packages/core/src/hierarchy.ts index b063495307..cefa99203c 100644 --- a/packages/core/src/hierarchy.ts +++ b/packages/core/src/hierarchy.ts @@ -92,6 +92,24 @@ export class Hierarchy { } } + findClassOrMixinMixin(doc: Doc, mixin: Ref>): M | undefined { + const cc = this.classHierarchyMixin(doc._class, mixin) + if (cc !== undefined) { + return cc + } + + const _doc = _toDoc(doc) + // Find all potential mixins of doc + for (const [k, v] of Object.entries(_doc)) { + if (typeof v === 'object' && this.classifiers.has(k as Ref)) { + const cc = this.classHierarchyMixin(k as Ref>, mixin) + if (cc !== undefined) { + return cc + } + } + } + } + isMixin (_class: Ref>): boolean { const data = this.classifiers.get(_class) return data !== undefined && this._isMixin(data) diff --git a/packages/core/src/operations.ts b/packages/core/src/operations.ts index 75daac4b3f..01ac8e2686 100644 --- a/packages/core/src/operations.ts +++ b/packages/core/src/operations.ts @@ -289,7 +289,7 @@ export class TxOperations implements Omit { continue } const dv = (doc as any)[k] - if (!deepEqual(dv, v) && v != null) { + if (!deepEqual(dv, v) && v !== undefined) { ;(documentUpdate as any)[k] = v } } diff --git a/plugins/contact-resources/src/components/MergePersons.svelte b/plugins/contact-resources/src/components/MergePersons.svelte index ea72563f2a..e12378c2e5 100644 --- a/plugins/contact-resources/src/components/MergePersons.svelte +++ b/plugins/contact-resources/src/components/MergePersons.svelte @@ -111,7 +111,7 @@ await client.update(targetPerson, update) } for (const channel of resultChannels.values()) { - if (channel.attachedTo !== targetPerson._id) continue + if (channel.attachedTo === targetPerson._id) continue await client.update(channel, { attachedTo: targetPerson._id }) } for (const old of oldChannels) { diff --git a/plugins/tracker-resources/src/components/CreateIssue.svelte b/plugins/tracker-resources/src/components/CreateIssue.svelte index ad3484a4de..044aa392bd 100644 --- a/plugins/tracker-resources/src/components/CreateIssue.svelte +++ b/plugins/tracker-resources/src/components/CreateIssue.svelte @@ -16,7 +16,7 @@ import { AttachmentStyledBox } from '@hcengineering/attachment-resources' import chunter from '@hcengineering/chunter' import { Employee } from '@hcengineering/contact' - import core, { Account, AttachedData, Doc, fillDefaults, generateId, Ref, SortingOrder } from '@hcengineering/core' + import core, { Account, DocData, Class, Doc, fillDefaults, generateId, Ref, SortingOrder } from '@hcengineering/core' import { getResource, translate } from '@hcengineering/platform' import { Card, @@ -38,7 +38,8 @@ IssueStatus, IssueTemplate, Milestone, - Project + Project, + ProjectIssueTargetOptions } from '@hcengineering/tracker' import { addNotification, @@ -299,6 +300,18 @@ currentProject = res.shift() }) + $: targetSettings = + currentProject !== undefined + ? client + .getHierarchy() + .findClassOrMixinMixin, ProjectIssueTargetOptions>( + currentProject, + tracker.mixin.ProjectIssueTargetOptions + ) + : undefined + + let targetSettingOptions: Record = {} + async function updateIssueStatusId (object: IssueDraft, currentProject: Project | undefined) { if (currentProject?.defaultIssueStatus && object.status === undefined) { object.status = currentProject.defaultIssueStatus @@ -340,7 +353,7 @@ } } - async function createIssue () { + async function createIssue (): Promise { const _id: Ref = generateId() if (!canSave || object.status === undefined) { return @@ -357,7 +370,7 @@ true ) - const value: AttachedData = { + const value: DocData = { doneState: null, title: getTitle(object.title), description: object.description, @@ -381,6 +394,11 @@ childInfo: [] } + if (targetSettings !== undefined) { + const updateOp = await getResource(targetSettings.update) + updateOp?.(_id, _space, value, targetSettingOptions) + } + await client.addCollection( tracker.class.Issue, _space, @@ -569,6 +587,15 @@ docProps={{ disabled: true, noUnderline: true }} focusIndex={20000} /> + {#if targetSettings?.headerComponent && currentProject} + { + targetSettingOptions = evt.detail + }} + /> + {/if}
@@ -649,6 +676,15 @@ component={object.component} bind:subIssues={object.subIssues} /> + {#if targetSettings?.bodyComponent && currentProject} + { + targetSettingOptions = evt.detail + }} + /> + {/if}
+ {#if targetSettings?.poolComponent && currentProject} + { + targetSettingOptions = evt.detail + }} + /> + {/if}
{#if attachments.size > 0} @@ -785,5 +830,14 @@ descriptionBox.attach() }} /> + {#if targetSettings?.footerComponent && currentProject} + { + targetSettingOptions = evt.detail + }} + /> + {/if} diff --git a/plugins/tracker-resources/src/components/issues/edit/ControlPanel.svelte b/plugins/tracker-resources/src/components/issues/edit/ControlPanel.svelte index 0b8cdfa78f..0d03d4414e 100644 --- a/plugins/tracker-resources/src/components/issues/edit/ControlPanel.svelte +++ b/plugins/tracker-resources/src/components/issues/edit/ControlPanel.svelte @@ -15,7 +15,7 @@ @@ -53,10 +54,14 @@ }} > - {#if value} + {#if title} + {title} + {:else if value} {value} {:else} - + + {/if} diff --git a/plugins/view-resources/src/components/HyperlinkEditorPopup.svelte b/plugins/view-resources/src/components/HyperlinkEditorPopup.svelte index 126c3a45d5..4f2904efa3 100644 --- a/plugins/view-resources/src/components/HyperlinkEditorPopup.svelte +++ b/plugins/view-resources/src/components/HyperlinkEditorPopup.svelte @@ -59,20 +59,20 @@ {/if}
-