From 4451b66c44d8935c2105f006a07556f5879a79b2 Mon Sep 17 00:00:00 2001 From: Alexander Krivonosov <31561808+GneyHabub@users.noreply.github.com> Date: Sat, 1 May 2021 09:08:32 +0300 Subject: [PATCH] Fix the problem with instant redirect (#390) * Fix the problem with instant redirect * Rewrite updateSchema thunk --- .../Schemas/Details/LatestVersionItem.tsx | 1 + .../Schemas/Details/SchemaVersion.tsx | 1 + .../LatestVersionItem.spec.tsx.snap | 1 + .../__snapshots__/SchemaVersion.spec.tsx.snap | 1 + .../src/components/Schemas/Edit/Edit.tsx | 38 ++++++--- .../__snapshots__/Edit.spec.tsx.snap | 6 ++ .../components/Schemas/New/NewContainer.ts | 8 +- .../common/JSONEditor/JSONEditor.tsx | 30 ++++--- .../actions/__test__/thunks/schemas.spec.ts | 73 +++-------------- .../src/redux/actions/actions.ts | 10 +-- .../src/redux/actions/thunks/schemas.ts | 80 ++++++++----------- .../src/redux/reducers/schemas/reducer.ts | 2 + 12 files changed, 112 insertions(+), 139 deletions(-) diff --git a/kafka-ui-react-app/src/components/Schemas/Details/LatestVersionItem.tsx b/kafka-ui-react-app/src/components/Schemas/Details/LatestVersionItem.tsx index 70f405af4ee..7a689a99cad 100644 --- a/kafka-ui-react-app/src/components/Schemas/Details/LatestVersionItem.tsx +++ b/kafka-ui-react-app/src/components/Schemas/Details/LatestVersionItem.tsx @@ -33,6 +33,7 @@ const LatestVersionItem: React.FC = ({
= ({ {id} ({ mode: 'onChange' }); @@ -62,15 +62,19 @@ const Edit = ({ compatibilityLevel: CompatibilityLevelCompatibilityEnum; newSchema: string; }) => { - await updateSchema( - schema, - newSchema, - schemaType, - compatibilityLevel, - clusterName, - subject - ); - history.push(clusterSchemaPath(clusterName, subject)); + try { + await updateSchema( + schema, + newSchema, + schemaType, + compatibilityLevel, + clusterName, + subject + ); + history.push(clusterSchemaPath(clusterName, subject)); + } catch (e) { + // do not redirect + } }, [schema, register, control, clusterName, subject, updateSchema, history] ); @@ -96,7 +100,7 @@ const Edit = ({
- {schemasAreFetched && !isSubmitting ? ( + {schemasAreFetched ? (
{Object.keys(SchemaType).map((type: string) => (
- diff --git a/kafka-ui-react-app/src/components/Schemas/Edit/__tests__/__snapshots__/Edit.spec.tsx.snap b/kafka-ui-react-app/src/components/Schemas/Edit/__tests__/__snapshots__/Edit.spec.tsx.snap index d7287b0de3b..a24c37681d0 100644 --- a/kafka-ui-react-app/src/components/Schemas/Edit/__tests__/__snapshots__/Edit.spec.tsx.snap +++ b/kafka-ui-react-app/src/components/Schemas/Edit/__tests__/__snapshots__/Edit.spec.tsx.snap @@ -48,6 +48,7 @@ exports[`Edit Component when schemas are fetched matches the snapshot 1`] = ` >