From 830c50da3a5cddfceeec48e8c0ec2ae68af51e77 Mon Sep 17 00:00:00 2001 From: kevinslin Date: Wed, 8 Jul 2020 08:11:56 -0700 Subject: [PATCH] feat: show schema suggestion at same level as query --- .../src/components/lookup/LookupProvider.ts | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/plugin-core/src/components/lookup/LookupProvider.ts b/packages/plugin-core/src/components/lookup/LookupProvider.ts index 8a884145dd..fe5f0093a1 100644 --- a/packages/plugin-core/src/components/lookup/LookupProvider.ts +++ b/packages/plugin-core/src/components/lookup/LookupProvider.ts @@ -1,4 +1,4 @@ -import { DNodeUtils, Note, Schema, SchemaUtils } from "@dendronhq/common-all"; +import { DNodeUtils, Note, Schema, SchemaUtils, DNode } from "@dendronhq/common-all"; import { createLogger } from "@dendronhq/common-server"; import { DendronEngine } from "@dendronhq/engine-server"; import _ from "lodash"; @@ -12,12 +12,30 @@ const L = createLogger("LookupProvider"); class QueryStringUtils { /** * Get all schema matches for current query + * + * # eg. Query with Root + * + * schema: + * - bar + * - alpha + * - beta + * - foo + * - one + * - two + * qs: foo + * + * return: [one, two] + * + * # eg. Query not at root + * qs: foo.one + * + * * @param _qs * @param engineResp */ static getAllSchemaAtLevel(_qs: string, engineResp: Note[]): Schema[] { const maybeSchema = engineResp[0]?.schema; - return maybeSchema?.parent?.children as Schema[] || []; + return maybeSchema?.children as Schema[] || []; } static isDomainQuery(qs: string): boolean { @@ -63,11 +81,18 @@ class PickerUtils { ) { return picker.value; } + static getSelection( picker: QuickPick ): T { return picker.selectedItems[0]; } + + static filterStubs(items: DNode[]): DNode[] { + return _.filter(items, ent => { + return !ent.stub + }); + } } @@ -136,6 +161,7 @@ export class LookupProvider { return ent.fname; }); } + updatedItems = PickerUtils.filterStubs(updatedItems); // check if perfect match, remove @noActiveItem result if that's the case if (perfectMatch) {