Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 9c5f73a

Browse files
gregoneizaaklauer
authored andcommitted
UI: fix config var renaming (#2421)
* delete renamed var after edition
1 parent 4fd549d commit 9c5f73a

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

Diff for: .changelog/2421.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
ui: fixed config variable duplication when renaming
3+
```

Diff for: ui/app/components/project-config-variables/list-item.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import Component from '@glimmer/component';
2-
import { tracked } from '@glimmer/tracking';
3-
import { action } from '@ember/object';
41
import { ConfigVar, Project } from 'waypoint-pb';
5-
import { inject as service } from '@ember/service';
2+
63
import ApiService from 'waypoint/services/api';
4+
import Component from '@glimmer/component';
75
import FlashMessagesService from 'waypoint/services/pds-flash-messages';
6+
import { action } from '@ember/object';
7+
import { inject as service } from '@ember/service';
8+
import { tracked } from '@glimmer/tracking';
89

910
interface VariableArgs {
1011
variable: ConfigVar.AsObject;
@@ -60,7 +61,13 @@ export default class ProjectConfigVariablesListItemComponent extends Component<V
6061
this.flashMessages.error('Variable keys or values can not be empty');
6162
return;
6263
}
63-
await this.args.saveVariableSettings(this.variable, false);
64+
if (this.initialVariable.name !== this.variable.name) {
65+
await this.args.saveVariableSettings(this.variable, false);
66+
await this.args.deleteVariable(this.initialVariable);
67+
this.storeInitialVariable();
68+
} else {
69+
await this.args.saveVariableSettings(this.variable, false);
70+
}
6471
this.isCreating = false;
6572
this.isEditing = false;
6673
}

Diff for: ui/app/components/project-config-variables/list.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { ConfigGetRequest, ConfigSetRequest, ConfigVar, Project, Ref } from 'waypoint-pb';
2+
3+
import ApiService from 'waypoint/services/api';
14
import Component from '@glimmer/component';
2-
import { tracked } from '@glimmer/tracking';
3-
import { action } from '@ember/object';
4-
import { ConfigSetRequest, ConfigGetRequest, ConfigVar, Project, Ref } from 'waypoint-pb';
55
import { Empty } from 'google-protobuf/google/protobuf/empty_pb';
6-
import { inject as service } from '@ember/service';
7-
import ApiService from 'waypoint/services/api';
86
import FlashMessagesService from 'waypoint/services/pds-flash-messages';
7+
import { action } from '@ember/object';
8+
import { inject as service } from '@ember/service';
9+
import { tracked } from '@glimmer/tracking';
910

1011
interface ProjectConfigArgs {
1112
variablesList: ConfigVar.AsObject[];

Diff for: ui/tests/integration/components/project-config-variables-list-test.ts

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { clickable, collection, create, fillable, isPresent, text } from 'ember-cli-page-object';
12
import { module, test } from 'qunit';
2-
import { setupRenderingTest } from 'ember-qunit';
3-
import { setupMirage } from 'ember-cli-mirage/test-support';
4-
import { render, settled } from '@ember/test-helpers';
3+
import { pauseTest, render, settled } from '@ember/test-helpers';
4+
55
import { TestContext } from 'ember-test-helpers';
66
import hbs from 'htmlbars-inline-precompile';
7-
import { create, collection, clickable, isPresent, fillable, text } from 'ember-cli-page-object';
7+
import { setupMirage } from 'ember-cli-mirage/test-support';
8+
import { setupRenderingTest } from 'ember-qunit';
89

910
const page = create({
1011
hasForm: isPresent('[data-test-config-variables-form]'),
@@ -113,4 +114,33 @@ module('Integration | Component | project-config-variables-list', function (hook
113114
assert.ok(page.variablesList.objectAt(0).hasDropDownEdit, 'Static Variable is editable');
114115
assert.notOk(page.variablesList.objectAt(3).hasDropDown, 'Dynamic Variable is not editable or deletable');
115116
});
117+
118+
test('renaming variables works', async function (assert) {
119+
let dbproj = await this.server.create('project', { name: 'Proj1' });
120+
let proj = dbproj.toProtobuf().toObject();
121+
let dbVariablesList = this.server.createList('config-variable', 3, 'random', { project: dbproj });
122+
let dynamicVar = this.server.create('config-variable', 'dynamic', { project: dbproj });
123+
dbVariablesList.push(dynamicVar);
124+
let varList = dbVariablesList.map((v) => {
125+
return v.toProtobuf().toObject();
126+
});
127+
this.set('variablesList', varList);
128+
this.set('project', proj);
129+
await render(
130+
hbs`<ProjectConfigVariables::List @variablesList={{this.variablesList}} @project={{this.project}}/>`
131+
);
132+
assert.equal(page.variablesList.length, 4, 'the list contains the right number of variables');
133+
await page.variablesList.objectAt(0).dropdown();
134+
await page.variablesList.objectAt(0).dropdownEdit();
135+
await page.varName('edited_var_name');
136+
await page.saveButton();
137+
// Necessary to wait for the next request after save
138+
await settled();
139+
await page.variablesList.objectAt(1).dropdown();
140+
assert.equal(
141+
page.variablesList.length,
142+
4,
143+
'the list contains the right number of variables after name edition'
144+
);
145+
});
116146
});

0 commit comments

Comments
 (0)