Skip to content
Snippets Groups Projects
Commit 70e9a69c authored by Ryan Senior's avatar Ryan Senior
Browse files

Add a new enum type for remapping

Currently this is used similarly to category. As we get more remapping
features (booleans, strings etc) this will be different from
categories and won't have the existing category baggage.
parent a739373a
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,8 @@
(and (not (contains? #{:retired :sensitive :hidden :details-only} (keyword visibility_type)))
(not (isa? (keyword base_type) :type/DateTime))
(or (isa? (keyword base_type) :type/Boolean)
(isa? (keyword special_type) :type/Category))))
(isa? (keyword special_type) :type/Category)
(isa? (keyword special_type) :type/Enum))))
(defn- create-field-values!
"Create `FieldValues` for a `Field`."
......
......@@ -60,6 +60,7 @@
;;; Other
(derive :type/Boolean :type/*)
(derive :type/Enum :type/*)
;;; Text-Like Types: Things that should be displayed as text for most purposes but that *shouldn't* support advanced filter options like starts with / contains
......
......@@ -501,10 +501,10 @@
"Field values will only be returned when the field's special type is
set to type/Category. This function will change that for
category_id, then invoke `F` and roll it back afterwards"
[f]
[special-type f]
(let [original-special-type (:special_type (Field (id :venues :category_id)))]
(try
(db/update! Field (id :venues :category_id) {:special_type :type/Category})
(db/update! Field (id :venues :category_id) {:special_type special-type})
(f)
(finally
(db/update! Field (id :venues :category_id) {:special_type original-special-type})))))
......@@ -525,6 +525,28 @@
(with-data
(create-venue-category-remapping "Foo")
(category-id-special-type
:type/Category
(fn []
(narrow-fields ["PRICE" "CATEGORY_ID"]
((user->client :rasta) :get 200 (format "table/%d/query_metadata" (id :venues))))))))
;; ## GET /api/table/:id/query_metadata
;; Ensure internal remapped dimensions and human_readable_values are returned when type is enum
(expect
[{:table_id (id :venues)
:id (id :venues :category_id)
:name "CATEGORY_ID"
:values (map-indexed (fn [idx [category]] [idx category]) venue-categories)
:dimensions {:name "Foo", :field_id (id :venues :category_id), :human_readable_field_id nil, :type "internal"}}
{:id (id :venues :price)
:table_id (id :venues)
:name "PRICE"
:values [[1] [2] [3] [4]]
:dimensions []}]
(with-data
(create-venue-category-remapping "Foo")
(category-id-special-type
:type/Enum
(fn []
(narrow-fields ["PRICE" "CATEGORY_ID"]
((user->client :rasta) :get 200 (format "table/%d/query_metadata" (id :venues))))))))
......@@ -545,6 +567,7 @@
(with-data
(create-venue-category-fk-remapping "Foo")
(category-id-special-type
:type/Category
(fn []
(narrow-fields ["PRICE" "CATEGORY_ID"]
((user->client :rasta) :get 200 (format "table/%d/query_metadata" (id :venues))))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment