fix(plugin): incorrect normalize data case for the hashmap value

pull/11506/head
charlie 2024-09-05 20:12:29 +08:00
parent adc032e87f
commit e05dc085a2
3 changed files with 10 additions and 8 deletions

View File

@ -810,7 +810,7 @@ export interface IEditorProxy extends Record<string, any> {
upsertProperty: ( upsertProperty: (
key: string, key: string,
schema?: Partial<{ schema?: Partial<{
type: 'default' | 'map' | 'keyword' | 'date' | 'checkbox' | string, type: 'default' | 'map' | 'number' | 'keyword' | 'node' | 'date' | 'checkbox' | string,
cardinality: 'many' | 'one', cardinality: 'many' | 'one',
hide: boolean hide: boolean
public: boolean public: boolean

View File

@ -80,7 +80,7 @@
(defn- get-caller-plugin-id (defn- get-caller-plugin-id
[] (gobj/get js/window "$$callerPluginID")) [] (gobj/get js/window "$$callerPluginID"))
(defn- sanitize-user-property-key (defn- sanitize-user-property-name
[k] [k]
(if (string? k) (if (string? k)
(-> k (string/trim) (-> k (string/trim)
@ -869,7 +869,7 @@
;; properties (db only) ;; properties (db only)
(defn ^:export get_property (defn ^:export get_property
[k] [k]
(when-let [k' (and (string? k) (some-> k (sanitize-user-property-key) (keyword)))] (when-let [k' (and (string? k) (some-> k (sanitize-user-property-name) (keyword)))]
(p/let [k (if (qualified-keyword? k') k' (get-db-ident-for-property-name k)) (p/let [k (if (qualified-keyword? k') k' (get-db-ident-for-property-name k))
p (db-utils/pull k)] p (db-utils/pull k)]
(bean/->js (sdk-utils/normalize-keyword-for-json p))))) (bean/->js (sdk-utils/normalize-keyword-for-json p)))))
@ -913,7 +913,7 @@
(def ^:export remove_block_property (def ^:export remove_block_property
(fn [block-uuid key] (fn [block-uuid key]
(p/let [key (sanitize-user-property-key key) (p/let [key (sanitize-user-property-name key)
block-uuid (sdk-utils/uuid-or-throw-error block-uuid) block-uuid (sdk-utils/uuid-or-throw-error block-uuid)
_ (db-async/<get-block (state/get-current-repo) block-uuid :children? false) _ (db-async/<get-block (state/get-current-repo) block-uuid :children? false)
db? (config/db-based-graph? (state/get-current-repo)) db? (config/db-based-graph? (state/get-current-repo))
@ -930,13 +930,15 @@
_ (db-async/<get-block (state/get-current-repo) block-uuid :children? false)] _ (db-async/<get-block (state/get-current-repo) block-uuid :children? false)]
(when-let [block (db-model/get-block-by-uuid block-uuid)] (when-let [block (db-model/get-block-by-uuid block-uuid)]
(let [properties (:block/properties block) (let [properties (:block/properties block)
key (sanitize-user-property-key key) key (sanitize-user-property-name key)
property-name (-> (if (keyword? key) (name key) key) (util/safe-lower-case)) property-name (-> (if (keyword? key) (name key) key) (util/safe-lower-case))
property-value (or (get properties key) property-value (or (get properties key)
(get properties property-name) (get properties property-name)
(get properties (get-db-ident-for-property-name property-name))) (get properties (get-db-ident-for-property-name property-name)))
property-value (if-let [property-id (:db/id property-value)] (db/pull property-id) property-value)] property-value (if-let [property-id (:db/id property-value)]
(bean/->js (sdk-utils/normalize-keyword-for-json property-value))))))) (db/pull property-id) property-value)
ret (sdk-utils/normalize-keyword-for-json property-value)]
(bean/->js ret))))))
(def ^:export get_block_properties (def ^:export get_block_properties
(fn [block-uuid] (fn [block-uuid]

View File

@ -42,7 +42,7 @@
;; @FIXME compatible layer for classic APIs ;; @FIXME compatible layer for classic APIs
(and (map? a) (:block/uuid a)) (and (map? a) (:block/uuid a))
(some->> (:block/title a) (assoc a :block/content)) (or (some->> (:block/title a) (assoc a :block/content)) a)
:else a)) input))))) :else a)) input)))))