Skip to content

Commit b4db065

Browse files
Attila Csehcsehatt741
authored andcommitted
code review changes
1 parent c98d016 commit b4db065

File tree

10 files changed

+75
-111
lines changed

10 files changed

+75
-111
lines changed

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/FloatField/FloatFieldInput.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const FloatFieldInput = memo(
1313
props: FieldComponentProps<FloatFieldInputInstance, FloatFieldInputTemplate, { settings?: NodeFieldFloatSettings }>
1414
) => {
1515
const { nodeId, field, fieldTemplate, settings } = props;
16-
const { defaultValue, onChange, min, max, step, fineStep, constrainValue, showShuffle, handleClickRandomizeValue } =
16+
const { defaultValue, onChange, min, max, step, fineStep, constrainValue, showShuffle, randomizeValue } =
1717
useFloatField(nodeId, field.name, fieldTemplate, settings);
1818

1919
const { t } = useTranslation();
@@ -33,13 +33,7 @@ export const FloatFieldInput = memo(
3333
constrainValue={constrainValue}
3434
/>
3535
{showShuffle && (
36-
<Button
37-
size="sm"
38-
isDisabled={false}
39-
onClick={handleClickRandomizeValue}
40-
leftIcon={<PiShuffleBold />}
41-
flexShrink={0}
42-
>
36+
<Button size="sm" isDisabled={false} onClick={randomizeValue} leftIcon={<PiShuffleBold />} flexShrink={0}>
4337
{t('workflows.builder.shuffle')}
4438
</Button>
4539
)}

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/FloatField/FloatFieldInputAndSlider.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const FloatFieldInputAndSlider = memo(
1313
props: FieldComponentProps<FloatFieldInputInstance, FloatFieldInputTemplate, { settings?: NodeFieldFloatSettings }>
1414
) => {
1515
const { nodeId, field, fieldTemplate, settings } = props;
16-
const { defaultValue, onChange, min, max, step, fineStep, constrainValue, showShuffle, handleClickRandomizeValue } =
16+
const { defaultValue, onChange, min, max, step, fineStep, constrainValue, showShuffle, randomizeValue } =
1717
useFloatField(nodeId, field.name, fieldTemplate, settings);
1818

1919
const { t } = useTranslation();
@@ -46,13 +46,7 @@ export const FloatFieldInputAndSlider = memo(
4646
constrainValue={constrainValue}
4747
/>
4848
{showShuffle && (
49-
<Button
50-
size="sm"
51-
isDisabled={false}
52-
onClick={handleClickRandomizeValue}
53-
leftIcon={<PiShuffleBold />}
54-
flexShrink={0}
55-
>
49+
<Button size="sm" isDisabled={false} onClick={randomizeValue} leftIcon={<PiShuffleBold />} flexShrink={0}>
5650
{t('workflows.builder.shuffle')}
5751
</Button>
5852
)}

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/FloatField/FloatFieldSlider.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const FloatFieldSlider = memo(
1313
props: FieldComponentProps<FloatFieldInputInstance, FloatFieldInputTemplate, { settings?: NodeFieldFloatSettings }>
1414
) => {
1515
const { nodeId, field, fieldTemplate, settings } = props;
16-
const { defaultValue, onChange, min, max, step, fineStep, showShuffle, handleClickRandomizeValue } = useFloatField(
16+
const { defaultValue, onChange, min, max, step, fineStep, showShuffle, randomizeValue } = useFloatField(
1717
nodeId,
1818
field.name,
1919
fieldTemplate,
@@ -38,13 +38,7 @@ export const FloatFieldSlider = memo(
3838
flex="1 1 0"
3939
/>
4040
{showShuffle && (
41-
<Button
42-
size="sm"
43-
isDisabled={false}
44-
onClick={handleClickRandomizeValue}
45-
leftIcon={<PiShuffleBold />}
46-
flexShrink={0}
47-
>
41+
<Button size="sm" isDisabled={false} onClick={randomizeValue} leftIcon={<PiShuffleBold />} flexShrink={0}>
4842
{t('workflows.builder.shuffle')}
4943
</Button>
5044
)}

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/FloatField/useFloatField.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const useFloatField = (
7878
[dispatch, fieldName, nodeId]
7979
);
8080

81-
const handleClickRandomizeValue = useCallback(() => {
81+
const randomizeValue = useCallback(() => {
8282
const value = Number((Math.round(randomFloat(min, max) / step) * step).toFixed(10));
8383
dispatch(fieldFloatValueChanged({ nodeId, fieldName, value }));
8484
}, [dispatch, fieldName, nodeId, min, max, step]);
@@ -92,6 +92,6 @@ export const useFloatField = (
9292
fineStep,
9393
constrainValue,
9494
showShuffle,
95-
handleClickRandomizeValue,
95+
randomizeValue,
9696
};
9797
};

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/IntegerField/IntegerFieldInput.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,16 @@ export const IntegerFieldInput = memo(
1717
>
1818
) => {
1919
const { nodeId, field, fieldTemplate, settings } = props;
20-
const {
21-
defaultValue,
22-
onValueChange,
23-
min,
24-
max,
25-
step,
26-
fineStep,
27-
constrainValue,
28-
showShuffle,
29-
handleClickRandomizeValue,
30-
} = useIntegerField(nodeId, field.name, fieldTemplate, settings);
20+
const { defaultValue, onChange, min, max, step, fineStep, constrainValue, showShuffle, randomizeValue } =
21+
useIntegerField(nodeId, field.name, fieldTemplate, settings);
3122

3223
const { t } = useTranslation();
3324

3425
return (
3526
<>
3627
<CompositeNumberInput
3728
defaultValue={defaultValue}
38-
onChange={onValueChange}
29+
onChange={onChange}
3930
value={field.value}
4031
min={min}
4132
max={max}
@@ -46,13 +37,7 @@ export const IntegerFieldInput = memo(
4637
constrainValue={constrainValue}
4738
/>
4839
{showShuffle && (
49-
<Button
50-
size="sm"
51-
isDisabled={false}
52-
onClick={handleClickRandomizeValue}
53-
leftIcon={<PiShuffleBold />}
54-
flexShrink={0}
55-
>
40+
<Button size="sm" isDisabled={false} onClick={randomizeValue} leftIcon={<PiShuffleBold />} flexShrink={0}>
5641
{t('workflows.builder.shuffle')}
5742
</Button>
5843
)}

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/IntegerField/IntegerFieldInputAndSlider.tsx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,16 @@ export const IntegerFieldInputAndSlider = memo(
1717
>
1818
) => {
1919
const { nodeId, field, fieldTemplate, settings } = props;
20-
const {
21-
defaultValue,
22-
onValueChange,
23-
min,
24-
max,
25-
step,
26-
fineStep,
27-
constrainValue,
28-
showShuffle,
29-
handleClickRandomizeValue,
30-
} = useIntegerField(nodeId, field.name, fieldTemplate, settings);
20+
const { defaultValue, onChange, min, max, step, fineStep, constrainValue, showShuffle, randomizeValue } =
21+
useIntegerField(nodeId, field.name, fieldTemplate, settings);
3122

3223
const { t } = useTranslation();
3324

3425
return (
3526
<>
3627
<CompositeSlider
3728
defaultValue={defaultValue}
38-
onChange={onValueChange}
29+
onChange={onChange}
3930
value={field.value}
4031
min={min}
4132
max={max}
@@ -48,7 +39,7 @@ export const IntegerFieldInputAndSlider = memo(
4839
/>
4940
<CompositeNumberInput
5041
defaultValue={defaultValue}
51-
onChange={onValueChange}
42+
onChange={onChange}
5243
value={field.value}
5344
min={min}
5445
max={max}
@@ -59,13 +50,7 @@ export const IntegerFieldInputAndSlider = memo(
5950
constrainValue={constrainValue}
6051
/>
6152
{showShuffle && (
62-
<Button
63-
size="sm"
64-
isDisabled={false}
65-
onClick={handleClickRandomizeValue}
66-
leftIcon={<PiShuffleBold />}
67-
flexShrink={0}
68-
>
53+
<Button size="sm" isDisabled={false} onClick={randomizeValue} leftIcon={<PiShuffleBold />} flexShrink={0}>
6954
{t('workflows.builder.shuffle')}
7055
</Button>
7156
)}

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/IntegerField/IntegerFieldSlider.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ export const IntegerFieldSlider = memo(
1717
>
1818
) => {
1919
const { nodeId, field, fieldTemplate, settings } = props;
20-
const { defaultValue, onValueChange, min, max, step, fineStep, showShuffle, handleClickRandomizeValue } =
21-
useIntegerField(nodeId, field.name, fieldTemplate, settings);
20+
const { defaultValue, onChange, min, max, step, fineStep, showShuffle, randomizeValue } = useIntegerField(
21+
nodeId,
22+
field.name,
23+
fieldTemplate,
24+
settings
25+
);
2226

2327
const { t } = useTranslation();
2428

2529
return (
2630
<>
2731
<CompositeSlider
2832
defaultValue={defaultValue}
29-
onChange={onValueChange}
33+
onChange={onChange}
3034
value={field.value}
3135
min={min}
3236
max={max}
@@ -38,13 +42,7 @@ export const IntegerFieldSlider = memo(
3842
flex="1 1 0"
3943
/>
4044
{showShuffle && (
41-
<Button
42-
size="sm"
43-
isDisabled={false}
44-
onClick={handleClickRandomizeValue}
45-
leftIcon={<PiShuffleBold />}
46-
flexShrink={0}
47-
>
45+
<Button size="sm" isDisabled={false} onClick={randomizeValue} leftIcon={<PiShuffleBold />} flexShrink={0}>
4846
{t('workflows.builder.shuffle')}
4947
</Button>
5048
)}

invokeai/frontend/web/src/features/nodes/components/flow/nodes/Invocation/fields/IntegerField/useIntegerField.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,27 @@ export const useIntegerField = (
7070
[max, min, overrideMax, overrideMin, overrideStep, step]
7171
);
7272

73-
const onValueChange = useCallback(
73+
const onChange = useCallback(
7474
(value: number) => {
7575
dispatch(fieldIntegerValueChanged({ nodeId, fieldName, value }));
7676
},
7777
[dispatch, fieldName, nodeId]
7878
);
7979

80-
const handleClickRandomizeValue = useCallback(() => {
80+
const randomizeValue = useCallback(() => {
8181
const value = Math.round(randomInt(min, max) / step) * step;
8282
dispatch(fieldIntegerValueChanged({ nodeId, fieldName, value }));
8383
}, [dispatch, fieldName, nodeId, min, max, step]);
8484

8585
return {
8686
defaultValue: fieldTemplate.default,
87-
onValueChange,
87+
onChange,
8888
min,
8989
max,
9090
step,
9191
fineStep,
9292
constrainValue,
9393
showShuffle,
94-
handleClickRandomizeValue,
94+
randomizeValue,
9595
};
9696
};

invokeai/frontend/web/src/features/nodes/components/sidePanel/builder/NodeFieldElementFloatSettings.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ type Props = {
2020
};
2121

2222
export const NodeFieldElementFloatSettings = memo(({ id, settings, nodeId, fieldName, fieldTemplate }: Props) => {
23+
return (
24+
<>
25+
<SettingShuffle id={id} settings={settings} nodeId={nodeId} fieldName={fieldName} fieldTemplate={fieldTemplate} />
26+
<SettingComponent
27+
id={id}
28+
settings={settings}
29+
nodeId={nodeId}
30+
fieldName={fieldName}
31+
fieldTemplate={fieldTemplate}
32+
/>
33+
<SettingMin id={id} settings={settings} nodeId={nodeId} fieldName={fieldName} fieldTemplate={fieldTemplate} />
34+
<SettingMax id={id} settings={settings} nodeId={nodeId} fieldName={fieldName} fieldTemplate={fieldTemplate} />
35+
</>
36+
);
37+
});
38+
NodeFieldElementFloatSettings.displayName = 'NodeFieldElementFloatSettings';
39+
40+
const SettingShuffle = memo(({ id, settings }: Props) => {
2341
const { showShuffle } = settings;
2442

2543
const { t } = useTranslation();
@@ -34,24 +52,13 @@ export const NodeFieldElementFloatSettings = memo(({ id, settings, nodeId, field
3452
}, [dispatch, id, settings, showShuffle]);
3553

3654
return (
37-
<>
38-
<FormControl>
39-
<FormLabel flex={1}>{t('workflows.builder.showShuffle')}</FormLabel>
40-
<Switch size="sm" isChecked={showShuffle} onChange={toggleShowShuffle} />
41-
</FormControl>
42-
<SettingComponent
43-
id={id}
44-
settings={settings}
45-
nodeId={nodeId}
46-
fieldName={fieldName}
47-
fieldTemplate={fieldTemplate}
48-
/>
49-
<SettingMin id={id} settings={settings} nodeId={nodeId} fieldName={fieldName} fieldTemplate={fieldTemplate} />
50-
<SettingMax id={id} settings={settings} nodeId={nodeId} fieldName={fieldName} fieldTemplate={fieldTemplate} />
51-
</>
55+
<FormControl>
56+
<FormLabel flex={1}>{t('workflows.builder.showShuffle')}</FormLabel>
57+
<Switch size="sm" isChecked={showShuffle} onChange={toggleShowShuffle} />
58+
</FormControl>
5259
);
5360
});
54-
NodeFieldElementFloatSettings.displayName = 'NodeFieldElementFloatSettings';
61+
SettingShuffle.displayName = 'SettingShuffle';
5562

5663
const SettingComponent = memo(({ id, settings }: Props) => {
5764
const { t } = useTranslation();

invokeai/frontend/web/src/features/nodes/components/sidePanel/builder/NodeFieldElementIntegerSettings.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ type Props = {
2121
};
2222

2323
export const NodeFieldElementIntegerSettings = memo(({ id, settings, nodeId, fieldName, fieldTemplate }: Props) => {
24+
return (
25+
<>
26+
<SettingShuffle id={id} settings={settings} nodeId={nodeId} fieldName={fieldName} fieldTemplate={fieldTemplate} />
27+
<SettingComponent
28+
id={id}
29+
settings={settings}
30+
nodeId={nodeId}
31+
fieldName={fieldName}
32+
fieldTemplate={fieldTemplate}
33+
/>
34+
<SettingMin id={id} settings={settings} nodeId={nodeId} fieldName={fieldName} fieldTemplate={fieldTemplate} />
35+
<SettingMax id={id} settings={settings} nodeId={nodeId} fieldName={fieldName} fieldTemplate={fieldTemplate} />
36+
</>
37+
);
38+
});
39+
NodeFieldElementIntegerSettings.displayName = 'NodeFieldElementIntegerSettings';
40+
41+
const SettingShuffle = memo(({ id, settings }: Props) => {
2442
const { showShuffle } = settings;
2543

2644
const { t } = useTranslation();
@@ -35,24 +53,13 @@ export const NodeFieldElementIntegerSettings = memo(({ id, settings, nodeId, fie
3553
}, [dispatch, id, settings, showShuffle]);
3654

3755
return (
38-
<>
39-
<FormControl>
40-
<FormLabel flex={1}>{t('workflows.builder.showShuffle')}</FormLabel>
41-
<Switch size="sm" isChecked={showShuffle} onChange={toggleShowShuffle} />
42-
</FormControl>
43-
<SettingComponent
44-
id={id}
45-
settings={settings}
46-
nodeId={nodeId}
47-
fieldName={fieldName}
48-
fieldTemplate={fieldTemplate}
49-
/>
50-
<SettingMin id={id} settings={settings} nodeId={nodeId} fieldName={fieldName} fieldTemplate={fieldTemplate} />
51-
<SettingMax id={id} settings={settings} nodeId={nodeId} fieldName={fieldName} fieldTemplate={fieldTemplate} />
52-
</>
56+
<FormControl>
57+
<FormLabel flex={1}>{t('workflows.builder.showShuffle')}</FormLabel>
58+
<Switch size="sm" isChecked={showShuffle} onChange={toggleShowShuffle} />
59+
</FormControl>
5360
);
5461
});
55-
NodeFieldElementIntegerSettings.displayName = 'NodeFieldElementIntegerSettings';
62+
SettingShuffle.displayName = 'SettingShuffle';
5663

5764
const SettingComponent = memo(({ id, settings }: Props) => {
5865
const { t } = useTranslation();

0 commit comments

Comments
 (0)