Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v17] Disable resetting to the standard model #50159

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
*/

import { Info } from 'design/Alert/Alert';
import { ButtonSecondary, Text } from 'design';
import { Text } from 'design';

export const RequiresResetToStandard = ({ reset }: { reset(): void }) => (
export const RequiresResetToStandard = () => (
<Info>
<Text>
Some fields were not readable by the standard editor. To continue editing,
go back to YAML editor or reset the affected fields to standard settings.
This role is too complex to be edited in the standard editor. To continue
editing, go back to YAML editor.
</Text>
<ButtonSecondary size="large" my={2} onClick={reset}>
Reset to Standard Settings
</ButtonSecondary>
</Info>
);
23 changes: 2 additions & 21 deletions web/packages/teleport/src/Roles/RoleEditor/RoleEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,14 @@ test('rendering and switching tabs for a non-standard role', async () => {
expect(screen.getByRole('button', { name: 'Update Role' })).toBeDisabled();

await user.click(getStandardEditorTab());
expect(
screen.getByRole('button', { name: 'Reset to Standard Settings' })
).toBeVisible();
expect(screen.getByText(/This role is too complex/)).toBeVisible();
expect(screen.getByLabelText('Role Name')).toHaveValue('some-role');
expect(screen.getByLabelText('Description')).toHaveValue('');
expect(screen.getByRole('button', { name: 'Update Role' })).toBeDisabled();

await user.click(getYamlEditorTab());
expect(fromFauxYaml(await getTextEditorContents())).toEqual(originalRole);
expect(screen.getByRole('button', { name: 'Update Role' })).toBeDisabled();

// Switch once again, reset to standard
await user.click(getStandardEditorTab());
expect(screen.getByRole('button', { name: 'Update Role' })).toBeDisabled();
await user.click(
screen.getByRole('button', { name: 'Reset to Standard Settings' })
);
expect(screen.getByRole('button', { name: 'Update Role' })).toBeEnabled();
await user.type(screen.getByLabelText('Description'), 'some description');

await user.click(getYamlEditorTab());
const editorContents = fromFauxYaml(await getTextEditorContents());
expect(editorContents.metadata.description).toBe('some description');
expect(editorContents.spec.deny).toEqual({});
expect(screen.getByRole('button', { name: 'Update Role' })).toBeEnabled();
});

test('switching tabs triggers validation', async () => {
Expand Down Expand Up @@ -192,9 +175,7 @@ test('switching tabs ignores standard model validation for a non-standard role',
);
expect(getYamlEditorTab()).toHaveAttribute('aria-selected', 'true');
await user.click(getStandardEditorTab());
expect(
screen.getByText(/Some fields were not readable by the standard editor/)
).toBeVisible();
expect(screen.getByText(/This role is too complex/)).toBeVisible();
await user.click(getYamlEditorTab());
// Proceed, even though our validation would consider the data invalid.
expect(getYamlEditorTab()).toHaveAttribute('aria-selected', 'true');
Expand Down
16 changes: 1 addition & 15 deletions web/packages/teleport/src/Roles/RoleEditor/StandardEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,6 @@ export const StandardEditor = ({
});
}

/**
* Resets the standard editor back into viewable state. The existing model
* has been already stripped from unsupported features by the parsing
* attempt, the only thing left to do is to set the `requiresReset` flag.
*/
function resetForStandardEditor() {
handleChange({
...standardEditorModel.roleModel,
requiresReset: false,
});
}

function addAccessSpec(kind: AccessSpecKind) {
handleChange({
...standardEditorModel.roleModel,
Expand Down Expand Up @@ -217,9 +205,7 @@ export const StandardEditor = ({

return (
<>
{roleModel.requiresReset && (
<RequiresResetToStandard reset={resetForStandardEditor} />
)}
{roleModel.requiresReset && <RequiresResetToStandard />}
<EditorWrapper
mute={standardEditorModel.roleModel.requiresReset}
data-testid="standard-editor"
Expand Down
Loading