1
0
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:
Alex Andreev 2023-02-13 16:52:42 +03:00 committed by GitHub
parent 0719293b11
commit c9d43ffdba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 190 additions and 11 deletions

View File

@ -10119,11 +10119,11 @@ exports[`cluster/namespaces - edit namespace from new tab when navigating to nam
class="footer" class="footer"
> >
<div <div
class="Dock" class="Dock isOpen"
tabindex="-1" tabindex="-1"
> >
<div <div
class="ResizingAnchor vertical leading disabled" class="ResizingAnchor vertical leading"
/> />
<div <div
class="tabs-container flex align-center" class="tabs-container flex align-center"
@ -10134,10 +10134,63 @@ exports[`cluster/namespaces - edit namespace from new tab when navigating to nam
> >
<div <div
class="Tabs tabs" 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>
<div <div
class="toolbar flex gaps align-center box grow pl-0" class="toolbar flex gaps align-center box grow"
> >
<div <div
class="dock-menu box grow" class="dock-menu box grow"
@ -10158,6 +10211,118 @@ exports[`cluster/namespaces - edit namespace from new tab when navigating to nam
New tab New tab
</div> </div>
</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> </div>
</div> </div>

View File

@ -401,8 +401,7 @@ metadata:
expect(rendered.baseElement).toMatchSnapshot(); expect(rendered.baseElement).toMatchSnapshot();
}); });
// TODO: Not doable at the moment because info panel controls closing of the tab it("does not close the dock tab", () => {
xit("does not close the dock tab", () => {
expect( expect(
rendered.getByTestId("dock-tab-for-some-first-tab-id"), rendered.getByTestId("dock-tab-for-some-first-tab-id"),
).toBeInTheDocument(); ).toBeInTheDocument();

View File

@ -76,7 +76,7 @@ class NonInjectedCreateResource extends React.Component<CreateResourceProps & De
this.error = error.toString(); this.error = error.toString();
}; };
create = async (): Promise<void> => { create = async (): Promise<string | void> => {
const { apiManager, getDetailsUrl, navigate, requestKubeObjectCreation } = this.props; const { apiManager, getDetailsUrl, navigate, requestKubeObjectCreation } = this.props;
if (this.error || !this.data?.trim()) { 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.logger.warn("Failed to create resource", { resource }, result.error);
this.props.showCheckedErrorNotification(result.error, "Unknown error occured while creating resources"); this.props.showCheckedErrorNotification(result.error, "Unknown error occured while creating resources");
return; throw result.error;
} }
const { kind, apiVersion, metadata: { name, namespace }} = result.response; 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() { renderControls() {

View File

@ -174,5 +174,7 @@ export class EditResourceModel {
runInAction(() => { runInAction(() => {
this.editingResource.firstDraft = currentValue; this.editingResource.firstDraft = currentValue;
}); });
return result.response.toString();
}; };
} }

View File

@ -93,18 +93,25 @@ class NonInjectedInfoPanel extends Component<InfoPanelProps & Dependencies> {
if (showNotifications && result) { if (showNotifications && result) {
this.props.showSuccessNotification(result); this.props.showSuccessNotification(result);
} }
return result;
} catch (error) { } catch (error) {
if (showNotifications) { if (showNotifications) {
this.props.showCheckedErrorNotification(error, "Unknown error while submitting"); this.props.showCheckedErrorNotification(error, "Unknown error while submitting");
} }
return false;
} finally { } finally {
this.waiting = false; this.waiting = false;
} }
}; };
submitAndClose = async () => { submitAndClose = async () => {
await this.submit(); const result = await this.submit();
this.close();
if (result) {
this.close();
}
}; };
close = () => { close = () => {