TSK-1242 Short link for organization in recruit (#3008)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-04-18 15:02:34 +06:00 committed by GitHub
parent 5f0566bb9f
commit d5f1668532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 19 deletions

View File

@ -97,7 +97,7 @@ export class TVacancy extends TSpaceWithStates implements Vacancy {
export class TCandidates extends TSpace implements Candidates {}
@Mixin(recruit.mixin.Candidate, contact.class.Person)
@UX(recruit.string.Talent, recruit.icon.RecruitApplication, undefined, 'name')
@UX(recruit.string.Talent, recruit.icon.RecruitApplication, 'TLNT', 'name')
export class TCandidate extends TPerson implements Candidate {
@Prop(TypeString(), recruit.string.Title)
@Index(IndexKind.FullText)
@ -135,7 +135,7 @@ export class TCandidate extends TPerson implements Candidate {
}
@Mixin(recruit.mixin.VacancyList, contact.class.Organization)
@UX(recruit.string.VacancyList, recruit.icon.RecruitApplication, undefined, 'name')
@UX(recruit.string.VacancyList, recruit.icon.RecruitApplication, 'CM', 'name')
export class TVacancyList extends TOrganization implements VacancyList {
@Prop(Collection(recruit.class.Vacancy), recruit.string.Vacancies)
vacancies!: number
@ -748,7 +748,11 @@ export function createModel (builder: Builder): void {
})
builder.mixin(recruit.mixin.Candidate, core.class.Class, view.mixin.LinkProvider, {
encode: recruit.function.GetCandidateLinkFragment
encode: recruit.function.GetIdObjectLinkFragment
})
builder.mixin(recruit.mixin.VacancyList, core.class.Class, view.mixin.LinkProvider, {
encode: recruit.function.GetIdObjectLinkFragment
})
builder.createDoc(

View File

@ -40,7 +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>>,
GetIdObjectLinkFragment: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
GetObjectLink: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<string>>
},
string: {

View File

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

View File

@ -1,6 +1,6 @@
import { Class, Client, Doc, Ref } from '@hcengineering/core'
import { Class, Client, Doc, Hierarchy, Ref } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
import { Applicant, Candidate, recruitId, Review, Vacancy } from '@hcengineering/recruit'
import { Applicant, Candidate, recruitId, Review, Vacancy, VacancyList } from '@hcengineering/recruit'
import { getCurrentLocation, getPanelURI, Location, ResolvedLocation } from '@hcengineering/ui'
import view from '@hcengineering/view'
import { workbenchId } from '@hcengineering/workbench'
@ -31,18 +31,36 @@ export async function resolveLocation (loc: Location): Promise<ResolvedLocation
// shortlink
if (isShortId(shortLink)) {
return await generateLocation(loc, shortLink)
} else {
return await generateCandidateLink(loc, shortLink)
} else if (shortLink !== undefined) {
return await generateIdLocation(loc, shortLink)
}
}
async function generateCandidateLink (loc: Location, _id: string): Promise<ResolvedLocation | undefined> {
async function generateIdLocation (loc: Location, shortLink: string): Promise<ResolvedLocation | undefined> {
const tokens = shortLink.split('-')
if (tokens.length < 2) {
return undefined
}
const client = getClient()
const hierarchy = client.getHierarchy()
const doc = await client.findOne(recruit.mixin.Candidate, { _id: _id as Ref<Candidate> })
const classLabel = tokens[0]
const _id = tokens[1]
const classes = [recruit.mixin.VacancyList, recruit.mixin.Candidate]
let _class: Ref<Class<Doc>> | undefined
for (const clazz of classes) {
if (hierarchy.getClass(clazz).shortLabel === classLabel) {
_class = clazz
break
}
}
if (_class === undefined) {
console.error(`Not found class with short label ${classLabel}`)
return undefined
}
const doc = await client.findOne(_class, { _id: _id as Ref<Doc> })
if (doc === undefined) {
console.error(`Could not find candidate with id ${_id}.`)
console.error(`Could not find ${_class} with id ${_id}.`)
return undefined
}
const appComponent = loc.path[0] ?? ''
@ -50,17 +68,18 @@ async function generateCandidateLink (loc: Location, _id: string): Promise<Resol
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']
const special = _class === recruit.mixin.Candidate ? 'talents' : 'organizations'
const defaultPath = [appComponent, workspace, recruitId, special]
return {
loc: {
path: [appComponent, workspace],
fragment: getPanelURI(component, doc._id, recruit.mixin.Candidate, 'content')
fragment: getPanelURI(component, doc._id, _class, 'content')
},
shouldNavigate: false,
defaultLocation: {
path: defaultPath,
fragment: getPanelURI(component, doc._id, recruit.mixin.Candidate, 'content')
fragment: getPanelURI(component, doc._id, _class, 'content')
}
}
}
@ -126,13 +145,16 @@ export async function getSequenceLink (doc: RecruitDocument): Promise<Location>
return loc
}
export async function getCandidateLink (doc: Candidate): Promise<Location> {
export async function getObjectLink (doc: Candidate | VacancyList): Promise<Location> {
const _class = Hierarchy.mixinOrClass(doc)
const client = getClient()
const clazz = client.getHierarchy().getClass(_class)
const loc = getCurrentLocation()
loc.path.length = 2
loc.fragment = undefined
loc.query = undefined
loc.path[2] = recruitId
loc.path[3] = doc._id
loc.path[3] = clazz.shortLabel !== undefined ? `${clazz.shortLabel}-${doc._id}` : doc._id
return loc
}

View File

@ -232,7 +232,10 @@
loc.path[2] = (currentAppAlias as string) ?? resolved.defaultLocation.path[2]
loc.path[3] = currentSpace ?? (currentSpecial as string) ?? resolved.defaultLocation.path[3]
if (loc.path[3] !== undefined) {
loc.path[4] = currentSpecial ?? (asideId as string) ?? resolved.defaultLocation.path[4]
loc.path[4] =
(currentSpace !== undefined ? currentSpecial : undefined) ??
(asideId as string) ??
resolved.defaultLocation.path[4]
} else {
loc.path.length = 4
}