enhance(apis): add support for tag properties in createTag API

This commit is contained in:
charlie
2026-01-03 21:51:23 +08:00
parent 664743b286
commit baff8a4cc1
2 changed files with 24 additions and 9 deletions

View File

@@ -349,6 +349,14 @@
(is (= (get tag3 "title") title) "get tag with ident") (is (= (get tag3 "title") title) "get tag with ident")
(is (= (get tag4 "title") title) "get tag with uuid"))) (is (= (get tag4 "title") title) "get tag with uuid")))
(testing "create tag with tagProperties"
(let [tag-props [{:name "prop1" :schema {:type "string"}}
{:name "prop2" :schema {:type "number"}}
{:name "prop3" :schema {:type "checkbox"}}]
tag (ls-api-call! :editor.createTag "tag-with-props" {:tagProperties tag-props})
props (get tag ":logseq.property.class/properties")]
(is (= 3 (count props)) "tag has 3 properties")))
(testing "add and remove tag extends" (testing "add and remove tag extends"
(let [tag1 (ls-api-call! :editor.createTag "tag1") (let [tag1 (ls-api-call! :editor.createTag "tag1")
tag2 (ls-api-call! :editor.createTag "tag2") tag2 (ls-api-call! :editor.createTag "tag2")
@@ -395,8 +403,8 @@
(is (empty? result) "should not return regular pages, only tags"))) (is (empty? result) "should not return regular pages, only tags")))
(testing "get tags by name with multiple tags having similar names" (testing "get tags by name with multiple tags having similar names"
(let [tag1 (ls-api-call! :editor.createTag "category") (let [_tag1 (ls-api-call! :editor.createTag "category")
tag2 (ls-api-call! :editor.createTag "Category") _tag2 (ls-api-call! :editor.createTag "Category")
result (ls-api-call! :editor.getTagsByName "category")] result (ls-api-call! :editor.getTagsByName "category")]
;; Due to case-insensitive name normalization, both tags should be the same ;; Due to case-insensitive name normalization, both tags should be the same
(is (>= (count result) 1) "should return at least one tag") (is (>= (count result) 1) "should return at least one tag")

View File

@@ -327,6 +327,13 @@ export type SearchBlockItem = {
export type SearchPageItem = string export type SearchPageItem = string
export type SearchFileItem = string export type SearchFileItem = string
export type PropertySchema = {
type: 'default' | 'number' | 'node' | 'date' | 'checkbox' | 'url' | string,
cardinality: 'many' | 'one',
hide: boolean
public: boolean
}
export interface IPluginSearchServiceHooks { export interface IPluginSearchServiceHooks {
name: string name: string
options?: Record<string, any> options?: Record<string, any>
@@ -767,7 +774,12 @@ export interface IEditorProxy extends Record<string, any> {
getAllTags: () => Promise<PageEntity[] | null> getAllTags: () => Promise<PageEntity[] | null>
getAllProperties: () => Promise<PageEntity[] | null> getAllProperties: () => Promise<PageEntity[] | null>
getTagObjects: (nameOrIdent: string) => Promise<BlockEntity[] | null> getTagObjects: (nameOrIdent: string) => Promise<BlockEntity[] | null>
createTag: (tagName: string, opts?: Partial<{ uuid: string }>) => Promise<PageEntity | null> createTag: (
tagName: string,
opts?: Partial<{
uuid: string, // custom uuid
tagProperties: Array<{ name: string, schema?: Partial<PropertySchema>, properties?: {} }>
}>) => Promise<PageEntity | null>
getTag: (nameOrIdent: string | EntityID) => Promise<PageEntity | null> getTag: (nameOrIdent: string | EntityID) => Promise<PageEntity | null>
getTagsByName: (tagName: string) => Promise<Array<PageEntity> | null> getTagsByName: (tagName: string) => Promise<Array<PageEntity> | null>
addTagProperty: (tagId: BlockIdentity, propertyIdOrName: BlockIdentity) => Promise<void> addTagProperty: (tagId: BlockIdentity, propertyIdOrName: BlockIdentity) => Promise<void>
@@ -819,12 +831,7 @@ export interface IEditorProxy extends Record<string, any> {
// insert or update property entity // insert or update property entity
upsertProperty: ( upsertProperty: (
key: string, key: string,
schema?: Partial<{ schema?: Partial<PropertySchema>,
type: 'default' | 'number' | 'node' | 'date' | 'checkbox' | 'url' | string,
cardinality: 'many' | 'one',
hide: boolean
public: boolean
}>,
opts?: { name?: string }) => Promise<IEntityID> opts?: { name?: string }) => Promise<IEntityID>
// remove property entity // remove property entity