-
Notifications
You must be signed in to change notification settings - Fork 151
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 <eskopelitis@microsoft.com> Makefile: Add backend-coverage and backend-coverage-html To see the full coverage report in text or html in a browser. Signed-off-by: René Dudfield <renedudfield@microsoft.com> .github/workflows/backend-test: Add coverage report to PR comment This adds a line to the PR comment with a collapsable toggle so the user can click to see the full coverage report. Signed-off-by: René Dudfield <renedudfield@microsoft.com> .github/workflows/backend-test: Add coverage html report As an artifact, and link to the artifact to view in the browser. Signed-off-by: René Dudfield <renedudfield@microsoft.com> frontend CreateNamespaceButton: Remove aria label for create/cancel It was unnecessary. Signed-off-by: Vincent T <vtaylor@microsoft.com> frontend CreateNamespaceButton: Add Create Namespace label For the action button. Signed-off-by: Vincent T <vtaylor@microsoft.com> frontend CreateNamespaceButton: Add data-testid for all buttons Signed-off-by: Vincent T <vtaylor@microsoft.com>
- Loading branch information
Showing
33 changed files
with
1,449 additions
and
180 deletions.
There are no files selected for viewing
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
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
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, EditorDialog } from '../common'; | ||
|
||
export interface CreateResourceButtonProps { | ||
resourceClass: KubeObjectClass; | ||
} | ||
|
||
export function CreateResourceButton(props: CreateResourceButtonProps) { | ||
const { resourceClass } = props; | ||
const { t } = useTranslation(['glossary', 'translation']); | ||
const [openDialog, setOpenDialog] = React.useState(false); | ||
const [errorMessage, setErrorMessage] = React.useState(''); | ||
|
||
const baseObject = resourceClass.getBaseObject(); | ||
const resourceName = baseObject.kind; | ||
|
||
return ( | ||
<React.Fragment> | ||
<ActionButton | ||
color="primary" | ||
description={t('translation|Create {{ resourceName }}', { resourceName })} | ||
icon={'mdi:plus-circle'} | ||
onClick={() => { | ||
setOpenDialog(true); | ||
}} | ||
/> | ||
<EditorDialog | ||
item={baseObject} | ||
open={openDialog} | ||
onClose={() => setOpenDialog(false)} | ||
onSave={() => setOpenDialog(false)} | ||
saveLabel={t('translation|Apply')} | ||
errorMessage={errorMessage} | ||
onEditorChanged={() => setErrorMessage('')} | ||
title={t('translation|Create {{ resourceName }}', { resourceName })} | ||
/> | ||
</React.Fragment> | ||
); | ||
} |
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.