mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add breadcrumbs to removal of kube objects, but also discuss about general improvements (#4282)
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Co-authored-by: Janne Savolainen <janne.savolainen@houston-inc.com> Co-authored-by: Mikko Aspiala <mikko.aspiala@houston-inc.com>
This commit is contained in:
parent
304941d397
commit
7ed50f83fc
6
.idea/jsLibraryMappings.xml
Normal file
6
.idea/jsLibraryMappings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptLibraryMappings">
|
||||
<file url="PROJECT" libraries="{ogre-tools}" />
|
||||
</component>
|
||||
</project>
|
||||
@ -15,5 +15,6 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="ogre-tools" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
16
.idea/libraries/ogre_tools.xml
Normal file
16
.idea/libraries/ogre_tools.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<component name="libraryTable">
|
||||
<library name="ogre-tools" type="javaScript">
|
||||
<properties>
|
||||
<sourceFilesUrls>
|
||||
<item url="file://$PROJECT_DIR$/node_modules/@ogre-tools/injectable-react/ogre-tools-injectable-react.d.ts" />
|
||||
<item url="file://$PROJECT_DIR$/node_modules/@ogre-tools/injectable/ogre-tools-injectable.d.ts" />
|
||||
</sourceFilesUrls>
|
||||
</properties>
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/node_modules/@ogre-tools/injectable-react/ogre-tools-injectable-react.d.ts" />
|
||||
<root url="file://$PROJECT_DIR$/node_modules/@ogre-tools/injectable/ogre-tools-injectable.d.ts" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
12
package.json
12
package.json
@ -72,7 +72,12 @@
|
||||
"setupFiles": [
|
||||
"<rootDir>/src/jest.setup.ts",
|
||||
"jest-canvas-mock"
|
||||
]
|
||||
],
|
||||
"globals": {
|
||||
"ts-jest": {
|
||||
"isolatedModules": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"build": {
|
||||
"generateUpdatesFilesForAllChannels": true,
|
||||
@ -193,8 +198,8 @@
|
||||
"@kubernetes/client-node": "^0.16.1",
|
||||
"@sentry/electron": "^2.5.4",
|
||||
"@sentry/integrations": "^6.15.0",
|
||||
"@ogre-tools/injectable": "^1.2.1",
|
||||
"@ogre-tools/injectable-react": "^1.2.1",
|
||||
"@ogre-tools/injectable": "^1.3.0",
|
||||
"@ogre-tools/injectable-react": "^1.3.1",
|
||||
"abort-controller": "^3.0.0",
|
||||
"auto-bind": "^4.0.0",
|
||||
"autobind-decorator": "^2.4.0",
|
||||
@ -260,6 +265,7 @@
|
||||
"ws": "^7.5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@async-fn/jest": "^1.5.0",
|
||||
"@material-ui/core": "^4.12.3",
|
||||
"@material-ui/icons": "^4.11.2",
|
||||
"@material-ui/lab": "^4.0.0-alpha.60",
|
||||
|
||||
@ -140,6 +140,7 @@ export class ConfirmDialog extends React.Component<ConfirmDialogProps> {
|
||||
isOpen={dialogState.isOpen}
|
||||
onClose={this.onClose}
|
||||
close={this.close}
|
||||
{...(dialogState.isOpen ? { "data-testid":"confirmation-dialog" } : {})}
|
||||
>
|
||||
<div className="confirm-content">
|
||||
{icon} {message}
|
||||
@ -158,6 +159,7 @@ export class ConfirmDialog extends React.Component<ConfirmDialogProps> {
|
||||
label={labelOk}
|
||||
onClick={prevDefault(this.ok)}
|
||||
waiting={this.isSaving}
|
||||
data-testid="confirm"
|
||||
{...okButtonProps}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@ -41,6 +41,7 @@ export interface DialogProps {
|
||||
modal?: boolean;
|
||||
pinned?: boolean;
|
||||
animated?: boolean;
|
||||
"data-testid"?: string;
|
||||
}
|
||||
|
||||
interface DialogState {
|
||||
@ -149,7 +150,7 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { modal, animated, pinned } = this.props;
|
||||
const { modal, animated, pinned, "data-testid": testId } = this.props;
|
||||
let { className } = this.props;
|
||||
|
||||
className = cssNames("Dialog flex center", className, { modal, pinned });
|
||||
@ -158,6 +159,7 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
|
||||
className={className}
|
||||
onClick={stopPropagation}
|
||||
ref={this.ref}
|
||||
data-testid={testId}
|
||||
>
|
||||
<div className="box" ref={e => this.contentElem = e}>
|
||||
{this.props.children}
|
||||
|
||||
@ -0,0 +1,371 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`kube-object-menu given kube object renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div>
|
||||
<ul
|
||||
class="Animate opacity Menu MenuActions flex KubeObjectMenu toolbar gaps right bottom"
|
||||
style="--enter-duration: 100ms; --leave-duration: 100ms;"
|
||||
>
|
||||
<li>
|
||||
Some menu item
|
||||
</li>
|
||||
<li
|
||||
class="MenuItem"
|
||||
data-testid="menu-action-remove"
|
||||
tabindex="0"
|
||||
>
|
||||
<i
|
||||
class="Icon material interactive focusable"
|
||||
id="tooltip_target_4"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="delete"
|
||||
>
|
||||
delete
|
||||
</span>
|
||||
<div />
|
||||
</i>
|
||||
<span
|
||||
class="title"
|
||||
>
|
||||
Delete
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Animate opacity-scale Dialog flex center ConfirmDialog modal"
|
||||
style="--enter-duration: 100ms; --leave-duration: 100ms;"
|
||||
/>
|
||||
<div
|
||||
class="Tooltip narrow invisible formatter"
|
||||
>
|
||||
Delete
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`kube-object-menu given kube object when removing kube object renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div>
|
||||
<ul
|
||||
class="Animate opacity Menu MenuActions flex KubeObjectMenu toolbar gaps right bottom"
|
||||
style="--enter-duration: 100ms; --leave-duration: 100ms;"
|
||||
>
|
||||
<li>
|
||||
Some menu item
|
||||
</li>
|
||||
<li
|
||||
class="MenuItem"
|
||||
data-testid="menu-action-remove"
|
||||
tabindex="0"
|
||||
>
|
||||
<i
|
||||
class="Icon material interactive focusable"
|
||||
id="tooltip_target_8"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="delete"
|
||||
>
|
||||
delete
|
||||
</span>
|
||||
<div />
|
||||
</i>
|
||||
<span
|
||||
class="title"
|
||||
>
|
||||
Delete
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Animate opacity-scale Dialog flex center ConfirmDialog modal"
|
||||
data-testid="confirmation-dialog"
|
||||
style="--enter-duration: 100ms; --leave-duration: 100ms;"
|
||||
>
|
||||
<div
|
||||
class="box"
|
||||
>
|
||||
<div
|
||||
class="confirm-content"
|
||||
>
|
||||
<i
|
||||
class="Icon material focusable big"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="warning"
|
||||
>
|
||||
warning
|
||||
</span>
|
||||
</i>
|
||||
|
||||
<div>
|
||||
<p>
|
||||
Remove
|
||||
some-kind
|
||||
|
||||
<b>
|
||||
some-namespace/some-name
|
||||
</b>
|
||||
from
|
||||
<b>
|
||||
Some name
|
||||
</b>
|
||||
?
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="confirm-buttons"
|
||||
>
|
||||
<button
|
||||
class="Button cancel plain"
|
||||
type="button"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
class="Button ok primary"
|
||||
data-testid="confirm"
|
||||
type="button"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Tooltip narrow invisible formatter"
|
||||
>
|
||||
Delete
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`kube-object-menu given kube object with namespace when removing kube object, renders confirmation dialog with namespace 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div>
|
||||
<ul
|
||||
class="Animate opacity Menu MenuActions flex KubeObjectMenu toolbar gaps right bottom"
|
||||
style="--enter-duration: 100ms; --leave-duration: 100ms;"
|
||||
>
|
||||
<li>
|
||||
Some menu item
|
||||
</li>
|
||||
<li
|
||||
class="MenuItem"
|
||||
data-testid="menu-action-remove"
|
||||
tabindex="0"
|
||||
>
|
||||
<i
|
||||
class="Icon material interactive focusable"
|
||||
id="tooltip_target_33"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="delete"
|
||||
>
|
||||
delete
|
||||
</span>
|
||||
<div />
|
||||
</i>
|
||||
<span
|
||||
class="title"
|
||||
>
|
||||
Delete
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Animate opacity-scale Dialog flex center ConfirmDialog modal"
|
||||
data-testid="confirmation-dialog"
|
||||
style="--enter-duration: 100ms; --leave-duration: 100ms;"
|
||||
>
|
||||
<div
|
||||
class="box"
|
||||
>
|
||||
<div
|
||||
class="confirm-content"
|
||||
>
|
||||
<i
|
||||
class="Icon material focusable big"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="warning"
|
||||
>
|
||||
warning
|
||||
</span>
|
||||
</i>
|
||||
|
||||
<div>
|
||||
<p>
|
||||
Remove
|
||||
some-kind
|
||||
|
||||
<b>
|
||||
some-namespace/some-name
|
||||
</b>
|
||||
from
|
||||
<b>
|
||||
Some name
|
||||
</b>
|
||||
?
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="confirm-buttons"
|
||||
>
|
||||
<button
|
||||
class="Button cancel plain"
|
||||
type="button"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
class="Button ok primary"
|
||||
data-testid="confirm"
|
||||
type="button"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Tooltip narrow invisible formatter"
|
||||
>
|
||||
Delete
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`kube-object-menu given kube object without namespace when removing kube object, renders confirmation dialog without namespace 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div>
|
||||
<ul
|
||||
class="Animate opacity Menu MenuActions flex KubeObjectMenu toolbar gaps right bottom"
|
||||
style="--enter-duration: 100ms; --leave-duration: 100ms;"
|
||||
>
|
||||
<li>
|
||||
Some menu item
|
||||
</li>
|
||||
<li
|
||||
class="MenuItem"
|
||||
data-testid="menu-action-remove"
|
||||
tabindex="0"
|
||||
>
|
||||
<i
|
||||
class="Icon material interactive focusable"
|
||||
id="tooltip_target_41"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="delete"
|
||||
>
|
||||
delete
|
||||
</span>
|
||||
<div />
|
||||
</i>
|
||||
<span
|
||||
class="title"
|
||||
>
|
||||
Delete
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Animate opacity-scale Dialog flex center ConfirmDialog modal"
|
||||
data-testid="confirmation-dialog"
|
||||
style="--enter-duration: 100ms; --leave-duration: 100ms;"
|
||||
>
|
||||
<div
|
||||
class="box"
|
||||
>
|
||||
<div
|
||||
class="confirm-content"
|
||||
>
|
||||
<i
|
||||
class="Icon material focusable big"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="warning"
|
||||
>
|
||||
warning
|
||||
</span>
|
||||
</i>
|
||||
|
||||
<div>
|
||||
<p>
|
||||
Remove
|
||||
some-kind
|
||||
|
||||
<b>
|
||||
some-name
|
||||
</b>
|
||||
from
|
||||
<b>
|
||||
Some name
|
||||
</b>
|
||||
?
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="confirm-buttons"
|
||||
>
|
||||
<button
|
||||
class="Button cancel plain"
|
||||
type="button"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
class="Button ok primary"
|
||||
data-testid="confirm"
|
||||
type="button"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Tooltip narrow invisible formatter"
|
||||
>
|
||||
Delete
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`kube-object-menu given no kube object, renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<ul
|
||||
class="Animate opacity Menu MenuActions flex KubeObjectMenu toolbar gaps right bottom"
|
||||
style="--enter-duration: 100ms; --leave-duration: 100ms;"
|
||||
/>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import type { ApiManager } from "../../../../common/k8s-api/api-manager";
|
||||
import { apiManager } from "../../../../common/k8s-api/api-manager";
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
import { lifecycleEnum } from "@ogre-tools/injectable";
|
||||
|
||||
const apiManagerInjectable: Injectable<ApiManager> = {
|
||||
getDependencies: () => ({}),
|
||||
instantiate: () => apiManager,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
};
|
||||
|
||||
export default apiManagerInjectable;
|
||||
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
import { lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "../../../../main/cluster";
|
||||
import clusterInjectable from "./cluster.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
cluster: Cluster;
|
||||
}
|
||||
|
||||
const clusterNameInjectable: Injectable<string | undefined, Dependencies> = {
|
||||
getDependencies: di => ({
|
||||
cluster: di.inject(clusterInjectable),
|
||||
}),
|
||||
|
||||
instantiate: ({ cluster }) => cluster?.name,
|
||||
|
||||
lifecycle: lifecycleEnum.transient,
|
||||
};
|
||||
|
||||
export default clusterNameInjectable;
|
||||
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import { getActiveClusterEntity } from "../../../api/catalog-entity-registry";
|
||||
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
import { lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "../../../../main/cluster";
|
||||
|
||||
const clusterInjectable: Injectable<Cluster | null> = {
|
||||
getDependencies: () => ({}),
|
||||
instantiate: () => getActiveClusterEntity(),
|
||||
lifecycle: lifecycleEnum.transient,
|
||||
};
|
||||
|
||||
export default clusterInjectable;
|
||||
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import { editResourceTab } from "../../dock/edit-resource.store";
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
import { lifecycleEnum } from "@ogre-tools/injectable";
|
||||
|
||||
const editResourceTabInjectable: Injectable<typeof editResourceTab> = {
|
||||
getDependencies: () => ({}),
|
||||
instantiate: () => editResourceTab,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
};
|
||||
|
||||
export default editResourceTabInjectable;
|
||||
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import { hideDetails } from "../../kube-detail-params";
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
import { lifecycleEnum } from "@ogre-tools/injectable";
|
||||
|
||||
export const hideDetailsInjectable: Injectable<typeof hideDetails> = {
|
||||
getDependencies: () => ({}),
|
||||
instantiate: () => hideDetails,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
};
|
||||
|
||||
export default hideDetailsInjectable;
|
||||
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import type { KubeObjectMenuRegistry } from "../../../../../extensions/registries";
|
||||
import type { KubeObject } from "../../../../../common/k8s-api/kube-object";
|
||||
|
||||
export interface Dependencies {
|
||||
kubeObjectMenuRegistry: KubeObjectMenuRegistry;
|
||||
}
|
||||
|
||||
export interface InstantiationParameter {
|
||||
kubeObject: KubeObject;
|
||||
}
|
||||
|
||||
export const getKubeObjectMenuItems = (
|
||||
{ kubeObjectMenuRegistry }: Dependencies,
|
||||
{ kubeObject }: InstantiationParameter,
|
||||
) => {
|
||||
if (!kubeObject) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return kubeObjectMenuRegistry
|
||||
.getItemsForKind(kubeObject.kind, kubeObject.apiVersion)
|
||||
.map(item => item.components.MenuItem);
|
||||
};
|
||||
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import { Injectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import kubeObjectMenuRegistryInjectable from "./kube-object-menu-registry.injectable";
|
||||
|
||||
import {
|
||||
InstantiationParameter,
|
||||
Dependencies,
|
||||
getKubeObjectMenuItems,
|
||||
} from "./get-kube-object-menu-items";
|
||||
|
||||
const kubeObjectMenuItemsInjectable: Injectable<
|
||||
ReturnType<typeof getKubeObjectMenuItems>,
|
||||
Dependencies,
|
||||
InstantiationParameter
|
||||
> = {
|
||||
getDependencies: di => ({
|
||||
kubeObjectMenuRegistry: di.inject(kubeObjectMenuRegistryInjectable),
|
||||
}),
|
||||
|
||||
instantiate: getKubeObjectMenuItems,
|
||||
|
||||
lifecycle: lifecycleEnum.transient,
|
||||
};
|
||||
|
||||
export default kubeObjectMenuItemsInjectable;
|
||||
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import { KubeObjectMenuRegistry } from "../../../../../extensions/registries";
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
import { lifecycleEnum } from "@ogre-tools/injectable";
|
||||
|
||||
const kubeObjectMenuRegistryInjectable: Injectable<KubeObjectMenuRegistry> = {
|
||||
getDependencies: () => ({}),
|
||||
instantiate: () => KubeObjectMenuRegistry.getInstance(),
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
};
|
||||
|
||||
export default kubeObjectMenuRegistryInjectable;
|
||||
@ -19,4 +19,5 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export * from "./kube-object-menu";
|
||||
export type { KubeObjectMenuProps } from "./kube-object-menu";
|
||||
export { KubeObjectMenu } from "./kube-object-menu-container";
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import { getInjectedComponent } from "@ogre-tools/injectable-react";
|
||||
import KubeObjectMenuInjectable from "./kube-object-menu.injectable";
|
||||
|
||||
export const KubeObjectMenu = getInjectedComponent(KubeObjectMenuInjectable);
|
||||
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import React from "react";
|
||||
|
||||
import {
|
||||
KubeObjectMenu,
|
||||
KubeObjectMenuDependencies,
|
||||
KubeObjectMenuProps,
|
||||
} from "./kube-object-menu";
|
||||
|
||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
import { lifecycleEnum, Injectable } from "@ogre-tools/injectable";
|
||||
import apiManagerInjectable from "./dependencies/api-manager.injectable";
|
||||
import clusterNameInjectable from "./dependencies/cluster-name.injectable";
|
||||
import editResourceTabInjectable from "./dependencies/edit-resource-tab.injectable";
|
||||
import hideDetailsInjectable from "./dependencies/hide-details.injectable";
|
||||
import kubeObjectMenuItemsInjectable from "./dependencies/kube-object-menu-items/kube-object-menu-items.injectable";
|
||||
|
||||
const KubeObjectMenuInjectable: Injectable<
|
||||
JSX.Element,
|
||||
KubeObjectMenuDependencies<KubeObject>,
|
||||
KubeObjectMenuProps<KubeObject>
|
||||
> = {
|
||||
getDependencies: (di, props) => ({
|
||||
clusterName: di.inject(clusterNameInjectable),
|
||||
apiManager: di.inject(apiManagerInjectable),
|
||||
editResourceTab: di.inject(editResourceTabInjectable),
|
||||
hideDetails: di.inject(hideDetailsInjectable),
|
||||
|
||||
kubeObjectMenuItems: di.inject(kubeObjectMenuItemsInjectable, {
|
||||
kubeObject: props.object,
|
||||
}),
|
||||
}),
|
||||
|
||||
instantiate: (dependencies, props) => (
|
||||
<KubeObjectMenu {...dependencies} {...props} />
|
||||
),
|
||||
|
||||
lifecycle: lifecycleEnum.transient,
|
||||
};
|
||||
|
||||
export default KubeObjectMenuInjectable;
|
||||
@ -0,0 +1,284 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { screen } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
import { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import type { ConfigurableDependencyInjectionContainer } from "@ogre-tools/injectable";
|
||||
import type { KubeObjectMenuRegistration } from "../../../extensions/registries";
|
||||
import { KubeObjectMenuRegistry } from "../../../extensions/registries";
|
||||
import { ConfirmDialog } from "../confirm-dialog";
|
||||
import asyncFn, { AsyncFnMock } from "@async-fn/jest";
|
||||
import { getDiForUnitTesting } from "../getDiForUnitTesting";
|
||||
|
||||
import clusterInjectable from "./dependencies/cluster.injectable";
|
||||
import hideDetailsInjectable from "./dependencies/hide-details.injectable";
|
||||
import editResourceTabInjectable from "./dependencies/edit-resource-tab.injectable";
|
||||
import { TabKind } from "../dock/dock.store";
|
||||
import kubeObjectMenuRegistryInjectable from "./dependencies/kube-object-menu-items/kube-object-menu-registry.injectable";
|
||||
import { DiRender, renderFor } from "../test-utils/renderFor";
|
||||
import type { Cluster } from "../../../main/cluster";
|
||||
import type { ApiManager } from "../../../common/k8s-api/api-manager";
|
||||
import apiManagerInjectable from "./dependencies/api-manager.injectable";
|
||||
import { KubeObjectMenu } from "./index";
|
||||
|
||||
describe("kube-object-menu", () => {
|
||||
let di: ConfigurableDependencyInjectionContainer;
|
||||
let render: DiRender;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
// TODO: Remove global shared state
|
||||
KubeObjectMenuRegistry.resetInstance();
|
||||
KubeObjectMenuRegistry.createInstance();
|
||||
|
||||
render = renderFor(di);
|
||||
|
||||
di.override(clusterInjectable, {
|
||||
name: "Some name",
|
||||
} as Cluster);
|
||||
|
||||
di.override(apiManagerInjectable, {
|
||||
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||
getStore: api => undefined,
|
||||
} as ApiManager);
|
||||
|
||||
di.override(hideDetailsInjectable, () => {});
|
||||
|
||||
di.override(editResourceTabInjectable, () => ({
|
||||
id: "irrelevant",
|
||||
kind: TabKind.TERMINAL,
|
||||
pinned: false,
|
||||
title: "irrelevant",
|
||||
}));
|
||||
|
||||
addDynamicMenuItem({
|
||||
di,
|
||||
apiVersions: ["some-api-version"],
|
||||
kind: "some-kind",
|
||||
});
|
||||
|
||||
addDynamicMenuItem({
|
||||
di,
|
||||
apiVersions: ["some-unrelated-api-version"],
|
||||
kind: "some-kind",
|
||||
});
|
||||
|
||||
addDynamicMenuItem({
|
||||
di,
|
||||
apiVersions: ["some-api-version"],
|
||||
kind: "some-unrelated-kind",
|
||||
});
|
||||
});
|
||||
|
||||
it("given no cluster, does not crash", () => {
|
||||
di.override(clusterInjectable, null);
|
||||
|
||||
expect(() => {
|
||||
render(<KubeObjectMenu object={null} toolbar={true} />);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it("given no kube object, renders", () => {
|
||||
const { baseElement } = render(
|
||||
<KubeObjectMenu object={null} toolbar={true} />,
|
||||
);
|
||||
|
||||
expect(baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
describe("given kube object", () => {
|
||||
let baseElement: Element;
|
||||
let removeActionMock: AsyncFnMock<Function>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const objectStub = KubeObject.create({
|
||||
apiVersion: "some-api-version",
|
||||
kind: "some-kind",
|
||||
metadata: {
|
||||
uid: "some-uid",
|
||||
name: "some-name",
|
||||
resourceVersion: "some-resource-version",
|
||||
namespace: "some-namespace",
|
||||
},
|
||||
});
|
||||
|
||||
removeActionMock = asyncFn();
|
||||
|
||||
({ baseElement } = render(
|
||||
<div>
|
||||
<ConfirmDialog />
|
||||
|
||||
<KubeObjectMenu
|
||||
object={objectStub}
|
||||
toolbar={true}
|
||||
removeAction={removeActionMock}
|
||||
/>
|
||||
</div>,
|
||||
));
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
expect(baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("does not open a confirmation dialog yet", () => {
|
||||
expect(screen.queryByTestId("confirmation-dialog")).toBeNull();
|
||||
});
|
||||
|
||||
describe("when removing kube object", () => {
|
||||
beforeEach(() => {
|
||||
const menuItem = screen.getByTestId("menu-action-remove");
|
||||
|
||||
userEvent.click(menuItem);
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
expect(baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("opens a confirmation dialog", () => {
|
||||
screen.getByTestId("confirmation-dialog");
|
||||
});
|
||||
|
||||
describe("when remove is confirmed", () => {
|
||||
beforeEach(() => {
|
||||
const confirmRemovalButton = screen.getByTestId("confirm");
|
||||
|
||||
userEvent.click(confirmRemovalButton);
|
||||
});
|
||||
|
||||
it("calls for removal of the kube object", () => {
|
||||
expect(removeActionMock).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it("does not close the confirmation dialog yet", () => {
|
||||
screen.getByTestId("confirmation-dialog");
|
||||
});
|
||||
|
||||
it("when removal resolves, closes the confirmation dialog", async () => {
|
||||
await removeActionMock.resolve();
|
||||
|
||||
expect(screen.queryByTestId("confirmation-dialog")).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("given kube object with namespace", () => {
|
||||
let baseElement: Element;
|
||||
|
||||
beforeEach(async () => {
|
||||
const objectStub = KubeObject.create({
|
||||
apiVersion: "some-api-version",
|
||||
kind: "some-kind",
|
||||
metadata: {
|
||||
uid: "some-uid",
|
||||
name: "some-name",
|
||||
resourceVersion: "some-resource-version",
|
||||
namespace: "some-namespace",
|
||||
},
|
||||
});
|
||||
|
||||
({ baseElement } = render(
|
||||
<div>
|
||||
<ConfirmDialog />
|
||||
|
||||
<KubeObjectMenu
|
||||
object={objectStub}
|
||||
toolbar={true}
|
||||
removeAction={() => {}}
|
||||
/>
|
||||
</div>,
|
||||
));
|
||||
});
|
||||
|
||||
it("when removing kube object, renders confirmation dialog with namespace", () => {
|
||||
const menuItem = screen.getByTestId("menu-action-remove");
|
||||
|
||||
userEvent.click(menuItem);
|
||||
|
||||
expect(baseElement).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe("given kube object without namespace", () => {
|
||||
let baseElement: Element;
|
||||
|
||||
beforeEach(async () => {
|
||||
const objectStub = KubeObject.create({
|
||||
apiVersion: "some-api-version",
|
||||
kind: "some-kind",
|
||||
metadata: {
|
||||
uid: "some-uid",
|
||||
name: "some-name",
|
||||
resourceVersion: "some-resource-version",
|
||||
namespace: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
({ baseElement } = render(
|
||||
<div>
|
||||
<ConfirmDialog />
|
||||
|
||||
<KubeObjectMenu
|
||||
object={objectStub}
|
||||
toolbar={true}
|
||||
removeAction={() => {}}
|
||||
/>
|
||||
</div>,
|
||||
));
|
||||
});
|
||||
|
||||
it("when removing kube object, renders confirmation dialog without namespace", () => {
|
||||
const menuItem = screen.getByTestId("menu-action-remove");
|
||||
|
||||
userEvent.click(menuItem);
|
||||
|
||||
expect(baseElement).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const addDynamicMenuItem = ({
|
||||
di,
|
||||
apiVersions,
|
||||
kind,
|
||||
}: {
|
||||
di: ConfigurableDependencyInjectionContainer;
|
||||
apiVersions: string[];
|
||||
kind: string;
|
||||
}) => {
|
||||
const MenuItemComponent: React.FC = () => <li>Some menu item</li>;
|
||||
|
||||
const dynamicMenuItemStub: KubeObjectMenuRegistration = {
|
||||
apiVersions,
|
||||
kind,
|
||||
components: { MenuItem: MenuItemComponent },
|
||||
};
|
||||
|
||||
const kubeObjectMenuRegistry = di.inject(kubeObjectMenuRegistryInjectable);
|
||||
|
||||
kubeObjectMenuRegistry.add(dynamicMenuItemStub);
|
||||
};
|
||||
@ -22,25 +22,37 @@
|
||||
import React from "react";
|
||||
import { boundMethod, cssNames } from "../../utils";
|
||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
import { editResourceTab } from "../dock/edit-resource.store";
|
||||
import { MenuActions, MenuActionsProps } from "../menu/menu-actions";
|
||||
import { hideDetails } from "../kube-detail-params";
|
||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||
import { KubeObjectMenuRegistry } from "../../../extensions/registries/kube-object-menu-registry";
|
||||
import { MenuActions, MenuActionsProps } from "../menu";
|
||||
import identity from "lodash/identity";
|
||||
import type { ApiManager } from "../../../common/k8s-api/api-manager";
|
||||
|
||||
export interface KubeObjectMenuProps<T> extends MenuActionsProps {
|
||||
object: T | null | undefined;
|
||||
export interface KubeObjectMenuDependencies<TKubeObject> {
|
||||
apiManager: ApiManager;
|
||||
kubeObjectMenuItems: React.ElementType[];
|
||||
clusterName: string;
|
||||
hideDetails: () => void;
|
||||
editResourceTab: (kubeObject: TKubeObject) => void;
|
||||
}
|
||||
|
||||
export interface KubeObjectMenuProps<TKubeObject> extends MenuActionsProps {
|
||||
object: TKubeObject | null | undefined;
|
||||
editable?: boolean;
|
||||
removable?: boolean;
|
||||
}
|
||||
|
||||
export class KubeObjectMenu<T extends KubeObject> extends React.Component<KubeObjectMenuProps<T>> {
|
||||
export interface KubeObjectMenuPropsAndDependencies<TKubeObject>
|
||||
extends KubeObjectMenuProps<TKubeObject>,
|
||||
KubeObjectMenuDependencies<TKubeObject> {}
|
||||
|
||||
export class KubeObjectMenu<
|
||||
TKubeObject extends KubeObject,
|
||||
> extends React.Component<KubeObjectMenuPropsAndDependencies<TKubeObject>> {
|
||||
get store() {
|
||||
const { object } = this.props;
|
||||
|
||||
if (!object) return null;
|
||||
|
||||
return apiManager.getStore(object.selfLink);
|
||||
return this.props.apiManager.getStore(object.selfLink);
|
||||
}
|
||||
|
||||
get isEditable() {
|
||||
@ -53,13 +65,13 @@ export class KubeObjectMenu<T extends KubeObject> extends React.Component<KubeOb
|
||||
|
||||
@boundMethod
|
||||
async update() {
|
||||
hideDetails();
|
||||
editResourceTab(this.props.object);
|
||||
this.props.hideDetails();
|
||||
this.props.editResourceTab(this.props.object);
|
||||
}
|
||||
|
||||
@boundMethod
|
||||
async remove() {
|
||||
hideDetails();
|
||||
this.props.hideDetails();
|
||||
const { object, removeAction } = this.props;
|
||||
|
||||
if (removeAction) await removeAction();
|
||||
@ -74,28 +86,27 @@ export class KubeObjectMenu<T extends KubeObject> extends React.Component<KubeOb
|
||||
return null;
|
||||
}
|
||||
|
||||
const breadcrumbParts = [object.getNs(), object.getName()];
|
||||
|
||||
const breadcrumb = breadcrumbParts.filter(identity).join("/");
|
||||
|
||||
return (
|
||||
<p>Remove {object.kind} <b>{object.getName()}</b>?</p>
|
||||
<p>
|
||||
Remove {object.kind} <b>{breadcrumb}</b> from <b>{this.props.clusterName}</b>?
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
getMenuItems(): React.ReactChild[] {
|
||||
const { object, toolbar } = this.props;
|
||||
|
||||
if (!object) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return KubeObjectMenuRegistry
|
||||
.getInstance()
|
||||
.getItemsForKind(object.kind, object.apiVersion)
|
||||
.map(({ components: { MenuItem }}, index) => (
|
||||
<MenuItem
|
||||
object={object}
|
||||
key={`menu-item-${index}`}
|
||||
toolbar={toolbar}
|
||||
/>
|
||||
));
|
||||
return this.props.kubeObjectMenuItems.map((MenuItem, index) => (
|
||||
<MenuItem
|
||||
object={object}
|
||||
toolbar={toolbar}
|
||||
key={`menu-item-${index}`}
|
||||
/>
|
||||
));
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@ -30,7 +30,6 @@ import { Icon, IconProps } from "../icon";
|
||||
import { Menu, MenuItem, MenuProps } from "../menu";
|
||||
import uniqueId from "lodash/uniqueId";
|
||||
import isString from "lodash/isString";
|
||||
import { RenderDelay } from "../render-delay/render-delay";
|
||||
|
||||
export interface MenuActionsProps extends Partial<MenuProps> {
|
||||
className?: string;
|
||||
@ -125,32 +124,31 @@ export class MenuActions extends React.Component<MenuActionsProps> {
|
||||
return (
|
||||
<>
|
||||
{this.renderTriggerIcon()}
|
||||
<RenderDelay>
|
||||
<Menu
|
||||
htmlFor={this.id}
|
||||
isOpen={this.isOpen} open={this.toggle} close={this.toggle}
|
||||
className={menuClassName}
|
||||
usePortal={autoClose}
|
||||
closeOnScroll={autoClose}
|
||||
closeOnClickItem={autoCloseOnSelect ?? autoClose }
|
||||
closeOnClickOutside={autoClose}
|
||||
{...menuProps}
|
||||
>
|
||||
{children}
|
||||
{updateAction && (
|
||||
<MenuItem onClick={updateAction}>
|
||||
<Icon material="edit" interactive={toolbar} tooltip="Edit"/>
|
||||
<span className="title">Edit</span>
|
||||
</MenuItem>
|
||||
)}
|
||||
{removeAction && (
|
||||
<MenuItem onClick={this.remove}>
|
||||
<Icon material="delete" interactive={toolbar} tooltip="Delete"/>
|
||||
<span className="title">Delete</span>
|
||||
</MenuItem>
|
||||
)}
|
||||
</Menu>
|
||||
</RenderDelay>
|
||||
|
||||
<Menu
|
||||
htmlFor={this.id}
|
||||
isOpen={this.isOpen} open={this.toggle} close={this.toggle}
|
||||
className={menuClassName}
|
||||
usePortal={autoClose}
|
||||
closeOnScroll={autoClose}
|
||||
closeOnClickItem={autoCloseOnSelect ?? autoClose }
|
||||
closeOnClickOutside={autoClose}
|
||||
{...menuProps}
|
||||
>
|
||||
{children}
|
||||
{updateAction && (
|
||||
<MenuItem onClick={updateAction}>
|
||||
<Icon material="edit" interactive={toolbar} tooltip="Edit"/>
|
||||
<span className="title">Edit</span>
|
||||
</MenuItem>
|
||||
)}
|
||||
{removeAction && (
|
||||
<MenuItem onClick={this.remove} data-testid="menu-action-remove">
|
||||
<Icon material="delete" interactive={toolbar} tooltip="Delete"/>
|
||||
<span className="title">Delete</span>
|
||||
</MenuItem>
|
||||
)}
|
||||
</Menu>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
42
src/renderer/components/test-utils/renderFor.tsx
Normal file
42
src/renderer/components/test-utils/renderFor.tsx
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import React from "react";
|
||||
|
||||
import {
|
||||
render as testingLibraryRender,
|
||||
RenderResult,
|
||||
} from "@testing-library/react";
|
||||
|
||||
import type { ConfigurableDependencyInjectionContainer } from "@ogre-tools/injectable";
|
||||
|
||||
import { DiContextProvider } from "@ogre-tools/injectable-react";
|
||||
|
||||
export type DiRender = (ui: React.ReactElement) => RenderResult;
|
||||
|
||||
type DiRenderFor = (
|
||||
di: ConfigurableDependencyInjectionContainer,
|
||||
) => DiRender;
|
||||
|
||||
export const renderFor: DiRenderFor = di => ui =>
|
||||
testingLibraryRender(
|
||||
<DiContextProvider value={{ di }}>{ui}</DiContextProvider>,
|
||||
);
|
||||
|
||||
59
yarn.lock
59
yarn.lock
@ -7,6 +7,11 @@
|
||||
resolved "https://registry.yarnpkg.com/7zip-bin/-/7zip-bin-5.1.1.tgz#9274ec7460652f9c632c59addf24efb1684ef876"
|
||||
integrity sha512-sAP4LldeWNz0lNzmTird3uWfFDWWTeg6V/MsmyyLR9X1idwKBWIgt/ZvinqQldJm3LecKEs1emkbquO6PCiLVQ==
|
||||
|
||||
"@async-fn/jest@^1.5.0":
|
||||
version "1.5.0"
|
||||
resolved "https://registry.yarnpkg.com/@async-fn/jest/-/jest-1.5.0.tgz#dda820de3e48eca6d5b17b00a01bdb060dfcc233"
|
||||
integrity sha512-IeuTZj1TdoBS64fpNfHG9efw6dW3UQuIXfEv0qhxyNro3368kKz9E/eO46zvPmQBxbBCox3RCbKexAJH1WAY+Q==
|
||||
|
||||
"@babel/code-frame@7.12.11":
|
||||
version "7.12.11"
|
||||
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f"
|
||||
@ -14,13 +19,20 @@
|
||||
dependencies:
|
||||
"@babel/highlight" "^7.10.4"
|
||||
|
||||
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.1", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.8.3":
|
||||
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.1", "@babel/code-frame@^7.10.4":
|
||||
version "7.14.5"
|
||||
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.14.5.tgz#23b08d740e83f49c5e59945fbf1b43e80bbf4edb"
|
||||
integrity sha512-9pzDqyc6OLDaqe+zbACgFkb6fKMNG6CObKpnYXChRsvYGyEdc7CA2BaqeOM+vOtCS5ndmJicPJhKAwYRI6UfFw==
|
||||
dependencies:
|
||||
"@babel/highlight" "^7.14.5"
|
||||
|
||||
"@babel/code-frame@^7.8.3":
|
||||
version "7.16.0"
|
||||
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.16.0.tgz#0dfc80309beec8411e65e706461c408b0bb9b431"
|
||||
integrity sha512-IF4EOMEV+bfYwOmNxGzSnjR2EmQod7f1UXOpZM3l4i4o4QNwzjtJAu/HxdjHq0aYBvdqMuQEY1eg0nqW9ZPORA==
|
||||
dependencies:
|
||||
"@babel/highlight" "^7.16.0"
|
||||
|
||||
"@babel/core@^7.1.0", "@babel/core@^7.7.5":
|
||||
version "7.10.2"
|
||||
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.10.2.tgz#bd6786046668a925ac2bd2fd95b579b92a23b36a"
|
||||
@ -148,6 +160,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz#a78c7a7251e01f616512d31b10adcf52ada5e0d2"
|
||||
integrity sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==
|
||||
|
||||
"@babel/helper-validator-identifier@^7.15.7":
|
||||
version "7.15.7"
|
||||
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.15.7.tgz#220df993bfe904a4a6b02ab4f3385a5ebf6e2389"
|
||||
integrity sha512-K4JvCtQqad9OY2+yTU8w+E82ywk/fe+ELNlt1G8z3bVGlZfn/hOcQQsUhGhW/N+tb3fxK800wLtKOE/aM0m72w==
|
||||
|
||||
"@babel/helpers@^7.10.1":
|
||||
version "7.10.1"
|
||||
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.10.1.tgz#a6827b7cb975c9d9cef5fd61d919f60d8844a973"
|
||||
@ -175,6 +192,15 @@
|
||||
chalk "^2.0.0"
|
||||
js-tokens "^4.0.0"
|
||||
|
||||
"@babel/highlight@^7.16.0":
|
||||
version "7.16.0"
|
||||
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.16.0.tgz#6ceb32b2ca4b8f5f361fb7fd821e3fddf4a1725a"
|
||||
integrity sha512-t8MH41kUQylBtu2+4IQA3atqevA2lRgqA2wyVB/YiWmsDSuylZZuXOUy9ric30hfzauEFfdsuk/eXTRrGrfd0g==
|
||||
dependencies:
|
||||
"@babel/helper-validator-identifier" "^7.15.7"
|
||||
chalk "^2.0.0"
|
||||
js-tokens "^4.0.0"
|
||||
|
||||
"@babel/parser@^7.1.0", "@babel/parser@^7.10.1", "@babel/parser@^7.10.2":
|
||||
version "7.10.2"
|
||||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.10.2.tgz#871807f10442b92ff97e4783b9b54f6a0ca812d0"
|
||||
@ -953,19 +979,19 @@
|
||||
dependencies:
|
||||
lodash "^4.17.21"
|
||||
|
||||
"@ogre-tools/injectable-react@^1.2.1":
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-react/-/injectable-react-1.2.1.tgz#886fbb9f9816d68daf41b6fd7ff5def6eae833b4"
|
||||
integrity sha512-kr9Q2T/VyhtUG8EbfzpFPk2ndwKQl9WHzqEfp8fasAXMNmUfUnyWs6iPNoJiuy2gh4/CNBvlFB8c647ls6/jUA==
|
||||
"@ogre-tools/injectable-react@^1.3.1":
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-react/-/injectable-react-1.3.1.tgz#dec3829ac8cf295c32cfe636ca2cd39a495d56ce"
|
||||
integrity sha512-5jHL9Zcb3QkrttdzqJpN6iCXaV2+fEuDNigwH6NJ3uyV1iQWuRIctnlXxfa9qtZESwaAz7o0hAwkyqEl7YSA4g==
|
||||
dependencies:
|
||||
"@ogre-tools/fp" "^1.0.2"
|
||||
"@ogre-tools/injectable" "^1.2.1"
|
||||
"@ogre-tools/injectable" "^1.3.0"
|
||||
lodash "^4.17.21"
|
||||
|
||||
"@ogre-tools/injectable@^1.2.1":
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable/-/injectable-1.2.1.tgz#f3eb481806dd6e53af8d9d37f8b20f3c0d875a60"
|
||||
integrity sha512-bfTlnT08uDydE0i5GxJ9SIoRKfNYVabQRrZfBraZi2rs3zx+DOpcZrJjhjDoSCzIr6C2azySuyxn1h8x8CMUPw==
|
||||
"@ogre-tools/injectable@^1.3.0":
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable/-/injectable-1.3.0.tgz#87d329a81575c9345b3af5c1afb0b45537f8f70e"
|
||||
integrity sha512-rBy8HSExUy1r53ATvk823GXevwultKuSn3mmyRlIj7opJDVRp7Usx0bvOPs+X169jmAZNzsT6HBXbDLXt4Jl4A==
|
||||
dependencies:
|
||||
"@ogre-tools/fp" "^1.0.2"
|
||||
lodash "^4.17.21"
|
||||
@ -1532,7 +1558,12 @@
|
||||
"@types/parse5" "*"
|
||||
"@types/tough-cookie" "*"
|
||||
|
||||
"@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.6":
|
||||
"@types/json-schema@^7.0.4":
|
||||
version "7.0.9"
|
||||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
|
||||
integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==
|
||||
|
||||
"@types/json-schema@^7.0.5", "@types/json-schema@^7.0.6":
|
||||
version "7.0.7"
|
||||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
|
||||
integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==
|
||||
@ -9244,9 +9275,9 @@ mem@^1.1.0:
|
||||
mimic-fn "^1.0.0"
|
||||
|
||||
memfs@^3.1.2:
|
||||
version "3.2.2"
|
||||
resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.2.2.tgz#5de461389d596e3f23d48bb7c2afb6161f4df40e"
|
||||
integrity sha512-RE0CwmIM3CEvpcdK3rZ19BC4E6hv9kADkMN5rPduRak58cNArWLi/9jFLsa4rhsjfVxMP3v0jO7FHXq7SvFY5Q==
|
||||
version "3.3.0"
|
||||
resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.3.0.tgz#4da2d1fc40a04b170a56622c7164c6be2c4cbef2"
|
||||
integrity sha512-BEE62uMfKOavX3iG7GYX43QJ+hAeeWnwIAuJ/R6q96jaMtiLzhsxHJC8B1L7fK7Pt/vXDRwb3SG/yBpNGDPqzg==
|
||||
dependencies:
|
||||
fs-monkey "1.0.3"
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user