Skip to content

Commit

Permalink
Merge c1d7ec2 into ad9ae87
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOtherDude committed Jan 11, 2018
2 parents ad9ae87 + c1d7ec2 commit dd5928a
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 20 deletions.
12 changes: 8 additions & 4 deletions addon/components/array-inline-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export default Component.extend(HookMixin, PropTypeMixin, {
}
},

getCell (arrayOptions, index) {
return get(arrayOptions, `tupleCells.${index}`) ||
get(arrayOptions, `itemCell.${index}`) ||
arrayOptions.itemCell
},

@readOnly
@computed('formDisabled', 'cellConfig')
disabled (formDisabled, cellConfig) {
Expand Down Expand Up @@ -101,16 +107,14 @@ export default Component.extend(HookMixin, PropTypeMixin, {

@readOnly
@computed('cellConfig', 'index')
itemCell (cellConfig, index, bunsenModel) {
itemCell (cellConfig, index) {
const arrayOptions = get(cellConfig, 'arrayOptions')

if (!isPresent(arrayOptions)) {
return {}
}

const cell = get(arrayOptions, `tupleCells.${index}`) ||
get(arrayOptions, `itemCell.${index}`) ||
arrayOptions.itemCell
const cell = this.getCell(arrayOptions, index)

return isPresent(cell) && !Array.isArray(cell) ? cell : {}
},
Expand Down
2 changes: 2 additions & 0 deletions addon/components/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export default Component.extend(HookMixin, PropTypeMixin, {

@readOnly
@computed('cellConfig', 'bunsenModel.type')
/* eslint-disable complexity */
showSection (cellConfig, type) {
const isArrayCell = type === 'array' && cellConfig.renderer === undefined
return (
Expand All @@ -280,6 +281,7 @@ export default Component.extend(HookMixin, PropTypeMixin, {
(isArrayCell && !cellConfig.hideLabel)
)
},
/* eslint-enable complexity */

@readOnly
@computed('cellConfig.model', 'children')
Expand Down
2 changes: 2 additions & 0 deletions addon/components/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ export default Component.extend(SpreadMixin, HookMixin, PropTypeMixin, {
return batchedChanges
},

/* eslint-disable complexity */
/**
* Get the view to render (generate one if consumer doesn't supply a view)
* @param {BunsenModel} model - the model schema to use to generate a view (if view is undefined)
Expand All @@ -339,6 +340,7 @@ export default Component.extend(SpreadMixin, HookMixin, PropTypeMixin, {

return normalizeView(view)
},
/* eslint-enable complexity */

/**
* Inform renderers that registered to be notified of form value changes of
Expand Down
2 changes: 2 additions & 0 deletions addon/input-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function getAttr (attrs, name) {
return get(attrs, `${firstSegment}.value.${remainingPath}`)
}

/* eslint-disable complexity */
export function getOption (attrs, optionName, formValue, fallback = '', useValue = true) {
if (!attrs) {
return undefined
Expand All @@ -36,3 +37,4 @@ export function getOption (attrs, optionName, formValue, fallback = '', useValue

return parseVariables(mutableFormValue, configOption, bunsenId, true) || fallback
}
/* eslint-enable complexity */
6 changes: 5 additions & 1 deletion addon/list-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export function getItemsFromAjaxCall ({ajax, bunsenId, data, filter, options, va
})
}

/* eslint-disable complexity */
/**
* Fetch the list of network functions from the backend and set them
* @param {Object} value the bunsen value for this form
Expand Down Expand Up @@ -186,13 +187,16 @@ export function getItemsFromEmberData ({value, modelDef, data, bunsenId, store,

if (arrayRecords) {
const recordsToAdd = arrayRecords.filter(record => {
return shouldAddCurrentValue({items, valueRecord: record, labelAttribute, valueAttribute, filter})
// Note: filtering current values out of multi-select data would clear those selections,
// so we ignore the filter in this case (@theotherdude 1/10/2018)
return shouldAddCurrentValue({items, valueRecord: record, labelAttribute, valueAttribute, filter: ''})
})
return normalizeItems({data: items, labelAttribute, records: recordsToAdd, valueAttribute})
}
return items
})
}
/* eslint-enable complexity */

/**
* Fetch the list of items from elsewhere in the form value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
valueChangeSet=valueChangeSet
}}
{{else}}
{{log label}}
{{frost-bunsen-input-wrapper
bunsenId=bunsenId
bunsenModel=bunsenModel
Expand Down
2 changes: 2 additions & 0 deletions addon/tree-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function traverseCell (cell, iteratee) {
}
}

/* eslint-disable complexity */
/**
* Post-order breadth-first traversal
* @param {Object} object - cellConfig
Expand Down Expand Up @@ -185,6 +186,7 @@ export function traverseCellBreadthFirst (object, iteratee) {
iteratee(obj)
}
}
/* eslint-enable complexity */

/**
* Traverses an object, ignoring arrays
Expand Down
2 changes: 2 additions & 0 deletions addon/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export function validateRenderer (owner, rendererName) {
return rendererName in builtInRenderers || owner.hasRegistration(`component:${rendererName}`)
}

/* eslint-disable complexity */
/**
* Get an error message from an error Object
* @param {Object} error - may be an Error, an API response, or anything else (maybe?)
Expand All @@ -386,6 +387,7 @@ export function getErrorMessage (error) {

return message
}
/* eslint-enable complexity */

/**
* Used to sanity check if the path to the model is valid
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module.exports = {
name: 'ember-frost-bunsen',

/* eslint-disable complexity */
init: function (app) {
this.options = this.options || {}
this.options.babel = this.options.babel || {}
Expand All @@ -17,4 +18,5 @@ module.exports = {
this._super.init && this._super.init.apply(this, arguments)
/* eslint-enable no-unused-expressions */
}
/* eslint-enable complexity */
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"ember-simple-uuid": "0.1.4",
"ember-sinon": "0.6.0",
"ember-source": "~2.12.0",
"ember-test-utils": "^6.0.0",
"ember-test-utils": "^8.1.0",
"ember-truth-helpers": "^1.2.0",
"ember-try": "0.2.11",
"eslint": "^3.13.1",
Expand Down Expand Up @@ -118,4 +118,4 @@
"ember-frost-icon-pack": {
"name": "frost-bunsen"
}
}
}
20 changes: 10 additions & 10 deletions tests/dummy/app/pods/view/renderers/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@
</div>
</div>
</div>
{{#unless (eq selectedTab "doc")}}
{{#if (eq selectedTab "doc")}}
<div class="demo-doc">
{{markdown-to-html
ghCodeBlocks=true
markdown=documentation
tables=true
}}
</div>
{{else}}
<div class="demo-code">
{{ivy-codemirror
options=(hash
Expand All @@ -43,15 +51,7 @@
value=code
}}
</div>
{{else}}
<div class="demo-doc">
{{markdown-to-html
ghCodeBlocks=true
markdown=documentation
tables=true
}}
</div>
{{/unless}}
{{/if}}
</div>
<div class="demo-view">
<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
expectOnValidationState
} from 'dummy/tests/helpers/ember-frost-bunsen'

import {expectSelectWithState} from 'dummy/tests/helpers/ember-frost-core'
import {expectSelectWithState, filterSelect} from 'dummy/tests/helpers/ember-frost-core'
import selectors from 'dummy/tests/helpers/selectors'

describe('Integration: Component / frost-bunsen-form / renderer / multi-select view queryForCurrentValue', function () {
Expand Down Expand Up @@ -874,6 +874,33 @@ describe('Integration: Component / frost-bunsen-form / renderer / multi-select v
})
})

describe('when filter excludes initial value', function () {
beforeEach(function () {
filterSelect('b')
return wait().then(() => {
queryResolver.resolve([
Ember.Object.create({
label: 'bar',
value: 1
}),
Ember.Object.create({
label: 'baz',
value: 2
})
])
findRecordResolver.resolve(Ember.Object.create({
label: 'foo',
value: 42
}))
return wait()
})
})

it('should still show selected value', function () {
expect($hook('my-form-foo').find('.frost-select-text').text().trim()).to.equal('foo')
})
})

describe('when last option selected (initial value)', function () {
beforeEach(function () {
props.onChange.reset()
Expand Down Expand Up @@ -1526,6 +1553,33 @@ describe('Integration: Component / frost-bunsen-form / renderer / multi-select v
})
})

describe('when filter excludes initial value', function () {
beforeEach(function () {
filterSelect('b')
return wait().then(() => {
queryResolver.resolve([
Ember.Object.create({
label: 'bar',
value: 1
}),
Ember.Object.create({
label: 'baz',
value: 2
})
])
findRecordResolver.resolve(Ember.Object.create({
label: 'foo',
value: 42
}))
return wait()
})
})

it('should still show selected value', function () {
expect($hook('my-form-foo').find('.frost-select-text').text().trim()).to.equal('foo')
})
})

describe('when last option selected (initial value)', function () {
beforeEach(function () {
props.onChange.reset()
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/list-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1412,13 +1412,15 @@ describe('Unit: list-utils', function () {
expect(error).to.equal(undefined)
})

it('should return the proper options', function () {
it('should return the proper options, including the current value', function () {
// Filtering out the current value would clear its selection in a multi-select (@theotherdude 1/10/2018)
expect(options).to.eql([
{value: 1, label: 'Batman'},
{value: 2, label: 'Superman'},
{value: 3, label: 'Green Lantern'},
{value: 4, label: 'Flash'},
{value: 5, label: 'Green Arrow'},
{value: 42, label: 'Atom Smasher'},
{value: 43, label: 'Quark Smasher'}
])
})
Expand Down

0 comments on commit dd5928a

Please sign in to comment.