feat: Port IAISelect's to IAIMantineSelect's

Ported everything except Model Manager selects and the Canvas Layer Select (this needs tooltip support)
This commit is contained in:
blessedcoolant 2023-06-13 00:11:30 +12:00 committed by psychedelicious
parent 14cdc800c3
commit 9a77bd9140
10 changed files with 75 additions and 96 deletions

View File

@ -22,9 +22,9 @@ export const SCHEDULERS = [
export type Scheduler = (typeof SCHEDULERS)[number]; export type Scheduler = (typeof SCHEDULERS)[number];
// Valid upscaling levels // Valid upscaling levels
export const UPSCALING_LEVELS: Array<{ key: string; value: number }> = [ export const UPSCALING_LEVELS: Array<{ label: string; value: string }> = [
{ key: '2x', value: 2 }, { label: '2x', value: '2' },
{ key: '4x', value: 4 }, { label: '4x', value: '4' },
]; ];
export const NUMPY_RAND_MIN = 0; export const NUMPY_RAND_MIN = 0;

View File

@ -9,7 +9,6 @@ const IAIMantineSelect = (props: IAISelectProps) => {
<Select <Select
searchable={searchable} searchable={searchable}
styles={() => ({ styles={() => ({
root: {},
label: { label: {
color: 'var(--invokeai-colors-base-300)', color: 'var(--invokeai-colors-base-300)',
fontWeight: 'normal', fontWeight: 'normal',

View File

@ -13,9 +13,9 @@ export const LAYER_NAMES = ['base', 'mask'] as const;
export type CanvasLayer = (typeof LAYER_NAMES)[number]; export type CanvasLayer = (typeof LAYER_NAMES)[number];
export const BOUNDING_BOX_SCALES_DICT = [ export const BOUNDING_BOX_SCALES_DICT = [
{ key: 'Auto', value: 'auto' }, { label: 'Auto', value: 'auto' },
{ key: 'Manual', value: 'manual' }, { label: 'Manual', value: 'manual' },
{ key: 'None', value: 'none' }, { label: 'None', value: 'none' },
]; ];
export const BOUNDING_BOX_SCALES = ['none', 'auto', 'manual'] as const; export const BOUNDING_BOX_SCALES = ['none', 'auto', 'manual'] as const;

View File

@ -5,6 +5,7 @@ import IAICustomSelect, {
} from 'common/components/IAICustomSelect'; } from 'common/components/IAICustomSelect';
import IAISelect from 'common/components/IAISelect'; import IAISelect from 'common/components/IAISelect';
import { useIsReadyToInvoke } from 'common/hooks/useIsReadyToInvoke'; import { useIsReadyToInvoke } from 'common/hooks/useIsReadyToInvoke';
import IAIMantineSelect from 'common/components/IAIMantineSelect';
import { import {
CONTROLNET_MODELS, CONTROLNET_MODELS,
ControlNetModelName, ControlNetModelName,
@ -26,11 +27,11 @@ const selector = createSelector(configSelector, (config) => {
})).filter((d) => !config.sd.disabledControlNetModels.includes(d.value)); })).filter((d) => !config.sd.disabledControlNetModels.includes(d.value));
}); });
// const DATA: IAICustomSelectOption[] = map(CONTROLNET_MODELS, (m) => ({ const DATA = map(CONTROLNET_MODELS, (m) => ({
// value: m.type, value: m.type,
// label: m.label, label: m.label,
// tooltip: m.type, tooltip: m.type,
// })); }));
const ParamControlNetModel = (props: ParamControlNetModelProps) => { const ParamControlNetModel = (props: ParamControlNetModelProps) => {
const { controlNetId, model } = props; const { controlNetId, model } = props;
@ -39,33 +40,20 @@ const ParamControlNetModel = (props: ParamControlNetModelProps) => {
const isReady = useIsReadyToInvoke(); const isReady = useIsReadyToInvoke();
const handleModelChanged = useCallback( const handleModelChanged = useCallback(
(e: ChangeEvent<HTMLSelectElement>) => { (val: string | null) => {
// TODO: do not cast // TODO: do not cast
const model = e.target.value as ControlNetModelName; const model = val as ControlNetModelName;
dispatch(controlNetModelChanged({ controlNetId, model })); dispatch(controlNetModelChanged({ controlNetId, model }));
}, },
[controlNetId, dispatch] [controlNetId, dispatch]
); );
// const handleModelChanged = useCallback(
// (val: string | null | undefined) => {
// // TODO: do not cast
// const model = val as ControlNetModelName;
// dispatch(controlNetModelChanged({ controlNetId, model }));
// },
// [controlNetId, dispatch]
// );
return ( return (
<IAISelect <IAIMantineSelect
tooltip={model} data={DATA}
tooltipProps={{ placement: 'top', hasArrow: true }}
validValues={controlNetModels}
value={model} value={model}
onChange={handleModelChanged} onChange={handleModelChanged}
isDisabled={!isReady} disabled={!isReady}
// ellipsisPosition="start"
// withCheckIcon
/> />
); );
// return ( // return (

View File

@ -1,17 +1,15 @@
import IAICustomSelect, { import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
IAICustomSelectOption, import { IAICustomSelectOption } from 'common/components/IAICustomSelect';
} from 'common/components/IAICustomSelect'; import IAIMantineSelect from 'common/components/IAIMantineSelect';
import { map } from 'lodash-es';
import { ChangeEvent, memo, useCallback } from 'react'; import { ChangeEvent, memo, useCallback } from 'react';
import { CONTROLNET_PROCESSORS } from '../../store/constants';
import { controlNetProcessorTypeChanged } from '../../store/controlNetSlice';
import { import {
ControlNetProcessorNode, ControlNetProcessorNode,
ControlNetProcessorType, ControlNetProcessorType,
} from '../../store/types'; } from '../../store/types';
import { controlNetProcessorTypeChanged } from '../../store/controlNetSlice';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { CONTROLNET_PROCESSORS } from '../../store/constants';
import { map } from 'lodash-es';
import { useIsReadyToInvoke } from 'common/hooks/useIsReadyToInvoke'; import { useIsReadyToInvoke } from 'common/hooks/useIsReadyToInvoke';
import IAISelect from 'common/components/IAISelect';
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { configSelector } from 'features/system/store/configSelectors'; import { configSelector } from 'features/system/store/configSelectors';
@ -68,36 +66,36 @@ const ParamControlNetProcessorSelect = (
const isReady = useIsReadyToInvoke(); const isReady = useIsReadyToInvoke();
const controlNetProcessors = useAppSelector(selector); const controlNetProcessors = useAppSelector(selector);
const handleProcessorTypeChanged = useCallback(
(e: ChangeEvent<HTMLSelectElement>) => {
dispatch(
controlNetProcessorTypeChanged({
controlNetId,
processorType: e.target.value as ControlNetProcessorType,
})
);
},
[controlNetId, dispatch]
);
// const handleProcessorTypeChanged = useCallback( // const handleProcessorTypeChanged = useCallback(
// (v: string | null | undefined) => { // (e: ChangeEvent<HTMLSelectElement>) => {
// dispatch( // dispatch(
// controlNetProcessorTypeChanged({ // controlNetProcessorTypeChanged({
// controlNetId, // controlNetId,
// processorType: v as ControlNetProcessorType, // processorType: e.target.value as ControlNetProcessorType,
// }) // })
// ); // );
// }, // },
// [controlNetId, dispatch] // [controlNetId, dispatch]
// ); // );
const handleProcessorTypeChanged = useCallback(
(v: string | null) => {
dispatch(
controlNetProcessorTypeChanged({
controlNetId,
processorType: v as ControlNetProcessorType,
})
);
},
[controlNetId, dispatch]
);
return ( return (
<IAISelect <IAIMantineSelect
label="Processor" label="Processor"
value={processorNode.type ?? 'canny_image_processor'} value={processorNode.type ?? 'canny_image_processor'}
validValues={controlNetProcessors} data={controlNetProcessors}
onChange={handleProcessorTypeChanged} onChange={handleProcessorTypeChanged}
isDisabled={!isReady} disabled={!isReady}
/> />
); );
// return ( // return (

View File

@ -1,12 +1,12 @@
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions'; import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import IAISelect from 'common/components/IAISelect'; import IAIMantineSelect from 'common/components/IAIMantineSelect';
import { generationSelector } from 'features/parameters/store/generationSelectors'; import { generationSelector } from 'features/parameters/store/generationSelectors';
import { setInfillMethod } from 'features/parameters/store/generationSlice'; import { setInfillMethod } from 'features/parameters/store/generationSlice';
import { systemSelector } from 'features/system/store/systemSelectors'; import { systemSelector } from 'features/system/store/systemSelectors';
import { ChangeEvent, memo, useCallback } from 'react'; import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
const selector = createSelector( const selector = createSelector(
@ -30,17 +30,17 @@ const ParamInfillMethod = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const handleChange = useCallback( const handleChange = useCallback(
(e: ChangeEvent<HTMLSelectElement>) => { (v: string) => {
dispatch(setInfillMethod(e.target.value)); dispatch(setInfillMethod(v));
}, },
[dispatch] [dispatch]
); );
return ( return (
<IAISelect <IAIMantineSelect
label={t('parameters.infillMethod')} label={t('parameters.infillMethod')}
value={infillMethod} value={infillMethod}
validValues={infillMethods} data={infillMethods}
onChange={handleChange} onChange={handleChange}
/> />
); );

View File

@ -1,15 +1,15 @@
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions'; import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import IAISelect from 'common/components/IAISelect'; import IAIMantineSelect from 'common/components/IAIMantineSelect';
import { canvasSelector } from 'features/canvas/store/canvasSelectors'; import { canvasSelector } from 'features/canvas/store/canvasSelectors';
import { setBoundingBoxScaleMethod } from 'features/canvas/store/canvasSlice'; import { setBoundingBoxScaleMethod } from 'features/canvas/store/canvasSlice';
import { import {
BoundingBoxScale,
BOUNDING_BOX_SCALES_DICT, BOUNDING_BOX_SCALES_DICT,
BoundingBoxScale,
} from 'features/canvas/store/canvasTypes'; } from 'features/canvas/store/canvasTypes';
import { ChangeEvent, memo } from 'react'; import { memo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
const selector = createSelector( const selector = createSelector(
@ -30,16 +30,14 @@ const ParamScaleBeforeProcessing = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const handleChangeBoundingBoxScaleMethod = ( const handleChangeBoundingBoxScaleMethod = (v: string) => {
e: ChangeEvent<HTMLSelectElement> dispatch(setBoundingBoxScaleMethod(v as BoundingBoxScale));
) => {
dispatch(setBoundingBoxScaleMethod(e.target.value as BoundingBoxScale));
}; };
return ( return (
<IAISelect <IAIMantineSelect
label={t('parameters.scaleBeforeProcessing')} label={t('parameters.scaleBeforeProcessing')}
validValues={BOUNDING_BOX_SCALES_DICT} data={BOUNDING_BOX_SCALES_DICT}
value={boundingBoxScale} value={boundingBoxScale}
onChange={handleChangeBoundingBoxScaleMethod} onChange={handleChangeBoundingBoxScaleMethod}
/> />

View File

@ -1,12 +1,11 @@
import { FACETOOL_TYPES } from 'app/constants'; import { FACETOOL_TYPES } from 'app/constants';
import { RootState } from 'app/store/store'; import { RootState } from 'app/store/store';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import IAISelect from 'common/components/IAISelect'; import IAIMantineSelect from 'common/components/IAIMantineSelect';
import { import {
FacetoolType, FacetoolType,
setFacetoolType, setFacetoolType,
} from 'features/parameters/store/postprocessingSlice'; } from 'features/parameters/store/postprocessingSlice';
import { ChangeEvent } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
export default function FaceRestoreType() { export default function FaceRestoreType() {
@ -17,13 +16,13 @@ export default function FaceRestoreType() {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { t } = useTranslation(); const { t } = useTranslation();
const handleChangeFacetoolType = (e: ChangeEvent<HTMLSelectElement>) => const handleChangeFacetoolType = (v: string) =>
dispatch(setFacetoolType(e.target.value as FacetoolType)); dispatch(setFacetoolType(v as FacetoolType));
return ( return (
<IAISelect <IAIMantineSelect
label={t('parameters.type')} label={t('parameters.type')}
validValues={FACETOOL_TYPES.concat()} data={FACETOOL_TYPES.concat()}
value={facetoolType} value={facetoolType}
onChange={handleChangeFacetoolType} onChange={handleChangeFacetoolType}
/> />

View File

@ -1,12 +1,11 @@
import { UPSCALING_LEVELS } from 'app/constants'; import { UPSCALING_LEVELS } from 'app/constants';
import type { RootState } from 'app/store/store'; import type { RootState } from 'app/store/store';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import IAISelect from 'common/components/IAISelect'; import IAIMantineSelect from 'common/components/IAIMantineSelect';
import { import {
setUpscalingLevel,
UpscalingLevel, UpscalingLevel,
setUpscalingLevel,
} from 'features/parameters/store/postprocessingSlice'; } from 'features/parameters/store/postprocessingSlice';
import type { ChangeEvent } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
export default function UpscaleScale() { export default function UpscaleScale() {
@ -21,16 +20,16 @@ export default function UpscaleScale() {
const { t } = useTranslation(); const { t } = useTranslation();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const handleChangeLevel = (e: ChangeEvent<HTMLSelectElement>) => const handleChangeLevel = (v: string) =>
dispatch(setUpscalingLevel(Number(e.target.value) as UpscalingLevel)); dispatch(setUpscalingLevel(Number(v) as UpscalingLevel));
return ( return (
<IAISelect <IAIMantineSelect
isDisabled={!isESRGANAvailable} disabled={!isESRGANAvailable}
label={t('parameters.scale')} label={t('parameters.scale')}
value={upscalingLevel} value={String(upscalingLevel)}
onChange={handleChangeLevel} onChange={handleChangeLevel}
validValues={UPSCALING_LEVELS} data={UPSCALING_LEVELS}
/> />
); );
} }

View File

@ -13,19 +13,21 @@ import {
useDisclosure, useDisclosure,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { VALID_LOG_LEVELS } from 'app/logging/useLogger';
import { LOCALSTORAGE_KEYS, LOCALSTORAGE_PREFIX } from 'app/store/constants';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import IAIButton from 'common/components/IAIButton'; import IAIButton from 'common/components/IAIButton';
import IAISelect from 'common/components/IAISelect'; import IAIMantineSelect from 'common/components/IAIMantineSelect';
import IAISwitch from 'common/components/IAISwitch'; import IAISwitch from 'common/components/IAISwitch';
import { systemSelector } from 'features/system/store/systemSelectors'; import { systemSelector } from 'features/system/store/systemSelectors';
import { import {
SystemState,
consoleLogLevelChanged, consoleLogLevelChanged,
setEnableImageDebugging, setEnableImageDebugging,
setShouldConfirmOnDelete, setShouldConfirmOnDelete,
setShouldDisplayGuides, setShouldDisplayGuides,
shouldAntialiasProgressImageChanged, shouldAntialiasProgressImageChanged,
shouldLogToConsoleChanged, shouldLogToConsoleChanged,
SystemState,
} from 'features/system/store/systemSlice'; } from 'features/system/store/systemSlice';
import { uiSelector } from 'features/ui/store/uiSelectors'; import { uiSelector } from 'features/ui/store/uiSelectors';
import { import {
@ -37,15 +39,13 @@ import { UIState } from 'features/ui/store/uiTypes';
import { isEqual } from 'lodash-es'; import { isEqual } from 'lodash-es';
import { import {
ChangeEvent, ChangeEvent,
cloneElement,
ReactElement, ReactElement,
cloneElement,
useCallback, useCallback,
useEffect, useEffect,
} from 'react'; } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { VALID_LOG_LEVELS } from 'app/logging/useLogger';
import { LogLevelName } from 'roarr'; import { LogLevelName } from 'roarr';
import { LOCALSTORAGE_KEYS, LOCALSTORAGE_PREFIX } from 'app/store/constants';
import SettingsSchedulers from './SettingsSchedulers'; import SettingsSchedulers from './SettingsSchedulers';
const selector = createSelector( const selector = createSelector(
@ -157,8 +157,8 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => {
}, [onSettingsModalClose, onRefreshModalOpen]); }, [onSettingsModalClose, onRefreshModalOpen]);
const handleLogLevelChanged = useCallback( const handleLogLevelChanged = useCallback(
(e: ChangeEvent<HTMLSelectElement>) => { (v: string) => {
dispatch(consoleLogLevelChanged(e.target.value as LogLevelName)); dispatch(consoleLogLevelChanged(v as LogLevelName));
}, },
[dispatch] [dispatch]
); );
@ -255,14 +255,12 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => {
isChecked={shouldLogToConsole} isChecked={shouldLogToConsole}
onChange={handleLogToConsoleChanged} onChange={handleLogToConsoleChanged}
/> />
<IAISelect <IAIMantineSelect
horizontal disabled={!shouldLogToConsole}
spaceEvenly
isDisabled={!shouldLogToConsole}
label={t('settings.consoleLogLevel')} label={t('settings.consoleLogLevel')}
onChange={handleLogLevelChanged} onChange={handleLogLevelChanged}
value={consoleLogLevel} value={consoleLogLevel}
validValues={VALID_LOG_LEVELS.concat()} data={VALID_LOG_LEVELS.concat()}
/> />
<IAISwitch <IAISwitch
label={t('settings.enableImageDebugging')} label={t('settings.enableImageDebugging')}