Configurable Field Set
Functions to determine column visibility and requiredness.
Usage
isVisible(Object)(Object)(String) => Boolean
A function for checking if a column is visible or not. Returns true
if the item cannot be found.
isVisible = (
// defines frontend names to match to the corresponding
// backend configurable_field_set field names
nameMapObj: { someName: 'field_set_name' },
) => (
// the object of configurable_field_set field names
sourceOfValuesObj: { field_set_name: { visible: Boolean } },
) => (
'someName'
) =>
returns Boolean
isRequired(Object)(Object)(String) => Boolean
A function for checking if a column is required or not. Returns false
if the item cannot be found.
isRequired = (
// defines frontend names to match to the corresponding
// backend configurable_field_set field names
nameMapObj: { someName: 'field_set_name' },
) => (
// the object of configurable_field_set field names
sourceOfValuesObj: { field_set_name: { required: Boolean } },
) => (
'someName'
) =>
returns Boolean
filterVisibleColumns(Object)(Object)(Array, String) => Array
A function for filtering an array of columns to only visible columns.
filterVisibleColumns = (
// defines frontend names to match the corresponding
// backend configurable_field_set field names
nameMapObj: { someName: 'field_set_name' },
) => (
// the object of configurable_field_set field names
sourceOfValuesObj: { field_set_name: { visible: Boolean } },
) => (
// some arbitrary array of columns
columnsArr = [{ [colKey]: 'someName' }],
colKey: 'key' // defaults to 'key'
) =>
returns []
aggregateVisibility(Array) => Object
A function that takes in an array of CFS fields objects and returns a new set of fields where the visibility of each field is set to true if ANY of the input fieldsets have that field set to "visible: true", otherwise set to false.
aggregateVisibility = (
[
{ name: { visible: true }, status: { visible: true }, contact: { visible: false }},
{ name: { visible: true }, status: { visible: false }, contact: { visible: false }},
],
) =>
returns {} // { name: { visible: true }, status: { visible: true }, contact: { visible: false } }
Change Log
0.3.2
- Added aggregateVisibility() method
0.3.0
-
Breaking The second argument to the second function,
'visible'
, has been removed fromisVisible()(undefined, 'visible')()
. This is in order to determine keys sooner -
Breaking The second argument to the first function,
true
, has been removed fromisVisible(undefined, true)()()
. This is in order to determine defaults for different keys sooner -
Breaking The second argument to the second function,
true
, has been removed fromfilterVisibleColumns()(undefined, true)()
. This is in order to determine defaults for different keys sooner - added
isRequired
0.2.1
-
Breaking The names of functions switched.
visibleColumns
is nowfilterVisibleColumns
, already knowing it's filter func. AndfilterVisibleColumns
is nowvisibleColumns
, needing a filter func - added isVisible function for non array checks
0.2.0
- unpublished
0.1.1
- Added false/empty visibleObj check to avoid filter call
0.1.0
- Initial commit