@wmfs/cardscript-extract-defaults
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -0,1 +1,23 @@ | ||
## [1.1.1](https://github.com/wmfs/cardscript-extract-defaults/compare/v1.1.0...v1.1.1) (2019-02-27) | ||
### 🐛 Bug Fixes | ||
* tests ([816b949](https://github.com/wmfs/cardscript-extract-defaults/commit/816b949)) | ||
### 🛠 Builds | ||
* update dev deps ([eb0450b](https://github.com/wmfs/cardscript-extract-defaults/commit/eb0450b)) | ||
### 📦 Code Refactoring | ||
* progress on input.apilookup ([15180f5](https://github.com/wmfs/cardscript-extract-defaults/commit/15180f5)) | ||
* reduce code ([80e6989](https://github.com/wmfs/cardscript-extract-defaults/commit/80e6989)) | ||
* simplifying code ([f9c2097](https://github.com/wmfs/cardscript-extract-defaults/commit/f9c2097)) | ||
* simplifying code ([bf346ed](https://github.com/wmfs/cardscript-extract-defaults/commit/bf346ed)) | ||
* start of refactoring for input.apilookup but needs more refactoring! ([a6ee0c5](https://github.com/wmfs/cardscript-extract-defaults/commit/a6ee0c5)) | ||
* WIP adjusted cardscript table to allow opening modal ([7057a24](https://github.com/wmfs/cardscript-extract-defaults/commit/7057a24)) | ||
# [1.1.0](https://github.com/wmfs/cardscript-extract-defaults/compare/v1.0.0...v1.1.0) (2019-01-25) | ||
@@ -2,0 +24,0 @@ |
134
lib/index.js
module.exports = function extractDefaults (cardscript) { | ||
const apiLookupPath = [] | ||
const cardListPath = [] | ||
@@ -9,2 +10,4 @@ const defaultValues = { | ||
function parseElement (element) { | ||
const defaultValue = extractDefaultValue(element) | ||
switch (element.type) { | ||
@@ -17,2 +20,5 @@ case 'Container': | ||
break | ||
case 'Column': | ||
element.items.forEach(parseElement) | ||
break | ||
case 'FactSet': | ||
@@ -24,3 +30,23 @@ element.facts.forEach(parseElement) | ||
break | ||
case 'Input.ApiLookup': | ||
defaultValues.rootView[element.id] = { | ||
loading: false, | ||
summary: { | ||
totalHits: 0 | ||
}, | ||
results: [], | ||
pagination: { | ||
page: 1, | ||
totalPages: 0 | ||
} | ||
} | ||
if (element.parametersCard) { | ||
apiLookupPath.push(element.id) | ||
defaultValues.rootView[element.id].params = {} | ||
element.parametersCard.body.forEach(parseElement) | ||
apiLookupPath.pop() | ||
} | ||
break | ||
case 'CardList': | ||
// todo: apiLookupPath | ||
if (element.editable) { | ||
@@ -40,5 +66,2 @@ if (cardListPath.length === 0) { | ||
break | ||
case 'Column': | ||
element.items.forEach(parseElement) | ||
break | ||
case 'Input.Date': | ||
@@ -49,59 +72,27 @@ case 'Input.Number': | ||
case 'Input.Time': | ||
if (element.value === 0 || element.value) { | ||
case 'Input.ChoiceSet': | ||
case 'Input.Toggle': | ||
if (defaultValue !== undefined) { | ||
if (cardListPath.length === 0) { | ||
defaultValues.rootView[element.id] = element.value | ||
if (apiLookupPath.length === 0) { | ||
defaultValues.rootView[element.id] = defaultValue | ||
} else { | ||
const apiLookupId = apiLookupPath[apiLookupPath.length - 1] | ||
defaultValues.rootView[apiLookupId].params[element.id] = defaultValue | ||
} | ||
} else { | ||
const cardListId = cardListPath[cardListPath.length - 1] | ||
defaultValues.cardLists[cardListId][element.id] = element.value | ||
if (apiLookupPath.length === 0) { | ||
const cardListId = cardListPath[cardListPath.length - 1] | ||
defaultValues.cardLists[cardListId][element.id] = defaultValue | ||
} else { | ||
// not sure about this... | ||
const apiLookupId = apiLookupPath[apiLookupPath.length - 1] | ||
const cardListId = cardListPath[cardListPath.length - 1] | ||
defaultValues.cardLists[apiLookupId].params[cardListId][element.id] = defaultValue | ||
} | ||
} | ||
} else if (element.type === 'Input.Text') { | ||
if (cardListPath.length === 0) { | ||
defaultValues.rootView[element.id] = '' | ||
} else { | ||
const cardListId = cardListPath[cardListPath.length - 1] | ||
defaultValues.cardLists[cardListId][element.id] = '' | ||
} | ||
} | ||
break | ||
case 'Input.Toggle': | ||
if (cardListPath.length === 0) { | ||
if (element.value === 'false') { | ||
defaultValues.rootView[element.id] = false | ||
} else if (element.value === 'true') { | ||
defaultValues.rootView[element.id] = true | ||
} else if (element.value) { | ||
defaultValues.rootView[element.id] = element.value | ||
} else { | ||
defaultValues.rootView[element.id] = false | ||
} | ||
} else { | ||
const cardListId = cardListPath[cardListPath.length - 1] | ||
if (element.value === 'false') { | ||
defaultValues.cardLists[cardListId][element.id] = false | ||
} else if (element.value === 'true') { | ||
defaultValues.cardLists[cardListId][element.id] = true | ||
} else if (element.value) { | ||
defaultValues.cardLists[cardListId][element.id] = element.value | ||
} else { | ||
defaultValues.cardLists[cardListId][element.id] = false | ||
} | ||
} | ||
break | ||
case 'Input.ChoiceSet': | ||
if (cardListPath.length === 0) { | ||
if (element.isMultiSelect) { | ||
defaultValues.rootView[element.id] = element.value ? element.value.split(',') : [] | ||
} else if (element.value) { | ||
defaultValues.rootView[element.id] = element.value | ||
} | ||
} else { | ||
const cardListId = cardListPath[cardListPath.length - 1] | ||
if (element.isMultiSelect) { | ||
defaultValues.cardLists[cardListId][element.id] = element.value ? element.value.split(',') : [] | ||
} else if (element.value) { | ||
defaultValues.cardLists[cardListId][element.id] = element.value | ||
} | ||
} | ||
break | ||
case 'Input.Address': | ||
// todo: apiLookupPath | ||
if (cardListPath.length === 0) { | ||
@@ -115,2 +106,3 @@ defaultValues.rootView[element.id + 'SearchResults'] = [] | ||
case 'Input.Signature': | ||
// todo: apiLookupPath | ||
if (cardListPath.length === 0) { | ||
@@ -123,2 +115,13 @@ defaultValues.rootView[element.id + 'OpenModal'] = false | ||
break | ||
case 'Table': | ||
// todo: apiLookupPath | ||
if (element.openable) { | ||
if (cardListPath.length === 0) { | ||
defaultValues.rootView[element.id + 'OpenModal'] = false | ||
} else { | ||
const cardListId = cardListPath[cardListPath.length - 1] | ||
defaultValues.cardLists[cardListId][element.id + 'OpenModal'] = false | ||
} | ||
} | ||
break | ||
} | ||
@@ -131,1 +134,24 @@ } | ||
} | ||
function extractDefaultValue ({ type, value, isMultiSelect }) { | ||
let defaultValue = value | ||
if (isMultiSelect) { | ||
defaultValue = value ? value.split(',') : [] | ||
} | ||
if (type === 'Input.Text' && value === undefined) { | ||
defaultValue = '' | ||
} | ||
if (type === 'Input.Toggle') { | ||
if (value !== undefined) { | ||
if (value === 'true') defaultValue = true | ||
if (value === 'false') defaultValue = false | ||
} else { | ||
defaultValue = false | ||
} | ||
} | ||
return defaultValue | ||
} |
{ | ||
"name": "@wmfs/cardscript-extract-defaults", | ||
"description": "Extracts sensible defaults from some Cardscript.", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"author": "West Midlands Fire Service", | ||
@@ -22,3 +22,3 @@ "keywords": [ | ||
"@semantic-release/git": "7.0.8", | ||
"@wmfs/cardscript-examples": "1.0.0" | ||
"@wmfs/cardscript-examples": "1.3.0" | ||
}, | ||
@@ -25,0 +25,0 @@ "scripts": { |
@@ -56,3 +56,18 @@ /* eslint-env mocha */ | ||
inputAddressSearchResults: [], | ||
inputSignatureOpenModal: false | ||
inputSignatureOpenModal: false, | ||
inputApiLookup: { | ||
loading: false, | ||
params: { | ||
searchQuery: '', | ||
sortBy: 'MOST_RECENT' | ||
}, | ||
results: [], | ||
pagination: { | ||
page: 1, | ||
totalPages: 0 | ||
}, | ||
summary: { | ||
totalHits: 0 | ||
} | ||
} | ||
}, | ||
@@ -59,0 +74,0 @@ cardLists: { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16517
269