Skip to content

Commit

Permalink
Issue 1920: reset image selection when renaming existing power worksp…
Browse files Browse the repository at this point in the history
…aces (#1921)

* added logic to reset images when existing power workspace name changed

* prettier formatting

* removed unused import

* removed craig from describe

* remove disabled, clear images on name change

* added componentdidupdate for name change

* prettier formatting

* updated changelog

* moved changelog to latest version
  • Loading branch information
Ay1man2 authored and GitHub Enterprise committed May 23, 2024
1 parent 62a51bb commit 5aff9f7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
- Fixed an issue causing Cloud Services with missing values not to be highlighed red on the `/v2/services` page
- The Power VS POC Template Activity Tracker COS instance now correctly uses a random suffix to ensure unique resource naming
- Fixed an issue causing imported VPC Security Groups to fail on Terraform Plan
- Power VS Images are now reset when changing zones or changing the name of an existing workspace

## 1.15.5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ class DynamicFetchMultiSelect extends React.Component {
this._isMounted = false;
}

// Force re-fetch of images on zone change
// Force re-fetch of images on name or zone change
componentDidUpdate(prevProps) {
if (prevProps.parentState.zone != this.props.parentState.zone) {
if (
prevProps.parentState.zone != this.props.parentState.zone ||
prevProps.parentState.name != this.props.parentState.name
) {
this._isMounted = false;
this.setState({ data: ["Loading..."] }, () => {
this.componentDidMount();
Expand Down
3 changes: 2 additions & 1 deletion client/src/lib/docs/release-notes.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"Fixed an issue in the Power VS POC template where the LogDNA files were written to the AIX save files COS bucket",
"Fixed an issue causing Cloud Services with missing values not to be highlighed red on the `/v2/services` page",
"The Power VS POC Template Activity Tracker COS instance now correctly uses a random suffix to ensure unique resource naming",
"Fixed an issue causing imported VPC Security Groups to fail on Terraform Plan"
"Fixed an issue causing imported VPC Security Groups to fail on Terraform Plan",
"Power VS Images are now reset when changing zones or changing the name of an existing workspace"
],
"upgrade_notes": [
"Updated the VPN as a Service template's default authentication method and changed the Secrets Manager to the Trial plan"
Expand Down
6 changes: 6 additions & 0 deletions client/src/lib/state/power-vs/power-vs-workspace-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ function powerVsWorkspaceSchema() {
? stateData.name
: `${componentProps.craig.store.json._options.prefix}-power-workspace-${stateData.name}`;
},
onStateChange: function (stateData) {
if (stateData.use_data) {
stateData.imageNames = [];
stateData.images = [];
}
},
}),
resource_group: resourceGroupsField(),
zone: {
Expand Down
1 change: 1 addition & 0 deletions client/src/lib/state/reusable-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ function nameField(jsonField, options) {
readOnly: options?.readOnly,
tooltip: options?.tooltip,
disabledText: options?.invalidText,
onStateChange: options?.onStateChange,
};
}

Expand Down
23 changes: 22 additions & 1 deletion unit-tests/state/power-vs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ describe("power-vs", () => {
});
});
describe("power.schema", () => {
describe("craig.power.name.helperText", () => {
describe("power.name.helperText", () => {
it("should return correct helper text for name when use data", () => {
assert.deepEqual(
craig.power.name.helperText({ use_data: true, name: "name" }),
Expand Down Expand Up @@ -469,6 +469,27 @@ describe("power-vs", () => {
);
});
});
describe("power.name.onStateChange", () => {
it("should clear images when changing name of imported workspace", () => {
let data = { use_data: true };
let expectedData = {
use_data: true,
imageNames: [],
images: [],
};
craig.power.name.onStateChange(data);
assert.deepEqual(data, expectedData, "it should clear images");
});
it("should not clear images when changing name of CRAIG created workspace", () => {
let data = { use_data: false, imageNames: ["testImage"] };
let expectedData = {
use_data: false,
imageNames: ["testImage"],
};
craig.power.name.onStateChange(data);
assert.deepEqual(data, expectedData, "it should not clear images");
});
});
describe("power.zone", () => {
describe("power.zone.onStateChange", () => {
it("should set images when changing zone", () => {
Expand Down

0 comments on commit 5aff9f7

Please sign in to comment.