mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix: create/edit resource tab Save & Close button behavior (#7124)
* Close dock tab only if submit() resolved Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Close dock tab only if all resources successfully created Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Simpler error throw Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> --------- Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
0719293b11
commit
c9d43ffdba
@ -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"
|
||||
@ -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"
|
||||
@ -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>
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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()) {
|
||||
@ -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 result.error;
|
||||
}
|
||||
|
||||
const { kind, apiVersion, metadata: { name, namespace }} = result.response;
|
||||
@ -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() {
|
||||
|
||||
@ -174,5 +174,7 @@ export class EditResourceModel {
|
||||
runInAction(() => {
|
||||
this.editingResource.firstDraft = currentValue;
|
||||
});
|
||||
|
||||
return result.response.toString();
|
||||
};
|
||||
}
|
||||
|
||||
@ -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 = () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user