Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const SchemaRendererNodeComponent: React.FC<SchemaRendererNodeProps> = ({
}) => {
const form = useForm();

const firstRenderRef = React.useRef(true);
const pendingTicksRef = React.useRef({input: 0, meta: 0});
const fieldRef = React.useRef<FieldState<any>>(null);
const unsubscribeRef = React.useRef<() => void>(null);
const [ticks, setTicks] = React.useState({input: 0, meta: 0});
Expand Down Expand Up @@ -88,7 +90,14 @@ const SchemaRendererNodeComponent: React.FC<SchemaRendererNodeProps> = ({
}

if (inputTick + metaTick) {
setTicks((t) => ({input: t.input + inputTick, meta: t.meta + metaTick}));
if (firstRenderRef.current) {
pendingTicksRef.current = {input: inputTick, meta: metaTick};
} else {
setTicks((t) => ({
input: t.input + inputTick,
meta: t.meta + metaTick,
}));
}
}
}

Expand Down Expand Up @@ -129,6 +138,15 @@ const SchemaRendererNodeComponent: React.FC<SchemaRendererNodeProps> = ({
}, [error, form, name, ticks.meta]);

React.useEffect(() => {
firstRenderRef.current = false;

if (pendingTicksRef.current.input || pendingTicksRef.current.meta) {
setTicks((t) => ({
input: t.input + pendingTicksRef.current.input,
meta: t.meta + pendingTicksRef.current.meta,
}));
}

return () => {
unsubscribeRef.current?.();
};
Expand Down
4 changes: 2 additions & 2 deletions src/lib/unstable/core/types/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface NodeLayoutProps<Schema extends JsonSchema, Props extends Record
export type NodeLayout<
Schema extends JsonSchema,
Props extends Record<string, any> = {},
> = React.ComponentType<NodeLayoutProps<Schema, Props>>;
> = React.FC<NodeLayoutProps<Schema, Props>>;

export interface NodeEntityProps<
Schema extends JsonSchema,
Expand All @@ -45,4 +45,4 @@ export type NodeEntity<
Schema extends JsonSchema,
Props extends Record<string, any> = {},
LayoutProps extends Record<string, any> = {},
> = React.ComponentType<NodeEntityProps<Schema, Props, LayoutProps>>;
> = React.FC<NodeEntityProps<Schema, Props, LayoutProps>>;
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ export interface ArrayRemoveButtonProps {
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
}

const ArrayRemoveButtonComponent: React.FC<ArrayRemoveButtonProps> = ({
name,
headName,
onClick,
}) => {
export const ArrayRemoveButton: React.FC<ArrayRemoveButtonProps> = ({name, headName, onClick}) => {
const form = useForm();

const [ready, setReady] = React.useState(false);
Expand Down Expand Up @@ -58,5 +54,3 @@ const ArrayRemoveButtonComponent: React.FC<ArrayRemoveButtonProps> = ({

return null;
};

export const ArrayRemoveButton = React.memo(ArrayRemoveButtonComponent);
7 changes: 3 additions & 4 deletions src/lib/unstable/kit/components/CopyButton/CopyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';

import {ClipboardButton} from '@gravity-ui/uikit';
import {isNumber, isString} from 'lodash';
import isNumber from 'lodash/isNumber';
import isString from 'lodash/isString';

import {block} from '../../utils';

Expand All @@ -15,7 +16,7 @@ export interface CopyButtonProps {
value: unknown;
}

const CopyButtonComponent: React.FC<CopyButtonProps> = ({className, copy, value}) => {
export const CopyButton: React.FC<CopyButtonProps> = ({className, copy, value}) => {
if (copy && (isString(value) || isNumber(value))) {
return (
<div className={b(null, className)}>
Expand All @@ -26,5 +27,3 @@ const CopyButtonComponent: React.FC<CopyButtonProps> = ({className, copy, value}

return null;
};

export const CopyButton = React.memo(CopyButtonComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import React from 'react';
import {DASH} from '../../constants';
import {EntityContainer} from '../EntityContainer';

const EmptyEntityValueComponent: React.FC = () => {
export const EmptyEntityValue: React.FC = () => {
return (
<EntityContainer stretch="fit" fill="empty">
{DASH}
</EntityContainer>
);
};

export const EmptyEntityValue = React.memo(EmptyEntityValueComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface EntityContainerProps extends FlexProps {
stretch: 'max' | 'fit' | 'by-child';
}

const EntityContainerComponent: React.FC<EntityContainerProps> = ({
export const EntityContainer: React.FC<EntityContainerProps> = ({
children,
fill,
stretch,
Expand All @@ -28,5 +28,3 @@ const EntityContainerComponent: React.FC<EntityContainerProps> = ({
</div>
);
};

export const EntityContainer = React.memo(EntityContainerComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface LayoutContainerProps extends FlexProps {
hideEmpty?: boolean;
}

const LayoutContainerComponent: React.FC<LayoutContainerProps> = ({
export const LayoutContainer: React.FC<LayoutContainerProps> = ({
className,
children,
hideEmpty = false,
Expand All @@ -25,5 +25,3 @@ const LayoutContainerComponent: React.FC<LayoutContainerProps> = ({
</Flex>
);
};

export const LayoutContainer = React.memo(LayoutContainerComponent);
4 changes: 1 addition & 3 deletions src/lib/unstable/kit/components/LongValue/LongValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface LongValueProps extends Omit<TextProps, 'children'> {
value?: string | number | boolean;
}

const LongValueComponent: React.FC<LongValueProps> = ({
export const LongValue: React.FC<LongValueProps> = ({
className,
color,
onClick,
Expand Down Expand Up @@ -77,5 +77,3 @@ const LongValueComponent: React.FC<LongValueProps> = ({
</Text>
);
};

export const LongValue = React.memo(LongValueComponent);
2 changes: 2 additions & 0 deletions src/lib/unstable/kit/constants/common.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const DASH = '—';

export const DEFAULT_DATE_FORMAT = 'DD.MM.YYYY HH:mm';
Loading
Loading