From 0592b39cf21f9cdc14c4f71744052b3ef90149d2 Mon Sep 17 00:00:00 2001 From: Bartosz Leper Date: Thu, 12 Dec 2024 16:43:13 +0100 Subject: [PATCH] Disable resetting to the standard model (#50048) * Disable resetting to the standard model * Review * Test fix * Fix a test --- .../RoleEditor/RequiresResetToStandard.tsx | 11 ++++----- .../src/Roles/RoleEditor/RoleEditor.test.tsx | 23 ++----------------- .../src/Roles/RoleEditor/StandardEditor.tsx | 16 +------------ 3 files changed, 7 insertions(+), 43 deletions(-) diff --git a/web/packages/teleport/src/Roles/RoleEditor/RequiresResetToStandard.tsx b/web/packages/teleport/src/Roles/RoleEditor/RequiresResetToStandard.tsx index 9b0b33bc4710f..67780c3e4ecbc 100644 --- a/web/packages/teleport/src/Roles/RoleEditor/RequiresResetToStandard.tsx +++ b/web/packages/teleport/src/Roles/RoleEditor/RequiresResetToStandard.tsx @@ -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 = () => ( - 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. - - Reset to Standard Settings - ); diff --git a/web/packages/teleport/src/Roles/RoleEditor/RoleEditor.test.tsx b/web/packages/teleport/src/Roles/RoleEditor/RoleEditor.test.tsx index 403c9f331255f..2d458fff5aebc 100644 --- a/web/packages/teleport/src/Roles/RoleEditor/RoleEditor.test.tsx +++ b/web/packages/teleport/src/Roles/RoleEditor/RoleEditor.test.tsx @@ -129,9 +129,7 @@ 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(); @@ -139,21 +137,6 @@ test('rendering and switching tabs for a non-standard role', async () => { 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 () => { @@ -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'); diff --git a/web/packages/teleport/src/Roles/RoleEditor/StandardEditor.tsx b/web/packages/teleport/src/Roles/RoleEditor/StandardEditor.tsx index 332283e0a57d4..f196096d462fe 100644 --- a/web/packages/teleport/src/Roles/RoleEditor/StandardEditor.tsx +++ b/web/packages/teleport/src/Roles/RoleEditor/StandardEditor.tsx @@ -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, @@ -217,9 +205,7 @@ export const StandardEditor = ({ return ( <> - {roleModel.requiresReset && ( - - )} + {roleModel.requiresReset && }