enhance: import :filters and helpfully ignore :icon

Better to ignore :icon and explain to user than import them as broken with no explanation.
part of LOG-2985
pull/11049/head
Gabriel Horner 2024-02-22 10:12:09 -05:00
parent 1f3515a70d
commit 531a8ef533
2 changed files with 48 additions and 26 deletions

View File

@ -121,9 +121,14 @@
{:type {:from prev-type :to prop-type}})))
(defn- update-built-in-property-values
[props db]
[props db ignored-properties {:block/keys [content name]}]
(->> props
(map (fn [[prop val]]
(keep (fn [[prop val]]
(if (= :icon prop)
(do (swap! ignored-properties
conj
{:property prop :value val :location (if name {:page name} {:block content})})
nil)
[prop
(case prop
:query-properties
@ -139,7 +144,12 @@
(:block/uuid (db-property/get-closed-value-entity-by-name db prop val))
:logseq.table.version
(parse-long val)
val)]))
:filters
(try (edn/read-string val)
(catch :default e
(js/console.error "Translating filters failed with:" e)
{}))
val)])))
(into {})))
(defn- handle-changed-property
@ -183,7 +193,9 @@
(defn- update-properties
"Updates block property names and values"
[props db page-names-to-uuids properties-text-values {:keys [whiteboard? property-changes import-state]}]
[props db page-names-to-uuids
{:block/keys [properties-text-values] :as block}
{:keys [whiteboard? property-changes import-state]}]
(let [prop-name->uuid (if whiteboard?
(fn prop-name->uuid [k]
(or (get-pid db k)
@ -195,7 +207,11 @@
;; TODO: Add import support for :template. Ignore for now as they cause invalid property types
(if (contains? props :template)
{}
(-> (update-built-in-property-values (select-keys props db-property/built-in-properties-keys) db)
(-> (update-built-in-property-values
(select-keys props db-property/built-in-properties-keys)
db
(:ignored-properties import-state)
(select-keys block [:block/name :block/content]))
(merge (update-user-property-values user-properties prop-name->uuid properties-text-values property-changes (:ignored-properties import-state)))
(update-keys prop-name->uuid)))))
@ -223,7 +239,9 @@
_ (when (seq property-changes) (prn :PROP-CHANGES property-changes))
options' (assoc options :property-changes property-changes)]
(assoc-in block [:block/properties]
(update-properties properties' db page-names-to-uuids (:block/properties-text-values block) options')))
(update-properties properties' db page-names-to-uuids
(select-keys block [:block/properties-text-values :block/name :block/content])
options')))
block)
(dissoc :block/properties-text-values :block/properties-order :block/invalid-properties)))

View File

@ -360,11 +360,15 @@
[:.text-lg.mb-2 (str "Import ignored " (count ignored-props) " "
(if (= 1 (count ignored-props)) "property" "properties"))]
[:span.text-xs
"To fix this, change these property values to have the correct type and reimport the graph"]
"To fix a property type, change the property value to the correct type and reimport the graph"]
(->> ignored-props
(map (fn [{:keys [property value schema]}]
(map (fn [{:keys [property value schema location]}]
[(str "Property " (pr-str property) " with value " (pr-str value))
(str "Property value has type " (get-in schema [:type :to]) " instead of type " (get-in schema [:type :from]))]))
(if (= property :icon)
(if (:page location)
(str "Page icons can't be imported. Go to the page " (pr-str (:page location)) " to manually import it.")
(str "Block icons can't be imported. Manually import it at the block: " (pr-str (:block location))))
(str "Property value has type " (get-in schema [:type :to]) " instead of type " (get-in schema [:type :from])))]))
(map (fn [[k v]]
[:dl.my-2.mb-0
[:dt.m-0 [:strong (str k)]]