Skip to content
Snippets Groups Projects
Unverified Commit 935a5429 authored by Ryan Senior's avatar Ryan Senior Committed by GitHub
Browse files

Merge pull request #8653 from paychex/field-filter-required-option

Allow the option to make field filter values required
parents 67733a07 6206257f
No related branches found
No related tags found
No related merge requests found
......@@ -197,7 +197,6 @@ export default class TagEditorParam extends Component {
</div>
)}
{tag.type !== "dimension" && (
<div className="flex align-center pb1">
<h5 className="text-normal mr1">{t`Required?`}</h5>
<Toggle
......@@ -205,7 +204,6 @@ export default class TagEditorParam extends Component {
onChange={value => this.setRequired(value)}
/>
</div>
)}
{((tag.type !== "dimension" && tag.required) ||
(tag.type === "dimension" || tag["widget-type"])) && (
......
......@@ -154,6 +154,8 @@
(s/defn ^:private default-value-for-dimension :- (s/maybe DimensionValue)
"Return the default value for a Dimension (Field Filter) param defined by the map TAG, if one is set."
[tag :- TagParam]
(when (and (:required tag) (not (:default tag)))
(throw (Exception. (str (tru "''{0}'' is a required param." (:display-name tag))))))
(when-let [default (:default tag)]
{:type (:widget-type tag :dimension) ; widget-type is the actual type of the default value if set
:target [:dimension [:template-tag (:name tag)]]
......
......@@ -319,6 +319,26 @@
(into {} (#'sql/value-for-tag {:name "checkin_date", :display-name "Checkin Date", :type :dimension, :dimension [:field-id (data/id :checkins :date)]}
nil)))
;; dimension -- required but unspecified
(expect Exception
(into {} (#'sql/value-for-tag {:name "checkin_date", :display-name "Checkin Date", :type "dimension", :required true,
:dimension ["field-id" (data/id :checkins :date)]}
nil)))
;; dimension -- required and default specified
(expect
{:field {:name "DATE"
:parent_id nil
:table_id (data/id :checkins)
:base_type :type/Date}
:param {:type :dimension
:target [:dimension [:template-tag "checkin_date"]]
:value "2015-04-01~2015-05-01"}}
(into {} (#'sql/value-for-tag {:name "checkin_date", :display-name "Checkin Date", :type :dimension, :required true, :default "2015-04-01~2015-05-01",
:dimension [:field-id (data/id :checkins :date)]}
nil)))
;; multiple values for the same tag should return a vector with multiple params instead of a single param
(expect
{:field {:name "DATE"
......
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