Fix Vacancies search blinking (#1566)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2022-04-27 21:29:11 +07:00 committed by GitHub
parent ca2b5ba0f3
commit 13834e6c07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,10 +14,10 @@
--> -->
<script lang="ts"> <script lang="ts">
import contact from '@anticrm/contact' import contact from '@anticrm/contact'
import core, { Doc, DocumentQuery, Lookup, Ref, WithLookup } from '@anticrm/core' import core, { Doc, DocumentQuery, Lookup, Ref } from '@anticrm/core'
import { createQuery } from '@anticrm/presentation' import { createQuery } from '@anticrm/presentation'
import { Applicant, Vacancy } from '@anticrm/recruit' import { Vacancy } from '@anticrm/recruit'
import { Button, getCurrentLocation, Icon, Label, navigate, Scroller, showPopup, IconAdd } from '@anticrm/ui' import { Button, getCurrentLocation, Icon, IconAdd, Label, navigate, Scroller, showPopup } from '@anticrm/ui'
import SearchEdit from '@anticrm/ui/src/components/SearchEdit.svelte' import SearchEdit from '@anticrm/ui/src/components/SearchEdit.svelte'
import { Table } from '@anticrm/view-resources' import { Table } from '@anticrm/view-resources'
import recruit from '../plugin' import recruit from '../plugin'
@ -31,52 +31,19 @@
} }
let search: string = '' let search: string = ''
let vquery: string = ''
let resultQuery: DocumentQuery<Doc> = {} let resultQuery: DocumentQuery<Doc> = {}
let vacancyQuery: DocumentQuery<Doc> = {}
let vacancies: WithLookup<Vacancy>[] = []
const query = createQuery()
let appQuery = false
const lookup: Lookup<Vacancy> = { const lookup: Lookup<Vacancy> = {
company: contact.class.Organization company: contact.class.Organization
} }
$: query.query(recruit.class.Vacancy, { archived: false }, (res) => { $: resultQuery = search === '' ? {} : { $search: search }
vacancies = res
}, { lookup })
function lowerIncludes (a: string | undefined, b: string): boolean {
return (a ?? '').toLowerCase().includes(b.toLowerCase())
}
$: if (vacancies.length > 0 && !appQuery) {
vacancyQuery = {
_id: {
$in: vacancies
.filter(
(it) =>
lowerIncludes(it.name, vquery) ||
lowerIncludes(it.description, vquery) ||
lowerIncludes(it.$lookup?.company?.name, vquery) ||
(applications?.get(it._id) ?? 0) > 0
)
.map((it) => it._id)
}
}
}
$: resultQuery = vquery === '' ? {} : { $search: vquery }
type ApplicationInfo = { count: number, modifiedOn: number } type ApplicationInfo = { count: number, modifiedOn: number }
let applications: Map<Ref<Vacancy>, ApplicationInfo> | undefined let applications: Map<Ref<Vacancy>, ApplicationInfo> | undefined
const applicantQuery = createQuery() const applicantQuery = createQuery()
$: if (vacancies.length > 0) { $: applicantQuery.query(
appQuery = true recruit.class.Applicant, { },
applicantQuery.query(
recruit.class.Applicant,
{ ...(resultQuery as DocumentQuery<Applicant>), space: { $in: vacancies.map((it) => it._id) } },
(res) => { (res) => {
const result = new Map<Ref<Vacancy>, ApplicationInfo>() const result = new Map<Ref<Vacancy>, ApplicationInfo>()
@ -88,10 +55,14 @@
} }
applications = result applications = result
appQuery = false }, {
projection: {
_id: 1,
modifiedOn: 1,
space: 1
}
} }
) )
}
function showCreateDialog () { function showCreateDialog () {
showPopup(CreateVacancy, { space: recruit.space.CandidatesPublic }, 'top') showPopup(CreateVacancy, { space: recruit.space.CandidatesPublic }, 'top')
@ -107,8 +78,8 @@
</div> </div>
<SearchEdit <SearchEdit
bind:value={search} bind:value={search}
on:change={() => { on:change={(e) => {
vquery = search search = e.detail
}} }}
/> />
<Button icon={IconAdd} label={recruit.string.VacancyCreateLabel} kind={'primary'} on:click={showCreateDialog} /> <Button icon={IconAdd} label={recruit.string.VacancyCreateLabel} kind={'primary'} on:click={showCreateDialog} />
@ -128,7 +99,7 @@
key: '', key: '',
presenter: recruit.component.VacancyCountPresenter, presenter: recruit.component.VacancyCountPresenter,
label: recruit.string.Applications, label: recruit.string.Applications,
props: { applications, resultQuery }, props: { applications },
sortingKey: '@applications', sortingKey: '@applications',
sortingFunction: applicationSorting sortingFunction: applicationSorting
}, },
@ -148,7 +119,7 @@
lookup lookup
}} }}
query={{ query={{
...vacancyQuery, ...resultQuery,
archived: false archived: false
}} }}
showNotification showNotification