Skip to content

Commit

Permalink
Disable resetting to the standard model (#50048) (#50159)
Browse files Browse the repository at this point in the history
* Disable resetting to the standard model

* Review

* Test fix

* Fix a test
  • Loading branch information
bl-nero authored Dec 13, 2024
1 parent ab16870 commit 8876ffc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 42 deletions.
2 changes: 1 addition & 1 deletion e
Submodule e updated from a4d6a1 to be16ae
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: 'Save Changes' })).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: 'Save Changes' })).toBeDisabled();

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

// Switch once again, reset to standard
await user.click(getStandardEditorTab());
expect(screen.getByRole('button', { name: 'Save Changes' })).toBeDisabled();
await user.click(
screen.getByRole('button', { name: 'Reset to Standard Settings' })
);
expect(screen.getByRole('button', { name: 'Save Changes' })).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: 'Save Changes' })).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
14 changes: 1 addition & 13 deletions web/packages/teleport/src/Roles/RoleEditor/StandardEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,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 @@ -223,7 +211,7 @@ export const StandardEditor = ({
<>
{roleModel.requiresReset && (
<Box mx={3}>
<RequiresResetToStandard reset={resetForStandardEditor} />
<RequiresResetToStandard />
</Box>
)}
<EditorWrapper
Expand Down

0 comments on commit 8876ffc

Please sign in to comment.