Skip to content

Commit baff8a4

Browse files
committed
enhance(apis): add support for tag properties in createTag API
1 parent 664743b commit baff8a4

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

clj-e2e/test/logseq/e2e/plugins_basic_test.clj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@
349349
(is (= (get tag3 "title") title) "get tag with ident")
350350
(is (= (get tag4 "title") title) "get tag with uuid")))
351351

352+
(testing "create tag with tagProperties"
353+
(let [tag-props [{:name "prop1" :schema {:type "string"}}
354+
{:name "prop2" :schema {:type "number"}}
355+
{:name "prop3" :schema {:type "checkbox"}}]
356+
tag (ls-api-call! :editor.createTag "tag-with-props" {:tagProperties tag-props})
357+
props (get tag ":logseq.property.class/properties")]
358+
(is (= 3 (count props)) "tag has 3 properties")))
359+
352360
(testing "add and remove tag extends"
353361
(let [tag1 (ls-api-call! :editor.createTag "tag1")
354362
tag2 (ls-api-call! :editor.createTag "tag2")
@@ -395,8 +403,8 @@
395403
(is (empty? result) "should not return regular pages, only tags")))
396404

397405
(testing "get tags by name with multiple tags having similar names"
398-
(let [tag1 (ls-api-call! :editor.createTag "category")
399-
tag2 (ls-api-call! :editor.createTag "Category")
406+
(let [_tag1 (ls-api-call! :editor.createTag "category")
407+
_tag2 (ls-api-call! :editor.createTag "Category")
400408
result (ls-api-call! :editor.getTagsByName "category")]
401409
;; Due to case-insensitive name normalization, both tags should be the same
402410
(is (>= (count result) 1) "should return at least one tag")

libs/src/LSPlugin.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,13 @@ export type SearchBlockItem = {
327327
export type SearchPageItem = string
328328
export type SearchFileItem = string
329329

330+
export type PropertySchema = {
331+
type: 'default' | 'number' | 'node' | 'date' | 'checkbox' | 'url' | string,
332+
cardinality: 'many' | 'one',
333+
hide: boolean
334+
public: boolean
335+
}
336+
330337
export interface IPluginSearchServiceHooks {
331338
name: string
332339
options?: Record<string, any>
@@ -767,7 +774,12 @@ export interface IEditorProxy extends Record<string, any> {
767774
getAllTags: () => Promise<PageEntity[] | null>
768775
getAllProperties: () => Promise<PageEntity[] | null>
769776
getTagObjects: (nameOrIdent: string) => Promise<BlockEntity[] | null>
770-
createTag: (tagName: string, opts?: Partial<{ uuid: string }>) => Promise<PageEntity | null>
777+
createTag: (
778+
tagName: string,
779+
opts?: Partial<{
780+
uuid: string, // custom uuid
781+
tagProperties: Array<{ name: string, schema?: Partial<PropertySchema>, properties?: {} }>
782+
}>) => Promise<PageEntity | null>
771783
getTag: (nameOrIdent: string | EntityID) => Promise<PageEntity | null>
772784
getTagsByName: (tagName: string) => Promise<Array<PageEntity> | null>
773785
addTagProperty: (tagId: BlockIdentity, propertyIdOrName: BlockIdentity) => Promise<void>
@@ -819,12 +831,7 @@ export interface IEditorProxy extends Record<string, any> {
819831
// insert or update property entity
820832
upsertProperty: (
821833
key: string,
822-
schema?: Partial<{
823-
type: 'default' | 'number' | 'node' | 'date' | 'checkbox' | 'url' | string,
824-
cardinality: 'many' | 'one',
825-
hide: boolean
826-
public: boolean
827-
}>,
834+
schema?: Partial<PropertySchema>,
828835
opts?: { name?: string }) => Promise<IEntityID>
829836

830837
// remove property entity

0 commit comments

Comments
 (0)