From 7f680323979a3e7be0c563b72bd5f4b8d3b9dc1d Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Mon, 17 Apr 2023 20:52:56 +0600 Subject: [PATCH] Candidate link resolver (#3003) --- models/recruit/src/index.ts | 4 +++ models/recruit/src/plugin.ts | 1 + plugins/recruit-resources/src/index.ts | 4 ++- plugins/recruit-resources/src/utils.ts | 44 ++++++++++++++++++++++++-- plugins/view-resources/src/utils.ts | 2 +- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts index 16a532192a..80c1db53d4 100644 --- a/models/recruit/src/index.ts +++ b/models/recruit/src/index.ts @@ -747,6 +747,10 @@ export function createModel (builder: Builder): void { encode: recruit.function.GetObjectLinkFragment }) + builder.mixin(recruit.mixin.Candidate, core.class.Class, view.mixin.LinkProvider, { + encode: recruit.function.GetCandidateLinkFragment + }) + builder.createDoc( view.class.ActionCategory, core.space.Model, diff --git a/models/recruit/src/plugin.ts b/models/recruit/src/plugin.ts index dd7b816b83..ee7ded9172 100644 --- a/models/recruit/src/plugin.ts +++ b/models/recruit/src/plugin.ts @@ -40,6 +40,7 @@ export default mergeIds(recruitId, recruit, { }, function: { GetObjectLinkFragment: '' as Resource<(doc: Doc, props: Record) => Promise>, + GetCandidateLinkFragment: '' as Resource<(doc: Doc, props: Record) => Promise>, GetObjectLink: '' as Resource<(doc: Doc, props: Record) => Promise> }, string: { diff --git a/plugins/recruit-resources/src/index.ts b/plugins/recruit-resources/src/index.ts index b6f9ec6031..cba699f3eb 100644 --- a/plugins/recruit-resources/src/index.ts +++ b/plugins/recruit-resources/src/index.ts @@ -65,6 +65,7 @@ import VacancyTemplateEditor from './components/VacancyTemplateEditor.svelte' import recruit from './plugin' import { getAppTitle, + getCandidateLink, getRevTitle, getSequenceId, getSequenceLink, @@ -336,7 +337,8 @@ export default async (): Promise => ({ HasNoActiveApplicant: hasNoActiveApplicant, NoneApplications: noneApplicant, GetObjectLink: objectLinkProvider, - GetObjectLinkFragment: getSequenceLink + GetObjectLinkFragment: getSequenceLink, + GetCandidateLinkFragment: getCandidateLink }, resolver: { Location: resolveLocation diff --git a/plugins/recruit-resources/src/utils.ts b/plugins/recruit-resources/src/utils.ts index d375c80c4d..20dd585d8a 100644 --- a/plugins/recruit-resources/src/utils.ts +++ b/plugins/recruit-resources/src/utils.ts @@ -1,6 +1,6 @@ import { Class, Client, Doc, Ref } from '@hcengineering/core' import { getClient } from '@hcengineering/presentation' -import { Applicant, recruitId, Review, Vacancy } from '@hcengineering/recruit' +import { Applicant, Candidate, recruitId, Review, Vacancy } from '@hcengineering/recruit' import { getCurrentLocation, getPanelURI, Location, ResolvedLocation } from '@hcengineering/ui' import view from '@hcengineering/view' import { workbenchId } from '@hcengineering/workbench' @@ -31,9 +31,38 @@ export async function resolveLocation (loc: Location): Promise { + const client = getClient() + const hierarchy = client.getHierarchy() + + const doc = await client.findOne(recruit.mixin.Candidate, { _id: _id as Ref }) + if (doc === undefined) { + console.error(`Could not find candidate with id ${_id}.`) + return undefined + } + const appComponent = loc.path[0] ?? '' + const workspace = loc.path[1] ?? '' + const targetClass = hierarchy.getClass(recruit.mixin.Candidate) + const panelComponent = hierarchy.as(targetClass, view.mixin.ObjectPanel) + const component = panelComponent.component ?? view.component.EditDoc + const defaultPath = [appComponent, workspace, recruitId, 'talents'] + + return { + loc: { + path: [appComponent, workspace], + fragment: getPanelURI(component, doc._id, recruit.mixin.Candidate, 'content') + }, + shouldNavigate: false, + defaultLocation: { + path: defaultPath, + fragment: getPanelURI(component, doc._id, recruit.mixin.Candidate, 'content') + } + } } async function generateLocation (loc: Location, shortLink: string): Promise { @@ -97,6 +126,17 @@ export async function getSequenceLink (doc: RecruitDocument): Promise return loc } +export async function getCandidateLink (doc: Candidate): Promise { + const loc = getCurrentLocation() + loc.path.length = 2 + loc.fragment = undefined + loc.query = undefined + loc.path[2] = recruitId + loc.path[3] = doc._id + + return loc +} + async function getTitle ( client: Client, ref: Ref, diff --git a/plugins/view-resources/src/utils.ts b/plugins/view-resources/src/utils.ts index aa3a055f4b..5a183fb68d 100644 --- a/plugins/view-resources/src/utils.ts +++ b/plugins/view-resources/src/utils.ts @@ -843,7 +843,7 @@ export async function getObjectLinkFragment ( props: Record = {}, component: AnyComponent = view.component.EditDoc ): Promise { - const provider = hierarchy.classHierarchyMixin(object._class, view.mixin.LinkProvider) + const provider = hierarchy.classHierarchyMixin(Hierarchy.mixinOrClass(object), view.mixin.LinkProvider) if (provider?.encode !== undefined) { const f = await getResource(provider.encode) const res = await f(object, props)