Skip to content

Commit

Permalink
CB-4601 use more specific prop name (#2443)
Browse files Browse the repository at this point in the history
Co-authored-by: mr-anton-t <[email protected]>
  • Loading branch information
devnaumov and mr-anton-t authored Mar 5, 2024
1 parent 6d4bb86 commit 23328e7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions webapp/packages/core-blocks/src/CommonDialog/RenameDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { CommonDialogWrapper } from './CommonDialog/CommonDialogWrapper';
import style from './RenameDialog.m.css';

interface IRenameDialogState {
value: string;
name: string;
message: string | undefined;
valid: boolean;
payload: RenameDialogPayload;
Expand All @@ -38,7 +38,7 @@ interface IRenameDialogState {
}

export interface RenameDialogPayload {
value: string;
name: string;
objectName?: string;
icon?: string;
subTitle?: string;
Expand All @@ -60,7 +60,7 @@ export const RenameDialog: DialogComponent<RenameDialogPayload, string> = observ
const [focusedRef] = useFocus<HTMLFormElement>({ focusFirstChild: true });
const styles = useS(style);

const { icon, subTitle, bigIcon, viewBox, value, objectName, create, confirmActionText } = payload;
const { icon, subTitle, bigIcon, viewBox, name, objectName, create, confirmActionText } = payload;
let { title } = payload;

if (!title) {
Expand All @@ -75,19 +75,19 @@ export const RenameDialog: DialogComponent<RenameDialogPayload, string> = observ

const state = useObservableRef<IRenameDialogState>(
() => ({
value,
name,
message: undefined,
valid: true,
validate: throttleAsync(async () => {
state.message = undefined;
state.valid = (await state.payload.validation?.(state.value, state.setMessage.bind(state))) ?? true;
state.valid = (await state.payload.validation?.(state.name, state.setMessage.bind(state))) ?? true;
}, 300),
setMessage(message) {
this.message = message;
},
}),
{
value: observable.ref,
name: observable.ref,
valid: observable.ref,
message: observable.ref,
},
Expand All @@ -98,17 +98,17 @@ export const RenameDialog: DialogComponent<RenameDialogPayload, string> = observ

useEffect(() => {
state.validate();
}, [value]);
}, [name]);

const errorMessage = state.valid ? ' ' : translate(state.message ?? 'ui_rename_taken_or_invalid');

return (
<CommonDialogWrapper size="small" className={className} fixedWidth>
<CommonDialogHeader title={title} subTitle={subTitle} icon={icon} viewBox={viewBox} bigIcon={bigIcon} onReject={rejectDialog} />
<CommonDialogBody>
<Form ref={focusedRef} onSubmit={() => resolveDialog(state.value)}>
<Form ref={focusedRef} onSubmit={() => resolveDialog(state.name)}>
<Container center>
<InputField name="value" state={state} error={!state.valid} description={errorMessage} onChange={() => state.validate()}>
<InputField name="name" state={state} error={!state.valid} description={errorMessage} onChange={() => state.validate()}>
{translate('ui_name') + ':'}
</InputField>
</Container>
Expand All @@ -119,7 +119,7 @@ export const RenameDialog: DialogComponent<RenameDialogPayload, string> = observ
{translate('ui_processing_cancel')}
</Button>
<Fill />
<Button type="button" mod={['unelevated']} disabled={!state.valid} onClick={() => resolveDialog(state.value)}>
<Button type="button" mod={['unelevated']} disabled={!state.valid} onClick={() => resolveDialog(state.name)}>
{translate(confirmActionText || (create ? 'ui_create' : 'ui_rename'))}
</Button>
</CommonDialogFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class NavTreeRMContextMenuService extends Bootstrap {
actions.rename(save);
} else {
const result = await this.commonDialogService.open(RenameDialog, {
value: key.name ?? '',
name: key.name ?? '',
subTitle: key.name,
objectName: node.nodeType || 'Object',
icon: node.icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class NavNodeContextMenuService extends Bootstrap {
actions.rename(save);
} else {
const result = await this.commonDialogService.open(RenameDialog, {
value: name,
name,
subTitle: name,
objectName: node.nodeType || 'Object',
icon: node.icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class SqlEditorBootstrap extends Bootstrap {
const regexp = /^(.*?)(\.\w+)$/gi.exec(name);

const result = await this.commonDialogService.open(RenameDialog, {
value: regexp?.[1] ?? name,
name: regexp?.[1] ?? name,
objectName: name,
icon: dataSource.icon,
validation: name =>
Expand Down

0 comments on commit 23328e7

Please sign in to comment.