R: Remove redundant checks

This commit is contained in:
Ivan 2025-02-05 22:14:14 +03:00
parent e96ce964ca
commit f5087241a3
8 changed files with 17 additions and 28 deletions

View File

@ -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<ReactCodeMirrorRef, RefsInputInputProps>(
@ -130,8 +131,8 @@ const RefsInput = forwardRef<ReactCodeMirrorRef, RefsInputInputProps>(
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<ReactCodeMirrorRef, RefsInputInputProps>(
}
function handleInput(event: React.KeyboardEvent<HTMLDivElement>) {
if (!thisRef.current?.view || !schema) {
if (!thisRef.current?.view) {
event.preventDefault();
event.stopPropagation();
return;

View File

@ -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) => {

View File

@ -49,7 +49,7 @@ function EditorOssCard() {
<EditorLibraryItem controller={controller} />
</FlexColumn>
{controller.schema ? <OssStats stats={controller.schema.stats} /> : null}
<OssStats stats={controller.schema.stats} />
</div>
</>
);

View File

@ -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,

View File

@ -120,9 +120,6 @@ export const OssEditState = ({ itemID, children }: React.PropsWithChildren<OssEd
);
function navigateTab(tab: OssTabID) {
if (!schema) {
return;
}
const url = urls.oss_props({
id: schema.id,
tab: tab

View File

@ -48,7 +48,7 @@ function EditorRSFormCard() {
<EditorLibraryItem controller={controller} />
</FlexColumn>
{controller.schema ? <RSFormStats stats={controller.schema.stats} isArchive={controller.isArchive} /> : null}
<RSFormStats stats={controller.schema.stats} isArchive={controller.isArchive} />
</div>
</>
);

View File

@ -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,

View File

@ -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;