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

Commit

Permalink
Merge pull request #2250 from hashicorp/ui/bugfix-leaky-settings
Browse files Browse the repository at this point in the history
Fix overwriting default project model
  • Loading branch information
gregone authored Sep 8, 2021
2 parents d1fdafb + 1380b02 commit 3559dd7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/2250.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: fix leaky project repository settings being reused when creating a new project
```
6 changes: 4 additions & 2 deletions ui/app/components/app-form/project-repository-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ export default class AppFormProjectRepositorySettings extends Component<ProjectS
@tracked project: Project.AsObject;
@tracked authCase: number;
@tracked serverHcl: boolean;
defaultProject: Project.AsObject;

constructor(owner: unknown, args: ProjectSettingsArgs) {
super(owner, args);
this.project = JSON.parse(JSON.stringify(DEFAULT_PROJECT_MODEL)) as Project.AsObject; // to ensure we're doing a deep copy
this.defaultProject = JSON.parse(JSON.stringify(DEFAULT_PROJECT_MODEL)) as Project.AsObject; // to ensure we're doing a deep copy
this.project = this.defaultProject;
let { project } = this.args;
this.populateExistingFields(project, this.project);
this.authCase = 4;
Expand Down Expand Up @@ -130,7 +132,7 @@ export default class AppFormProjectRepositorySettings extends Component<ProjectS
populateExistingFields(projectFromArgs: Project.AsObject, currentModel: Project.AsObject): void {
for (let [key, value] of Object.entries(projectFromArgs)) {
if (isEmpty(value)) {
currentModel[key] = DEFAULT_PROJECT_MODEL[key];
currentModel[key] = this.defaultProject[key];
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, clearRender, fillIn } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { Project } from 'waypoint-pb';

module('Integration | Component | app-form/project-settings', function (hooks) {
module('Integration | Component | app-form/project-repository-settings', function (hooks) {
setupRenderingTest(hooks);

test('second new project does not have previous input', async function (assert) {
Expand All @@ -14,7 +15,7 @@ module('Integration | Component | app-form/project-settings', function (hooks) {
await fillIn('#git-source-password', 'password');
await clearRender();

this.set('project2', {});
this.set('project2', new Project().toObject());
await render(hbs`<AppForm::ProjectRepositorySettings @project={{this.project2}} />`);

assert.dom('#git-source-url').hasValue('');
Expand Down

0 comments on commit 3559dd7

Please sign in to comment.