Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns behave.components.matrix-table
(:require [behave.stories.utils :refer [->params]]))

(defn- table-header [title rows-label cols-label header-names & [sub-title]]
(defn- table-header [title rows-label cols-label header-names header-color & [sub-title]]
[:thead.table-header
[:tr.table__title
[:tr.table__title (when header-color {:style {:background-color header-color}})
[:th {:col-span (inc (count header-names))} title]]
(when sub-title
[:tr.table__sub-title
Expand All @@ -28,13 +28,13 @@
- cols-labl : string
- cell-colors : a map of [row col] -> hex color
"
[{:keys [title sub-title column-headers row-headers data rows-label cols-label cell-colors]}]
[{:keys [title sub-title column-headers row-headers data rows-label cols-label header-color cell-colors]}]
(let [column-headers (->params column-headers)
row-headers (->params row-headers)
data (->params data)
column-header-names (map :name column-headers)]
[:table.table
[table-header title rows-label cols-label column-header-names sub-title]
[table-header title rows-label cols-label column-header-names header-color sub-title]
[:tbody.table__body
(for [row-header row-headers
:let [i (:key row-header)
Expand Down
9 changes: 8 additions & 1 deletion bases/behave_schema/src/behave/schema/group_variable.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

;;; Schema

#_{:clj-kondo/ignore [:missing-docstring]}
(def schema
[{:db/ident :group-variable/cpp-namespace
:db/doc "Group variable's C++ namespace."
Expand Down Expand Up @@ -94,10 +95,15 @@
:db/cardinality :db.cardinality/many}

{:db/ident :group-variable/direction
:db/doc "Group variable's direction."
:db/doc "DEPRECATED: use :group-variable/direction-ref. Group variable's direction keyword."
:db/valueType :db.type/keyword
:db/cardinality :db.cardinality/one}

{:db/ident :group-variable/direction-ref
:db/doc "Group variable's reference to a list-option of the 'Directions' list. Replaces :group-variable/direction."
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}

;; Boolean Settings
{:db/ident :group-variable/research?
:db/doc "Whether a Group Variable is for research."
Expand Down Expand Up @@ -162,6 +168,7 @@

;;; Tests

#_{:clj-kondo/ignore [:unresolved-symbol]}
(comment
(s/explain :behave/group-variable {:bp/uuid (str (random-uuid))
:group-variable/order 0
Expand Down
9 changes: 6 additions & 3 deletions bases/behave_schema/src/behave/schema/list.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns behave.schema.list
(:require [clojure.spec.alpha :as s]
[behave.schema.utils :refer [many-ref? valid-key? uuid-string? zero-pos?]]))
(:require [behave.schema.utils :refer [many-ref? valid-key? uuid-string? zero-pos?]]
[clojure.spec.alpha :as s]))

;;; Spec

Expand Down Expand Up @@ -30,6 +30,7 @@
:opt [:list-option/default
:list-option/hide?]))

#_{:clj-kondo/ignore [:missing-docstring]}
(def schema
;; Lists
[{:db/ident :list/uuid
Expand Down Expand Up @@ -68,7 +69,8 @@
{:db/ident :list/options
:db/doc "List's options."
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
:db/cardinality :db.cardinality/many
:db/isComponent true}

;; List Options
{:db/ident :list-option/uuid
Expand Down Expand Up @@ -216,6 +218,7 @@

;;; Tests

#_{:clj-kondo/ignore [:unresolved-symbol]}
(comment
(s/valid? :behave/list {:list/uuid (str (random-uuid))
:list/name "My List"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
(ns migrations.2026-04-28-link-directions-to-fire-direction
(:require [behave-cms.server :as cms]
[behave-cms.store :refer [default-conn]]
[clojure.string :as str]
[datomic.api :as d]
[schema-migrate.interface :as sm]))

;; ===========================================================================================================
;; Overview
;; ===========================================================================================================

;; 1. Create "Directions" color tag-set with Heading/Flanking/Backing tags and hex colors.
;; 2. Seed an English translation for the new tag-set key only; per-direction keys already exist.
;; 3. Attach :list/color-tag-set to the existing FireDirection list.
;; 4. Add :list-option/color-tag-ref to each FireDirection list-option (matched by :list-option/name).
;; 5. Backfill :group-variable/direction-ref from existing :group-variable/direction keywords,
;; resolving against FireDirection options by :list-option/name.

;; ===========================================================================================================
;; Initialize
;; ===========================================================================================================

(cms/init-db!)

#_{:clj-kondo/ignore [:missing-docstring]}
(def conn (default-conn))

;; ===========================================================================================================
;; Step 1 — color tag-set + tags
;; ===========================================================================================================

#_{:clj-kondo/ignore [:missing-docstring]}
(def directions-color-tag-payload
(sm/postwalk-insert
[{:db/id -100
:tag-set/name "Directions"
:tag-set/translation-key "behave:tag-set:directions"
:tag-set/color? true
:tag-set/tags
[{:db/id -101
:tag/name "Heading"
:tag/color "#13486a"
:tag/translation-key "behave:list-option:list-option:firedirection:heading"
:tag/order 0}
{:db/id -102
:tag/name "Flanking"
:tag/color "#4a7086"
:tag/translation-key "behave:list-option:list-option:firedirection:flanking"
:tag/order 1}
{:db/id -103
:tag/name "Backing"
:tag/color "#8297a3"
:tag/translation-key "behave:list-option:list-option:firedirection:backing"
:tag/order 2}]}]))

;; ===========================================================================================================
;; Step 2 — translation for the new tag-set (per-direction keys already exist)
;; ===========================================================================================================

#_{:clj-kondo/ignore [:missing-docstring]}
(def translations-payload
(sm/build-translations-payload
conn
{"behave:tag-set:directions" "Directions"}))

;; ===========================================================================================================
;; Step 3 + 4 — attach tag-set and color-tag-ref to FireDirection list and its options
;; ===========================================================================================================

#_{:clj-kondo/ignore [:missing-docstring]}
(def fire-direction-eid
(d/q '[:find ?l .
:where [?l :list/name "FireDirection"]]
(d/db conn)))

(def ^:private tag-name->tempid
{"heading" -101
"flanking" -102
"backing" -103})

#_{:clj-kondo/ignore [:missing-docstring]}
(def fire-direction-options
(d/q '[:find ?opt ?name
:in $ ?l
:where
[?l :list/options ?opt]
[?opt :list-option/name ?name]]
(d/db conn)
fire-direction-eid))

#_{:clj-kondo/ignore [:missing-docstring]}
(def attach-payload
(concat
[[:db/add fire-direction-eid :list/color-tag-set -100]]
(for [[opt-eid opt-name] fire-direction-options
:let [lc-name (str/lower-case opt-name)
tag-id (tag-name->tempid lc-name)]
:when tag-id]
[:db/add opt-eid :list-option/color-tag-ref tag-id])))

;; ===========================================================================================================
;; Step 5 — backfill :group-variable/direction-ref from legacy :group-variable/direction keywords
;; ===========================================================================================================

(def ^:private name->option-eid
(into {} (for [[opt-eid opt-name] fire-direction-options]
[(str/lower-case opt-name) opt-eid])))

#_{:clj-kondo/ignore [:missing-docstring]}
(def gv-pairs
(d/q '[:find ?gv ?dir
:where [?gv :group-variable/direction ?dir]]
(d/db conn)))

#_{:clj-kondo/ignore [:missing-docstring]}
(def backfill-payload
(vec (for [[gv-eid dir-kw] gv-pairs
:let [opt-eid (name->option-eid (name dir-kw))]
:when opt-eid]
[:db/add gv-eid :group-variable/direction-ref opt-eid])))

#_{:clj-kondo/ignore [:missing-docstring]}
(def payload
(concat directions-color-tag-payload
translations-payload
attach-payload
backfill-payload))

;; ===========================================================================================================
;; Transact
;; ===========================================================================================================

(comment
#_{:clj-kondo/ignore [:missing-docstring]}
(try (def tx-data @(d/transact conn payload))
(catch Exception e (str "caught exception: " (.getMessage e)))))

;; ===========================================================================================================
;; Rollback
;; ===========================================================================================================

(comment
(sm/rollback-tx! conn tx-data))
Binary file modified projects/behave/resources/public/layout.msgpack
Binary file not shown.
Loading
Loading