Skip to content

Commit

Permalink
Fix documents search (#6818)
Browse files Browse the repository at this point in the history
  • Loading branch information
BykhovDenis authored Oct 7, 2024
1 parent a78ec1b commit c9a032e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion models/server-document/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function createModel (builder: Builder): void {
component: document.component.DocumentSearchIcon,
props: ['icon', 'color']
},
title: 'name'
title: 'title'
}
})
}
2 changes: 1 addition & 1 deletion plugins/document-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function queryDocument (
search: string,
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
): Promise<ObjectSearchResult[]> {
const q: DocumentQuery<Document> = { name: { $like: `%${search}%` } }
const q: DocumentQuery<Document> = { title: { $like: `%${search}%` } }
if (filter?.in !== undefined || filter?.nin !== undefined) {
q._id = {}
if (filter.in !== undefined) {
Expand Down
12 changes: 9 additions & 3 deletions plugins/view-resources/src/components/ParentsNavigator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@
const client = getClient()
function hasParent (doc: Doc | AttachedDoc): boolean {
return 'parent' in doc && doc.parent != null
}
async function getParents (doc: Doc | AttachedDoc): Promise<readonly Doc[]> {
if (!isAttachedDoc(doc)) {
if (!isAttachedDoc(doc) && !hasParent(doc)) {
return []
}
const parents: Doc[] = []
let currentDoc: Doc | undefined = doc
while (currentDoc && isAttachedDoc(currentDoc)) {
const parent: Doc | undefined = await client.findOne(currentDoc.attachedToClass, { _id: currentDoc.attachedTo })
while (currentDoc && (isAttachedDoc(currentDoc) || hasParent(currentDoc))) {
const parent: Doc | undefined = isAttachedDoc(currentDoc)
? await client.findOne(currentDoc.attachedToClass, { _id: currentDoc.attachedTo })
: await client.findOne(currentDoc._class, { _id: (currentDoc as any).parent })
if (parent) {
currentDoc = parent
Expand Down

0 comments on commit c9a032e

Please sign in to comment.