From f5087241a3c96d213e85cf22156006e1ce344238 Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Wed, 5 Feb 2025 22:14:14 +0300 Subject: [PATCH] R: Remove redundant checks --- .../src/components/RefsInput/RefsInput.tsx | 21 ++++++++++--------- rsconcept/frontend/src/models/rsformAPI.ts | 2 +- .../OssPage/EditorOssCard/EditorOssCard.tsx | 2 +- .../pages/OssPage/EditorOssCard/FormOSS.tsx | 3 --- .../src/pages/OssPage/OssEditContext.tsx | 3 --- .../EditorRSFormCard/EditorRSFormCard.tsx | 2 +- .../EditorRSFormCard/FormRSForm.tsx | 3 --- .../src/pages/RSFormPage/RSEditContext.tsx | 9 +++----- 8 files changed, 17 insertions(+), 28 deletions(-) diff --git a/rsconcept/frontend/src/components/RefsInput/RefsInput.tsx b/rsconcept/frontend/src/components/RefsInput/RefsInput.tsx index 4c2e1ed2..7455ec0b 100644 --- a/rsconcept/frontend/src/components/RefsInput/RefsInput.tsx +++ b/rsconcept/frontend/src/components/RefsInput/RefsInput.tsx @@ -63,15 +63,16 @@ interface RefsInputInputProps | 'onBlur' | 'placeholder' > { - label?: string; - onChange?: (newValue: string) => void; - schema?: IRSForm; - onOpenEdit?: (cstID: ConstituentaID) => void; - disabled?: boolean; - - initialValue?: string; value?: string; resolved?: string; + onChange?: (newValue: string) => void; + + schema: IRSForm; + onOpenEdit?: (cstID: ConstituentaID) => void; + + label?: string; + disabled?: boolean; + initialValue?: string; } const RefsInput = forwardRef( @@ -130,8 +131,8 @@ const RefsInput = forwardRef( EditorView.lineWrapping, EditorView.contentAttributes.of({ spellcheck: 'true' }), NaturalLanguage, - ...(!schema || !onOpenEdit ? [] : [refsNavigation(schema, onOpenEdit)]), - ...(schema ? [refsHoverTooltip(schema, onOpenEdit !== undefined)] : []) + ...(!onOpenEdit ? [] : [refsNavigation(schema, onOpenEdit)]), + refsHoverTooltip(schema, onOpenEdit !== undefined) ]; function handleChange(newValue: string) { @@ -149,7 +150,7 @@ const RefsInput = forwardRef( } function handleInput(event: React.KeyboardEvent) { - if (!thisRef.current?.view || !schema) { + if (!thisRef.current?.view) { event.preventDefault(); event.stopPropagation(); return; diff --git a/rsconcept/frontend/src/models/rsformAPI.ts b/rsconcept/frontend/src/models/rsformAPI.ts index 835aab16..5fc297e4 100644 --- a/rsconcept/frontend/src/models/rsformAPI.ts +++ b/rsconcept/frontend/src/models/rsformAPI.ts @@ -242,7 +242,7 @@ export function getDefinitionPrefix(cst: IConstituenta): string { */ export function generateAlias(type: CstType, schema: IRSForm, takenAliases: string[] = []): string { const prefix = getCstTypePrefix(type); - if (!schema.items || schema.items.length <= 0) { + if (schema.items.length <= 0) { return `${prefix}1`; } let index = schema.items.reduce((prev, cst, index) => { diff --git a/rsconcept/frontend/src/pages/OssPage/EditorOssCard/EditorOssCard.tsx b/rsconcept/frontend/src/pages/OssPage/EditorOssCard/EditorOssCard.tsx index ce8d9c90..60487d10 100644 --- a/rsconcept/frontend/src/pages/OssPage/EditorOssCard/EditorOssCard.tsx +++ b/rsconcept/frontend/src/pages/OssPage/EditorOssCard/EditorOssCard.tsx @@ -49,7 +49,7 @@ function EditorOssCard() { - {controller.schema ? : null} + ); diff --git a/rsconcept/frontend/src/pages/OssPage/EditorOssCard/FormOSS.tsx b/rsconcept/frontend/src/pages/OssPage/EditorOssCard/FormOSS.tsx index a720f8bb..4ec956be 100644 --- a/rsconcept/frontend/src/pages/OssPage/EditorOssCard/FormOSS.tsx +++ b/rsconcept/frontend/src/pages/OssPage/EditorOssCard/FormOSS.tsx @@ -70,9 +70,6 @@ function FormOSS({ id }: FormOSSProps) { if (event) { event.preventDefault(); } - if (!schema) { - return; - } const data: IUpdateLibraryItemDTO = { id: schema.id, item_type: LibraryItemType.RSFORM, diff --git a/rsconcept/frontend/src/pages/OssPage/OssEditContext.tsx b/rsconcept/frontend/src/pages/OssPage/OssEditContext.tsx index 160ecdc8..fd649894 100644 --- a/rsconcept/frontend/src/pages/OssPage/OssEditContext.tsx +++ b/rsconcept/frontend/src/pages/OssPage/OssEditContext.tsx @@ -120,9 +120,6 @@ export const OssEditState = ({ itemID, children }: React.PropsWithChildren - {controller.schema ? : null} + ); diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorRSFormCard/FormRSForm.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorRSFormCard/FormRSForm.tsx index e708ad52..664cc1b8 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/EditorRSFormCard/FormRSForm.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/EditorRSFormCard/FormRSForm.tsx @@ -80,9 +80,6 @@ function FormRSForm({ id }: FormRSFormProps) { if (event) { event.preventDefault(); } - if (!schema) { - return; - } const data: IUpdateLibraryItemDTO = { id: schema.id, item_type: LibraryItemType.RSFORM, diff --git a/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx b/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx index fb2b8031..e2f35759 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx @@ -139,9 +139,6 @@ export const RSEditState = ({ } function navigateRSForm({ tab, activeID }: { tab: RSTabID; activeID?: ConstituentaID }) { - if (!schema) { - return; - } const data = { id: schema.id, tab: tab, @@ -170,7 +167,7 @@ export const RSEditState = ({ } function deleteSchema() { - if (!schema || !window.confirm(prompts.deleteLibraryItem)) { + if (!window.confirm(prompts.deleteLibraryItem)) { return; } const ossID = schema.oss.length > 0 ? schema.oss[0].id : undefined; @@ -227,7 +224,7 @@ export const RSEditState = ({ } function moveUp() { - if (!schema.items || selected.length === 0) { + if (selected.length === 0) { return; } const currentIndex = schema.items.reduce((prev, cst, index) => { @@ -249,7 +246,7 @@ export const RSEditState = ({ } function moveDown() { - if (!schema.items || selected.length === 0) { + if (selected.length === 0) { return; } let count = 0;