Skip to content

Commit

Permalink
Improve hide archived
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Bykhov <[email protected]>
  • Loading branch information
BykhovDenis committed Jan 23, 2025
1 parent bba3b48 commit cc9f6ff
Show file tree
Hide file tree
Showing 29 changed files with 256 additions and 272 deletions.
4 changes: 2 additions & 2 deletions models/document/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ function defineTeamspace (builder: Builder): void {
key: 'hideArchived',
type: 'toggle',
defaultValue: true,
actionTarget: 'query',
action: document.function.HideArchivedTeamspaces,
actionTarget: 'options',
action: view.function.HideArchived,
label: view.string.HideArchived
}
]
Expand Down
5 changes: 2 additions & 3 deletions models/document/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { type ObjectSearchCategory, type ObjectSearchFactory } from '@hcengineer
import { type IntlString, mergeIds, type Resource } from '@hcengineering/platform'
import { type TagCategory } from '@hcengineering/tags'
import { type AnyComponent } from '@hcengineering/ui'
import type { Viewlet, Action, ActionCategory, ViewAction, ViewQueryAction } from '@hcengineering/view'
import type { Action, ActionCategory, ViewAction, Viewlet } from '@hcengineering/view'

export default mergeIds(documentId, document, {
component: {
Expand Down Expand Up @@ -52,8 +52,7 @@ export default mergeIds(documentId, document, {
},
function: {
CanLockDocument: '' as Resource<(doc?: Doc | Doc[]) => Promise<boolean>>,
CanUnlockDocument: '' as Resource<(doc?: Doc | Doc[]) => Promise<boolean>>,
HideArchivedTeamspaces: '' as ViewQueryAction
CanUnlockDocument: '' as Resource<(doc?: Doc | Doc[]) => Promise<boolean>>
},
viewlet: {
TeamspaceTable: '' as Ref<Viewlet>
Expand Down
4 changes: 2 additions & 2 deletions models/drive/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ function defineDrive (builder: Builder): void {
key: 'hideArchived',
type: 'toggle',
defaultValue: true,
actionTarget: 'query',
action: drive.function.HideArchivedDrives,
actionTarget: 'options',
action: view.function.HideArchived,
label: view.string.HideArchived
}
]
Expand Down
4 changes: 1 addition & 3 deletions models/drive/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
type ActionCategory,
type ViewAction,
type ViewActionAvailabilityFunction,
type ViewQueryAction,
type Viewlet,
type ViewletDescriptor
} from '@hcengineering/view'
Expand Down Expand Up @@ -55,8 +54,7 @@ export default mergeIds(driveId, drive, {
FolderLinkProvider: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
FileLinkProvider: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
CanRenameFile: '' as Resource<ViewActionAvailabilityFunction>,
CanRenameFolder: '' as Resource<ViewActionAvailabilityFunction>,
HideArchivedDrives: '' as ViewQueryAction
CanRenameFolder: '' as Resource<ViewActionAvailabilityFunction>
},
completion: {
FileQuery: '' as Resource<ObjectSearchFactory>,
Expand Down
14 changes: 6 additions & 8 deletions models/recruit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ export function createModel (builder: Builder): void {
key: 'hideArchived',
type: 'toggle',
defaultValue: true,
label: recruit.string.HideArchivedVacancies
actionTarget: 'options',
action: view.function.HideArchived,
label: view.string.HideArchived
}

builder.createDoc(
Expand Down Expand Up @@ -452,8 +454,8 @@ export function createModel (builder: Builder): void {
key: 'hideArchivedVacancies',
type: 'toggle',
defaultValue: true,
actionTarget: 'query',
action: recruit.function.HideArchivedVacancies,
actionTarget: 'options',
action: view.function.HideArchived,
label: recruit.string.HideApplicantsFromArchivedVacancies
}

Expand Down Expand Up @@ -524,8 +526,7 @@ export function createModel (builder: Builder): void {
}
},
baseQuery: {
isDone: false,
'$lookup.space.archived': false
isDone: false
}
},
recruit.viewlet.TableApplicantMatch
Expand Down Expand Up @@ -777,9 +778,6 @@ export function createModel (builder: Builder): void {
strict: true,
hiddenKeys: ['name', 'space', 'modifiedOn']
},
baseQuery: {
'$lookup.space.archived': false
},
viewOptions: {
groupBy: ['company', 'dueTo', 'createdBy'],
orderBy: [
Expand Down
11 changes: 5 additions & 6 deletions models/recruit/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
// limitations under the License.
//

import type { Status, Client, Doc, Ref } from '@hcengineering/core'
import { type DocUpdateMessageViewlet } from '@hcengineering/activity'
import { type ChatMessageViewlet } from '@hcengineering/chunter'
import type { Client, Doc, Ref, Status } from '@hcengineering/core'
import { type NotificationGroup, type NotificationType } from '@hcengineering/notification'
import type { IntlString, Resource, Status as OperationStatus } from '@hcengineering/platform'
import type { IntlString, Status as OperationStatus, Resource } from '@hcengineering/platform'
import { mergeIds } from '@hcengineering/platform'
import { recruitId } from '@hcengineering/recruit'
import recruit from '@hcengineering/recruit-resources/src/plugin'
import { type TaskTypeDescriptor, type ProjectType } from '@hcengineering/task'
import { type ProjectType, type TaskTypeDescriptor } from '@hcengineering/task'
import type { AnyComponent, Location } from '@hcengineering/ui/src/types'
import type {
Action,
Expand All @@ -29,8 +31,6 @@ import type {
ViewQueryAction,
Viewlet
} from '@hcengineering/view'
import { type DocUpdateMessageViewlet } from '@hcengineering/activity'
import { type ChatMessageViewlet } from '@hcengineering/chunter'

export default mergeIds(recruitId, recruit, {
action: {
Expand All @@ -57,7 +57,6 @@ export default mergeIds(recruitId, recruit, {
GetObjectLink: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<string>>,
GetTalentId: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<string>>,
HideDoneState: '' as ViewQueryAction,
HideArchivedVacancies: '' as ViewQueryAction,
ApplicantHasEmail: '' as Resource<ViewActionAvailabilityFunction>,
ParseLinkId: '' as Resource<(id: string) => Promise<Ref<Doc> | undefined>>
},
Expand Down
5 changes: 4 additions & 1 deletion models/tracker/src/viewlets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,10 @@ export function defineViewlets (builder: Builder): void {
presenter: tracker.component.ModificationDatePresenter,
displayProps: { fixed: 'right', dividerBefore: true }
}
]
],
options: {
showArchived: true
}
},
tracker.viewlet.ProjectList
)
Expand Down
9 changes: 8 additions & 1 deletion models/view/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
import { type Blob, type Doc, type Ref } from '@hcengineering/core'
import { type IntlString, mergeIds, type Resource } from '@hcengineering/platform'
import { type AnyComponent } from '@hcengineering/ui/src/types'
import { type FilterFunction, type ViewAction, type ViewCategoryAction, viewId } from '@hcengineering/view'
import {
type FilterFunction,
type ViewAction,
type ViewCategoryAction,
viewId,
type ViewOptionsAction
} from '@hcengineering/view'
import { type BlobMetadata, type FileOrBlob, type FilePreviewExtension } from '@hcengineering/presentation/src/types'
import { type PresentationMiddlewareFactory } from '@hcengineering/presentation/src/pipeline'
import view from '@hcengineering/view-resources/src/plugin'
Expand Down Expand Up @@ -135,6 +141,7 @@ export default mergeIds(viewId, view, {
FilterDateNotSpecified: '' as FilterFunction,
FilterDateCustom: '' as FilterFunction,
ShowEmptyGroups: '' as ViewCategoryAction,
HideArchived: '' as ViewOptionsAction,
CanDeleteObject: '' as Resource<(doc?: Doc | Doc[]) => Promise<boolean>>,
CanEditSpace: '' as Resource<(doc?: Doc | Doc[]) => Promise<boolean>>,
CanArchiveSpace: '' as Resource<(doc?: Doc | Doc[]) => Promise<boolean>>,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export type FindOptions<T extends Doc> = {

// If specified total will be returned
total?: boolean

showArchived?: boolean
}

/**
Expand Down
7 changes: 1 addition & 6 deletions plugins/document-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ export async function canUnlockDocument (doc: Document | Document[]): Promise<bo
return arr.some((p) => p.lockedBy != null)
}

export function hideArchivedTeamspaces (value: boolean, query: DocumentQuery<Teamspace>): DocumentQuery<Teamspace> {
return value ? { ...query, archived: false } : query
}

export default async (): Promise<Resources> => ({
component: {
CreateDocument,
Expand Down Expand Up @@ -202,8 +198,7 @@ export default async (): Promise<Resources> => ({
CanLockDocument: canLockDocument,
CanUnlockDocument: canUnlockDocument,
GetDocumentLinkId: getDocumentLinkId,
ParseDocumentId: parseDocumentId,
HideArchivedTeamspaces: hideArchivedTeamspaces
ParseDocumentId: parseDocumentId
},
resolver: {
Location: resolveLocation
Expand Down
7 changes: 1 addition & 6 deletions plugins/drive-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ export async function CanRenameFolder (doc: Folder | Folder[] | undefined): Prom
return doc !== undefined && !Array.isArray(doc)
}

export function HideArchivedDrives (value: boolean, query: DocumentQuery<Drive>): DocumentQuery<Drive> {
return value ? { ...query, archived: false } : query
}

export default async (): Promise<Resources> => ({
component: {
CreateDrive,
Expand Down Expand Up @@ -204,8 +200,7 @@ export default async (): Promise<Resources> => ({
FileLinkProvider,
FolderLinkProvider,
CanRenameFile,
CanRenameFolder,
HideArchivedDrives
CanRenameFolder
},
resolver: {
Location: resolveLocation
Expand Down
5 changes: 1 addition & 4 deletions plugins/recruit-resources/src/components/Vacancies.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,7 @@
viewlet,
viewOptions,
viewOptionsConfig: viewlet.viewOptions?.other,
query: {
...resultQuery,
...(viewOptions?.hideArchived !== false ? { archived: false } : {})
},
query: resultQuery,
totalQuery: {},
tableId: 'vacanciesData'
}}
Expand Down
34 changes: 3 additions & 31 deletions plugins/recruit-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.
//

import contact from '@hcengineering/contact'
import {
toIdMap,
type Client,
Expand All @@ -24,14 +25,14 @@ import {
type RelatedDocument
} from '@hcengineering/core'
import { OK, Severity, Status, type Resources } from '@hcengineering/platform'
import { createQuery, getClient, type ObjectSearchResult } from '@hcengineering/presentation'
import { getClient, type ObjectSearchResult } from '@hcengineering/presentation'
import { type Applicant, type Candidate, type Vacancy } from '@hcengineering/recruit'
import contact from '@hcengineering/contact'
import task from '@hcengineering/task'
import { showPopup } from '@hcengineering/ui'
import { type Filter } from '@hcengineering/view'
import { FilterQuery, statusStore } from '@hcengineering/view-resources'
import ApplicantFilter from './components/ApplicantFilter.svelte'
import ApplicantNamePresenter from './components/ApplicantNamePresenter.svelte'
import ApplicationItem from './components/ApplicationItem.svelte'
import ApplicationPresenter from './components/ApplicationPresenter.svelte'
import Applications from './components/Applications.svelte'
Expand Down Expand Up @@ -64,7 +65,6 @@ import Opinions from './components/review/Opinions.svelte'
import OpinionsPresenter from './components/review/OpinionsPresenter.svelte'
import ReviewPresenter from './components/review/ReviewPresenter.svelte'
import Reviews from './components/review/Reviews.svelte'
import ApplicantNamePresenter from './components/ApplicantNamePresenter.svelte'
import recruit from './plugin'
import {
getAppIdentifier,
Expand Down Expand Up @@ -293,33 +293,6 @@ export function hideDoneState (value: any, query: DocumentQuery<Doc>): DocumentQ
return query
}

const activeVacancyQuery = createQuery(true)

let activeVacancies: Promise<Array<Ref<Vacancy>>> | Array<Ref<Vacancy>> | undefined

export async function hideArchivedVacancies (value: any, query: DocumentQuery<Doc>): Promise<DocumentQuery<Doc>> {
if (activeVacancies === undefined) {
activeVacancies = new Promise<Array<Ref<Vacancy>>>((resolve) => {
activeVacancyQuery.query(
recruit.class.Vacancy,
{ archived: { $ne: true } },
(res) => {
activeVacancies = res.map((it) => it._id)
resolve(activeVacancies)
},
{ projection: { _id: 1 } }
)
})
}
if (value as boolean) {
if (activeVacancies instanceof Promise) {
activeVacancies = await activeVacancies
}
return { ...query, space: { $in: activeVacancies } }
}
return query
}

export async function applicantHasEmail (doc: Doc | Doc[] | undefined): Promise<boolean> {
if (doc === undefined) return false
const client = getClient()
Expand Down Expand Up @@ -415,7 +388,6 @@ export default async (): Promise<Resources> => ({
GetObjectLinkFragment: getSequenceLink,
GetIdObjectLinkFragment: getObjectLink,
HideDoneState: hideDoneState,
HideArchivedVacancies: hideArchivedVacancies,
ApplicantHasEmail: applicantHasEmail,
ParseLinkId: parseLinkId
},
Expand Down
29 changes: 24 additions & 5 deletions plugins/task-resources/src/components/TypesView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
// limitations under the License.
-->
<script lang="ts">
import { Class, Doc, DocumentQuery, mergeQueries, Ref, Space, WithLookup } from '@hcengineering/core'
import { Class, Doc, DocumentQuery, FindOptions, mergeQueries, Ref, Space, WithLookup } from '@hcengineering/core'
import { IntlString } from '@hcengineering/platform'
import { createQuery } from '@hcengineering/presentation'
import { Project, ProjectType, ProjectTypeDescriptor } from '@hcengineering/task'
import { AnyComponent, Button, Component, IconAdd, Loading, SearchInput, showPopup, Header } from '@hcengineering/ui'
import { Viewlet, ViewletDescriptor, ViewletPreference, ViewOptions } from '@hcengineering/view'
import { FilterBar, FilterButton, ViewletSelector, ViewletSettingButton } from '@hcengineering/view-resources'
import {
FilterBar,
FilterButton,
getResultOptions,
ViewletSelector,
ViewletSettingButton
} from '@hcengineering/view-resources'
import { selectedTaskTypeStore, selectedTypeStore, taskTypeStore } from '..'
import task from '../plugin'
import TypeSelector from './TypeSelector.svelte'
Expand All @@ -42,11 +48,24 @@
let viewlets: WithLookup<Viewlet>[] = []
let viewOptions: ViewOptions | undefined
let resultOptions = viewlet?.options
$: void getResultOptions(viewlet?.options ?? {}, viewlet?.viewOptions?.other, viewOptions).then((p) => {
resultOptions = p
})
const spacesQ = createQuery()
let spaces: Project[] = []
$: spacesQ.query(task.class.Project, { type: $selectedTypeStore as Ref<ProjectType> }, (result) => {
spaces = result
})
$: spacesQ.query<Project>(
task.class.Project,
{ type: $selectedTypeStore as Ref<ProjectType> },
(result) => {
spaces = result
},
{
showArchived: resultOptions?.showArchived ?? false
}
)
let resultQuery: DocumentQuery<Doc>
$: query = { ...(baseQuery ?? {}), ...(viewlet?.baseQuery ?? {}), space: { $in: spaces.map((it) => it._id) } }
$: searchQuery = search === '' ? query : { ...query, $search: search }
Expand Down
Loading

0 comments on commit cc9f6ff

Please sign in to comment.