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

Fix: create/edit resource tab Save & Close button behavior #7124

Merged
merged 6 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10119,11 +10119,11 @@ exports[`cluster/namespaces - edit namespace from new tab when navigating to nam
class="footer"
>
<div
class="Dock"
class="Dock isOpen"
tabindex="-1"
>
<div
class="ResizingAnchor vertical leading disabled"
class="ResizingAnchor vertical leading"
/>
<div
class="tabs-container flex align-center"
Expand All @@ -10134,10 +10134,63 @@ exports[`cluster/namespaces - edit namespace from new tab when navigating to nam
>
<div
class="Tabs tabs"
/>
>
<div
class="Tab flex gaps align-center DockTab active"
data-testid="dock-tab-for-some-first-tab-id"
id="tab-some-first-tab-id"
role="tab"
tabindex="0"
>
<i
class="Icon material focusable small"
>
<span
class="icon"
data-icon-name="edit"
>
edit
</span>
</i>
<div
class="label"
>
<div
class="flex align-center"
>
<span
class="title"
>
Namespace: some-name
</span>
<div
class="close"
>
<i
class="Icon material interactive focusable small"
data-testid="dock-tab-close-for-some-first-tab-id"
tabindex="0"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
<div
data-testid="tooltip-content-for-dock-tab-close-for-some-first-tab-id"
>
Close ⌘+W
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div
class="toolbar flex gaps align-center box grow pl-0"
class="toolbar flex gaps align-center box grow"
>
<div
class="dock-menu box grow"
Expand All @@ -10158,6 +10211,118 @@ exports[`cluster/namespaces - edit namespace from new tab when navigating to nam
New tab
</div>
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="fullscreen"
>
fullscreen
</span>
</i>
<div>
Fit to window
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="keyboard_arrow_down"
>
keyboard_arrow_down
</span>
</i>
<div>
Minimize
</div>
</div>
</div>
<div
class="tab-content edit-resource"
data-testid="dock-tab-content-for-some-first-tab-id"
style="flex-basis: 300px;"
>
<div
class="EditResource flex column"
>
<div
class="InfoPanel flex gaps align-center"
>
<div
class="controls"
>
<div
class="resource-info flex gaps align-center"
>
<span>
Kind:
</span>
<div
class="badge"
>
Namespace
</div>
<span>
Name:
</span>
<div
class="badge"
>
some-name
</div>
<span>
Namespace:
</span>
<div
class="badge"
>
default
</div>
</div>
</div>
<div
class="flex gaps align-center"
/>
<button
class="Button plain"
data-testid="cancel-edit-resource-from-tab-for-some-first-tab-id"
type="button"
>
Cancel
</button>
<button
class="Button active outlined"
data-testid="save-edit-resource-from-tab-for-some-first-tab-id"
type="button"
>
Save
</button>
<button
class="Button primary active"
data-testid="save-and-close-edit-resource-from-tab-for-some-first-tab-id"
type="button"
>
Save & Close
</button>
</div>
<textarea
data-testid="monaco-editor-for-some-first-tab-id"
>
apiVersion: some-api-version
kind: Namespace
metadata:
uid: some-uid
name: some-name
resourceVersion: some-resource-version
selfLink: /apis/some-api-version/namespaces/some-uid
somePropertyToBeRemoved: some-value
somePropertyToBeChanged: some-old-value

</textarea>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ metadata:
expect(rendered.baseElement).toMatchSnapshot();
});

// TODO: Not doable at the moment because info panel controls closing of the tab
xit("does not close the dock tab", () => {
it("does not close the dock tab", () => {
expect(
rendered.getByTestId("dock-tab-for-some-first-tab-id"),
).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class NonInjectedCreateResource extends React.Component<CreateResourceProps & De
this.error = error.toString();
};

create = async (): Promise<void> => {
create = async (): Promise<string | void> => {
const { apiManager, getDetailsUrl, navigate, requestKubeObjectCreation } = this.props;

if (this.error || !this.data?.trim()) {
Expand All @@ -98,7 +98,7 @@ class NonInjectedCreateResource extends React.Component<CreateResourceProps & De
this.props.logger.warn("Failed to create resource", { resource }, result.error);
this.props.showCheckedErrorNotification(result.error, "Unknown error occured while creating resources");

return;
throw Error(result.error);
aleksfront marked this conversation as resolved.
Show resolved Hide resolved
}

const { kind, apiVersion, metadata: { name, namespace }} = result.response;
Expand All @@ -122,7 +122,13 @@ class NonInjectedCreateResource extends React.Component<CreateResourceProps & De
));
});

await Promise.allSettled(creatingResources);
const results = await Promise.allSettled(creatingResources);

if (results.some(result => result.status === "rejected")) {
return;
}

return "All resources have been successfully created";
};

renderControls() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,7 @@ export class EditResourceModel {
runInAction(() => {
this.editingResource.firstDraft = currentValue;
});

return result.response.toString();
};
}
11 changes: 9 additions & 2 deletions packages/core/src/renderer/components/dock/info-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,25 @@ class NonInjectedInfoPanel extends Component<InfoPanelProps & Dependencies> {
if (showNotifications && result) {
this.props.showSuccessNotification(result);
}

return result;
} catch (error) {
if (showNotifications) {
this.props.showCheckedErrorNotification(error, "Unknown error while submitting");
}

return false;
} finally {
this.waiting = false;
}
};

submitAndClose = async () => {
await this.submit();
this.close();
const result = await this.submit();

if (result) {
this.close();
}
};

close = () => {
Expand Down