Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions models/recruit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions models/recruit/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default mergeIds(recruitId, recruit, {
},
function: {
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>>
},
string: {
Expand Down
4 changes: 3 additions & 1 deletion plugins/recruit-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import VacancyTemplateEditor from './components/VacancyTemplateEditor.svelte'
import recruit from './plugin'
import {
getAppTitle,
getCandidateLink,
getRevTitle,
getSequenceId,
getSequenceLink,
Expand Down Expand Up @@ -336,7 +337,8 @@ export default async (): Promise<Resources> => ({
HasNoActiveApplicant: hasNoActiveApplicant,
NoneApplications: noneApplicant,
GetObjectLink: objectLinkProvider,
GetObjectLinkFragment: getSequenceLink
GetObjectLinkFragment: getSequenceLink,
GetCandidateLinkFragment: getCandidateLink
},
resolver: {
Location: resolveLocation
Expand Down
44 changes: 42 additions & 2 deletions plugins/recruit-resources/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -31,9 +31,38 @@ export async function resolveLocation (loc: Location): Promise<ResolvedLocation
// shortlink
if (isShortId(shortLink)) {
return await generateLocation(loc, shortLink)
} else {
return await generateCandidateLink(loc, shortLink)
}
}

async function generateCandidateLink (loc: Location, _id: string): Promise<ResolvedLocation | undefined> {
const client = getClient()
const hierarchy = client.getHierarchy()

return undefined
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> {
Expand Down Expand Up @@ -97,6 +126,17 @@ export async function getSequenceLink (doc: RecruitDocument): Promise<Location>
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> (
client: Client,
ref: Ref<T>,
Expand Down
2 changes: 1 addition & 1 deletion plugins/view-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ export async function getObjectLinkFragment (
props: Record<string, any> = {},
component: AnyComponent = view.component.EditDoc
): 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) {
const f = await getResource(provider.encode)
const res = await f(object, props)
Expand Down