Candidate link resolver (#3003)

This commit is contained in:
Denis Bykhov 2023-04-17 20:52:56 +06:00 committed by GitHub
parent 359c1a81bc
commit 7f68032397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 4 deletions

View File

@ -747,6 +747,10 @@ export function createModel (builder: Builder): void {
encode: recruit.function.GetObjectLinkFragment encode: recruit.function.GetObjectLinkFragment
}) })
builder.mixin(recruit.mixin.Candidate, core.class.Class, view.mixin.LinkProvider, {
encode: recruit.function.GetCandidateLinkFragment
})
builder.createDoc( builder.createDoc(
view.class.ActionCategory, view.class.ActionCategory,
core.space.Model, core.space.Model,

View File

@ -40,6 +40,7 @@ export default mergeIds(recruitId, recruit, {
}, },
function: { function: {
GetObjectLinkFragment: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>, GetObjectLinkFragment: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
GetCandidateLinkFragment: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
GetObjectLink: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<string>> GetObjectLink: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<string>>
}, },
string: { string: {

View File

@ -65,6 +65,7 @@ import VacancyTemplateEditor from './components/VacancyTemplateEditor.svelte'
import recruit from './plugin' import recruit from './plugin'
import { import {
getAppTitle, getAppTitle,
getCandidateLink,
getRevTitle, getRevTitle,
getSequenceId, getSequenceId,
getSequenceLink, getSequenceLink,
@ -336,7 +337,8 @@ export default async (): Promise<Resources> => ({
HasNoActiveApplicant: hasNoActiveApplicant, HasNoActiveApplicant: hasNoActiveApplicant,
NoneApplications: noneApplicant, NoneApplications: noneApplicant,
GetObjectLink: objectLinkProvider, GetObjectLink: objectLinkProvider,
GetObjectLinkFragment: getSequenceLink GetObjectLinkFragment: getSequenceLink,
GetCandidateLinkFragment: getCandidateLink
}, },
resolver: { resolver: {
Location: resolveLocation Location: resolveLocation

View File

@ -1,6 +1,6 @@
import { Class, Client, Doc, Ref } from '@hcengineering/core' import { Class, Client, Doc, Ref } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation' 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 { getCurrentLocation, getPanelURI, Location, ResolvedLocation } from '@hcengineering/ui'
import view from '@hcengineering/view' import view from '@hcengineering/view'
import { workbenchId } from '@hcengineering/workbench' import { workbenchId } from '@hcengineering/workbench'
@ -31,9 +31,38 @@ export async function resolveLocation (loc: Location): Promise<ResolvedLocation
// shortlink // shortlink
if (isShortId(shortLink)) { if (isShortId(shortLink)) {
return await generateLocation(loc, shortLink) return await generateLocation(loc, shortLink)
} else {
return await generateCandidateLink(loc, shortLink)
} }
}
return undefined async function generateCandidateLink (loc: Location, _id: string): Promise<ResolvedLocation | undefined> {
const client = getClient()
const hierarchy = client.getHierarchy()
const doc = await client.findOne(recruit.mixin.Candidate, { _id: _id as Ref<Candidate> })
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<ResolvedLocation | undefined> { async function generateLocation (loc: Location, shortLink: string): Promise<ResolvedLocation | undefined> {
@ -97,6 +126,17 @@ export async function getSequenceLink (doc: RecruitDocument): Promise<Location>
return loc return loc
} }
export async function getCandidateLink (doc: Candidate): Promise<Location> {
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<T extends RecruitDocument> ( async function getTitle<T extends RecruitDocument> (
client: Client, client: Client,
ref: Ref<T>, ref: Ref<T>,

View File

@ -843,7 +843,7 @@ export async function getObjectLinkFragment (
props: Record<string, any> = {}, props: Record<string, any> = {},
component: AnyComponent = view.component.EditDoc component: AnyComponent = view.component.EditDoc
): Promise<Location> { ): Promise<Location> {
const provider = hierarchy.classHierarchyMixin(object._class, view.mixin.LinkProvider) const provider = hierarchy.classHierarchyMixin(Hierarchy.mixinOrClass(object), view.mixin.LinkProvider)
if (provider?.encode !== undefined) { if (provider?.encode !== undefined) {
const f = await getResource(provider.encode) const f = await getResource(provider.encode)
const res = await f(object, props) const res = await f(object, props)