-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These changes introduce a new UI feature that allows users to create resources from the associated list view. Clicking the 'Create' button opens up the EditorDialog used in the generic 'Create / Apply' button, now accepting generic YAML/JSON text rather than explicitly expecting an item that looks like a Kubernetes resource. The dialog box also includes a generic template for each resource. The apply logic for this new feature (as well as the original 'Create / Apply' button) has been consolidated in EditorDialog, with a flag allowing external components to utilize their own dispatch functionality. Fixes: #1820 Signed-off-by: Evangelos Skopelitis <[email protected]>
- Loading branch information
Showing
65 changed files
with
6,059 additions
and
32 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
frontend/src/components/common/CreateResourceButton.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { expect, userEvent, waitFor } from '@storybook/test'; | ||
import { screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { KubeObjectClass } from '../../lib/k8s/cluster'; | ||
import ConfigMap from '../../lib/k8s/configMap'; | ||
import store from '../../redux/stores/store'; | ||
import { TestContext } from '../../test'; | ||
import { CreateResourceButton, CreateResourceButtonProps } from './CreateResourceButton'; | ||
|
||
export default { | ||
title: 'CreateResourceButton', | ||
component: CreateResourceButton, | ||
parameters: { | ||
storyshots: { | ||
disable: true, | ||
}, | ||
}, | ||
decorators: [ | ||
Story => { | ||
return ( | ||
<Provider store={store}> | ||
<TestContext> | ||
<Story /> | ||
</TestContext> | ||
</Provider> | ||
); | ||
}, | ||
], | ||
} as Meta; | ||
|
||
type Story = StoryObj<CreateResourceButtonProps>; | ||
|
||
export const ValidResource: Story = { | ||
args: { resourceClass: ConfigMap as unknown as KubeObjectClass }, | ||
|
||
play: async ({ args }) => { | ||
await userEvent.click( | ||
screen.getByRole('button', { | ||
name: `Create ${args.resourceClass.getBaseObject().kind}`, | ||
}) | ||
); | ||
|
||
await waitFor(() => expect(screen.getByRole('textbox')).toBeVisible()); | ||
|
||
await userEvent.click(screen.getByRole('textbox')); | ||
|
||
await userEvent.keyboard('{Control>}a{/Control} {Backspace}'); | ||
await userEvent.keyboard(`apiVersion: v1{Enter}`); | ||
await userEvent.keyboard(`kind: ConfigMap{Enter}`); | ||
await userEvent.keyboard(`metadata:{Enter}`); | ||
await userEvent.keyboard(` name: base-configmap`); | ||
|
||
const button = await screen.findByRole('button', { name: 'Apply' }); | ||
expect(button).toBeVisible(); | ||
}, | ||
}; | ||
|
||
export const InvalidResource: Story = { | ||
args: { resourceClass: ConfigMap as unknown as KubeObjectClass }, | ||
|
||
play: async ({ args }) => { | ||
await userEvent.click( | ||
screen.getByRole('button', { | ||
name: `Create ${args.resourceClass.getBaseObject().kind}`, | ||
}) | ||
); | ||
|
||
await waitFor(() => expect(screen.getByRole('textbox')).toBeVisible()); | ||
|
||
await userEvent.click(screen.getByRole('textbox')); | ||
|
||
await userEvent.keyboard('{Control>}a{/Control}'); | ||
await userEvent.keyboard(`apiVersion: v1{Enter}`); | ||
await userEvent.keyboard(`kind: ConfigMap{Enter}`); | ||
await userEvent.keyboard(`metadata:{Enter}`); | ||
await userEvent.keyboard(` name: base-configmap{Enter}`); | ||
await userEvent.keyboard(`creationTimestamp: ''`); | ||
|
||
const button = await screen.findByRole('button', { name: 'Apply' }); | ||
expect(button).toBeVisible(); | ||
|
||
await userEvent.click(button); | ||
|
||
await waitFor(() => | ||
userEvent.click( | ||
screen.getByRole('button', { | ||
name: `Create ${args.resourceClass.getBaseObject().kind}`, | ||
}) | ||
) | ||
); | ||
|
||
await waitFor(() => expect(screen.getByText(/Failed/)).toBeVisible(), { | ||
timeout: 15000, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { KubeObjectClass } from '../../lib/k8s/cluster'; | ||
import { ActionButton, AuthVisible, EditorDialog } from '../common'; | ||
|
||
export interface CreateResourceButtonProps { | ||
resourceClass: KubeObjectClass; | ||
resourceName?: string; | ||
} | ||
|
||
export function CreateResourceButton(props: CreateResourceButtonProps) { | ||
const { resourceClass, resourceName } = props; | ||
const { t } = useTranslation(['glossary', 'translation']); | ||
const [openDialog, setOpenDialog] = React.useState(false); | ||
const [errorMessage, setErrorMessage] = React.useState(''); | ||
|
||
const baseObject = resourceClass.getBaseObject(); | ||
const name = resourceName ?? baseObject.kind; | ||
|
||
return ( | ||
<AuthVisible item={resourceClass} authVerb="create"> | ||
<ActionButton | ||
color="primary" | ||
description={t('translation|Create {{ name }}', { name })} | ||
icon={'mdi:plus-circle'} | ||
onClick={() => { | ||
setOpenDialog(true); | ||
}} | ||
/> | ||
<EditorDialog | ||
item={baseObject} | ||
open={openDialog} | ||
onClose={() => setOpenDialog(false)} | ||
saveLabel={t('translation|Apply')} | ||
errorMessage={errorMessage} | ||
onEditorChanged={() => setErrorMessage('')} | ||
title={t('translation|Create {{ name }}', { name })} | ||
/> | ||
</AuthVisible> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
frontend/src/components/common/Resource/ViewButton.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...src/components/common/__snapshots__/CreateResourceButton.ConfigMapStory.stories.storyshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<DocumentFragment /> |
13 changes: 13 additions & 0 deletions
13
...rc/components/common/__snapshots__/CreateResourceButton.InvalidResource.stories.storyshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<DocumentFragment> | ||
<button | ||
aria-label="Create ConfigMap" | ||
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-whz9ym-MuiButtonBase-root-MuiIconButton-root" | ||
data-mui-internal-clone-element="true" | ||
tabindex="0" | ||
type="button" | ||
> | ||
<span | ||
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root" | ||
/> | ||
</button> | ||
</DocumentFragment> |
13 changes: 13 additions & 0 deletions
13
.../src/components/common/__snapshots__/CreateResourceButton.ValidResource.stories.storyshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<DocumentFragment> | ||
<button | ||
aria-label="Create ConfigMap" | ||
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-whz9ym-MuiButtonBase-root-MuiIconButton-root" | ||
data-mui-internal-clone-element="true" | ||
tabindex="0" | ||
type="button" | ||
> | ||
<span | ||
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root" | ||
/> | ||
</button> | ||
</DocumentFragment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.