Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ui search select fix #7338

Merged
merged 3 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ui/app/components/identity/edit-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export default Component.extend({
onSave: () => {},

cancelLink: computed('mode', 'model.identityType', function() {
let { model, mode } = this.getProperties('model', 'mode');
let key = `${mode}-${model.get('identityType')}`;
let { model, mode } = this;
let routes = {
'create-entity': 'vault.cluster.access.identity',
'edit-entity': 'vault.cluster.access.identity.show',
Expand All @@ -33,25 +32,25 @@ export default Component.extend({
'create-group-alias': 'vault.cluster.access.identity.aliases',
'edit-group-alias': 'vault.cluster.access.identity.aliases.show',
};

let key = model ? `${mode}-${model.identityType}` : 'merge-entity-alias';
return routes[key];
}),

getMessage(model, isDelete = false) {
let mode = this.get('mode');
let typeDisplay = humanize([model.get('identityType')]);
let mode = this.mode;
let typeDisplay = humanize([model.identityType]);
let action = isDelete ? 'deleted' : 'saved';
if (mode === 'merge') {
return 'Successfully merged entities';
}
if (model.get('id')) {
if (model.id) {
return `Successfully ${action} ${typeDisplay} ${model.id}.`;
}
return `Successfully ${action} ${typeDisplay}.`;
},

save: task(function*() {
let model = this.get('model');
let model = this.model;
let message = this.getMessage(model);

try {
Expand All @@ -67,7 +66,8 @@ export default Component.extend({
.withTestWaiter(),

willDestroy() {
let model = this.get('model');
let model = this.model;
if (!model) return;
if ((model.get('isDirty') && !model.isDestroyed) || !model.isDestroying) {
model.rollbackAttributes();
}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/search-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default Component.extend({
return `Add new ${singularize(this.label)}: ${id}`;
},
hideCreateOptionOnSameID(id) {
let existingOption = this.options.findBy('id', id) || this.options.findBy('name', id);
let existingOption = this.options && (this.options.findBy('id', id) || this.options.findBy('name', id));
return !existingOption;
},
},
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"ember-load-initializers": "^2.0.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-maybe-in-element": "^0.4.0",
"ember-power-select-with-create": "cibernox/ember-power-select-with-create#6203918f247c1c5d692db4f9185ab8321d2125e1",
"ember-power-select-with-create": "^0.6.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yesssssss 💅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we'll be able to backport the upgrade, but the same code fixes should still work

"ember-qunit": "^4.4.1",
"ember-radio-button": "^2.0.1",
"ember-resolver": "^5.0.1",
Expand Down
12 changes: 12 additions & 0 deletions ui/tests/integration/components/search-select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ module('Integration | Component | search select', function(hooks) {
assert.equal(component.options.objectAt(0).text, 'Type to search', 'text of option shows Type to search');
});

test('it shows add suggestion if there are no options', async function(assert) {
const models = [];
this.set('models', models);
this.set('onChange', sinon.spy());
await render(
hbs`{{search-select label="foo" inputValue=inputValue models=models fallbackComponent="string-list" onChange=onChange}}`
);
await clickTrigger();

await typeInSearch('new item');
assert.equal(component.options.objectAt(0).text, 'Add new foo: new item', 'shows the create suggestion');
});
test('it shows items not in the returned response', async function(assert) {
const models = ['test'];
this.set('models', models);
Expand Down
11 changes: 6 additions & 5 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7321,12 +7321,13 @@ ember-native-dom-helpers@^0.5.3:
broccoli-funnel "^1.1.0"
ember-cli-babel "^6.6.0"

ember-power-select-with-create@cibernox/ember-power-select-with-create#6203918f247c1c5d692db4f9185ab8321d2125e1:
version "0.6.1"
resolved "https://codeload.github.com/cibernox/ember-power-select-with-create/tar.gz/6203918f247c1c5d692db4f9185ab8321d2125e1"
ember-power-select-with-create@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/ember-power-select-with-create/-/ember-power-select-with-create-0.6.2.tgz#05faf361c435f5c2c61c24e687aebddefd569897"
integrity sha512-8OKUJWpLTImP+N+SkUqTYJByaZ7XDhePdhjqZtcimc6O1eEAdEGkh8itOLMLw95+X51Wua1DwfdoRycu+iqqQQ==
dependencies:
ember-cli-babel "^6.6.0"
ember-cli-htmlbars "^2.0.1"
ember-cli-babel "^7.1.2"
ember-cli-htmlbars "^3.0.0"
ember-power-select "^2.0.0"

ember-power-select@^2.0.0:
Expand Down