Skip to content

Commit 6a25b6e

Browse files
author
Alex Stephens
committed
CodeRabbit fix and remove any
1 parent 3cf3014 commit 6a25b6e

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

shesha-reactjs/src/components/autocomplete/models.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export function getColumns(fields: string[]): IDataColumnsProps[] {
2727

2828
export type AutocompleteDataSourceType = 'entitiesList' | 'url';
2929

30-
export type QueryParamFunc = (searchText: string, selected: any[]) => object;
31-
export type FilterSelectedFunc = (value: any) => object;
32-
export type KayValueFunc = (value: any, args: any) => string;
33-
export type DisplayValueFunc = (value: any, args: any) => string;
34-
export type OutcomeValueFunc = (value: any, args: any) => string | string[] | IEntityReferenceDto | IEntityReferenceDto[] | any;
30+
export type QueryParamFunc = (searchText: string, selected: unknown[]) => object;
31+
export type FilterSelectedFunc = (unknown) => object;
32+
export type KayValueFunc = (value: unknown, args: object) => unknown;
33+
export type DisplayValueFunc = (value: unknown, args: object) => string;
34+
export type OutcomeValueFunc = (value: unknown, args: object) => string | string[] | IEntityReferenceDto | IEntityReferenceDto[] | any;
3535

3636
export interface ISelectOption<TValue = any> {
3737
// TODO: make generic

shesha-reactjs/src/designer-components/autocomplete/autocomplete.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { migratePrevStyles } from '../_common-migrations/migrateStyles';
2424
import { useMetadataDispatcher } from '@/providers';
2525
import { useAsyncMemo } from '@/hooks/useAsyncMemo';
2626
import { isEntityTypeIdEmpty } from '@/providers/metadataDispatcher/entities/utils';
27+
import { isEntityReferenceId } from '@/utils/entity';
28+
import { isDefined } from '@/utils/nullables';
2729

2830
const AutocompleteComponent: AutocompleteComponentDefinition = {
2931
type: 'autocomplete',
@@ -47,36 +49,41 @@ const AutocompleteComponent: AutocompleteComponentDefinition = {
4749
const keyPropName = model.keyPropName || (model.dataSourceType === 'entitiesList' ? 'id' : 'value');
4850
const displayPropName = model.displayPropName || (model.dataSourceType === 'entitiesList' ? '_displayName' : 'displayText');
4951

50-
const keyValueFunc: KayValueFunc = useCallback((value: any, args: any) => {
52+
const keyValueFunc: KayValueFunc = useCallback((value: unknown, args: object) => {
53+
if (!isDefined(value)) return value;
5154
if (model.valueFormat === 'custom' && model.keyValueFunc)
5255
return executeExpression<string>(model.keyValueFunc, { ...args, value }, null, null);
53-
if (model.valueFormat === 'entityReference')
56+
if (model.valueFormat === 'entityReference' && isEntityReferenceId(value))
5457
return value?.id;
55-
return typeof (value) === 'object' ? getValueByPropertyName(value, keyPropName) : value;
58+
return typeof (value) === 'object' ? getValueByPropertyName(value as Record<string, unknown>, keyPropName) : value;
5659
}, [model.valueFormat, model.keyValueFunc, keyPropName]);
5760

58-
const outcomeValueFunc: OutcomeValueFunc = useCallback((item: any, args: any) => {
61+
const outcomeValueFunc: OutcomeValueFunc = useCallback((item: unknown, args: object) => {
62+
if (!isDefined(item)) return item;
5963
if (model.valueFormat === 'entityReference')
60-
return Boolean(item)
64+
return isEntityReferenceId(item)
6165
? {
6266
id: item.id,
63-
_displayName: item._displayName || getValueByPropertyName(item, displayPropName),
67+
_displayName: getValueByPropertyName(item as Record<string, unknown>, displayPropName) || item._displayName,
6468
_className: (item._className || entityMetadata?.fullClassName) ?? undefined,
6569
}
66-
: null;
70+
: typeof (item) !== 'object'
71+
? { id: item, _displayName: item?.toString(), _className: undefined }
72+
: item;
6773
if (model.valueFormat === 'custom' && model.outcomeValueFunc)
6874
return executeExpression(model.outcomeValueFunc, { ...args, item: item }, null, null);
69-
return typeof (item) === 'object' ? getValueByPropertyName(item, keyPropName) : item;
75+
return typeof (item) === 'object' ? getValueByPropertyName(item as Record<string, unknown>, keyPropName) : item;
7076
}, [model.valueFormat, model.outcomeValueFunc, keyPropName, displayPropName, entityMetadata]);
7177

72-
const displayValueFunc: OutcomeValueFunc = useCallback((value: any, args: any) => {
78+
const displayValueFunc: OutcomeValueFunc = useCallback((value: unknown, args: object) => {
79+
if (!isDefined(value)) return value;
7380
if (model.displayValueFunc)
7481
return executeExpression(model.displayValueFunc, { ...args, item: value }, null, null);
75-
return (typeof (value) === 'object' ? getValueByPropertyName(value, displayPropName) : value) || '';
82+
return (typeof (value) === 'object' ? getValueByPropertyName(value as Record<string, unknown>, displayPropName) : value) || '';
7683
}, [model.displayValueFunc, displayPropName]);
7784

78-
const filterKeysFunc: FilterSelectedFunc = useCallback((value: any | any[]) => {
79-
const localValue = value?.length === 1 ? value[0] : value;
85+
const filterKeysFunc: FilterSelectedFunc = useCallback((value: unknown) => {
86+
const localValue = Array.isArray(value) && value?.length === 1 ? value[0] : value;
8087
return Array.isArray(localValue)
8188
? { or: localValue.map((x) => executeExpression(model.filterKeysFunc, { value: x }, null, null)) }
8289
: executeExpression(model.filterKeysFunc, { value: localValue }, null, null);

shesha-reactjs/src/designer-components/slider/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ const SliderComponent: SliderComponentDefinition = {
5454
m.add<ISliderComponentPropsV0>(0, (prev) => ({ ...prev }))
5555
.add<ISliderComponentProps>(1, (prev) => ({
5656
...prev,
57-
min: prev?.min ? parseInt(prev.min, 10) : undefined,
58-
max: prev?.max ? parseInt(prev.max, 10) : undefined,
57+
min: prev?.min && prev.min !== '' ? parseInt(prev.min, 10) : undefined,
58+
max: prev?.max && prev.max !== '' ? parseInt(prev.max, 10) : undefined,
5959
})),
6060
};
6161

shesha-reactjs/src/designer-components/slider/interfaces.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { ComponentDefinition } from '@/interfaces';
22
import { IConfigurableFormComponent } from '@/providers/form/models';
33

4+
/** @deprecated Use ISliderComponentProps instead */
45
export interface ISliderComponentPropsV0 extends IConfigurableFormComponent {
6+
/** @deprecated legacy (string min/max). Use ISliderComponentProps (number min/max). */
57
min?: string;
8+
/** @deprecated legacy (string min/max). Use ISliderComponentProps (number min/max). */
69
max?: string;
710
}
811

0 commit comments

Comments
 (0)