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

Remove the category type predicate from remapping

The logic predates remapping, but since remapping used human readable
values, the predicates were kept in place. This commit changes that to
generate field values if it is not present and the user has asked for it.
parent c6be4a36
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
[metabase.models
[dimension :refer [Dimension]]
[field :as field :refer [Field]]
[field-values :refer [create-field-values-if-needed! field-should-have-field-values? field-values->pairs FieldValues]]]
[field-values :refer [create-field-values-if-needed! field-values->pairs FieldValues]]]
[metabase.util :as u]
[metabase.util.schema :as su]
[schema.core :as s]
......@@ -70,15 +70,11 @@
"If `Field`'s special type derives from `type/Category`, or its base type is `type/Boolean`, return
all distinct values of the field, and a map of human-readable values defined by the user."
[id]
(try
(let [field (api/read-check Field id)]
(if-let [field-values (and (field-should-have-field-values? field)
(create-field-values-if-needed! field))]
(-> field-values
(assoc :values (field-values->pairs field-values))
(dissoc :human_readable_values))
{:values []}))
(catch Exception e (.printStackTrace e) (throw e))))
(let [field (api/read-check Field id)
field-values (create-field-values-if-needed! field)]
(-> field-values
(assoc :values (field-values->pairs field-values))
(dissoc :human_readable_values))))
(api/defendpoint POST "/:id/dimension"
"Sets the dimension for the given field at ID"
......@@ -140,8 +136,6 @@
[id :as {{value-pairs :values} :body}]
{value-pairs [[(s/one s/Num "value") (s/optional su/NonBlankString "human readable value")]]}
(let [field (api/write-check Field id)]
(api/check (field-should-have-field-values? field)
[400 "You can only update the human readable values of a mapped values of a Field whose 'special_type' is 'category'/'city'/'state'/'country' or whose 'base_type' is 'type/Boolean'."])
(if-let [field-value-id (db/select-one-id FieldValues, :field_id id)]
(update-field-values! field-value-id value-pairs)
(create-field-values! field value-pairs)))
......
......@@ -52,8 +52,7 @@
(defn update-field-values!
"Update the `FieldValues` for FIELD, creating them if needed"
[{field-id :id, :as field}]
{:pre [(integer? field-id)
(field-should-have-field-values? field)]}
{:pre [(integer? field-id)]}
(if-let [field-values (FieldValues :field_id field-id)]
(db/update! FieldValues (u/get-id field-values)
:values ((resolve 'metabase.db.metadata-queries/field-distinct-values) field))
......@@ -73,9 +72,8 @@
{:arglists '([field] [field human-readable-values])}
[{field-id :id :as field} & [human-readable-values]]
{:pre [(integer? field-id)]}
(when (field-should-have-field-values? field)
(or (FieldValues :field_id field-id)
(create-field-values! field human-readable-values))))
(or (FieldValues :field_id field-id)
(create-field-values! field human-readable-values)))
(defn save-field-values!
"Save the `FieldValues` for FIELD-ID, creating them if needed, otherwise updating them."
......
......@@ -162,11 +162,6 @@
;; now update the values via the API
(tu/boolean-ids-and-timestamps ((user->client :rasta) :get 200 (format "field/%d/values" (id :venues :price))))))
;; Should return nothing for a field whose special_type is *not* :type/Category
(expect
{:values []}
((user->client :rasta) :get 200 (format "field/%d/values" (id :venues :id))))
(defn- num->$ [num-seq]
(mapv (fn [idx]
(vector idx (apply str (repeat idx \$))))
......
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