mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): revert IAICustomSelect usage to IAISelect
There are some bugs with it that I cannot figure out related to `floating-ui` and `downshift`'s handling of refs. Will need to revisit this component in the future.
This commit is contained in:
parent
2e42a4bdd9
commit
a3fa38b353
@ -2,6 +2,7 @@ import { useAppDispatch } from 'app/store/storeHooks';
|
|||||||
import IAICustomSelect, {
|
import IAICustomSelect, {
|
||||||
IAICustomSelectOption,
|
IAICustomSelectOption,
|
||||||
} from 'common/components/IAICustomSelect';
|
} from 'common/components/IAICustomSelect';
|
||||||
|
import IAISelect from 'common/components/IAISelect';
|
||||||
import { useIsReadyToInvoke } from 'common/hooks/useIsReadyToInvoke';
|
import { useIsReadyToInvoke } from 'common/hooks/useIsReadyToInvoke';
|
||||||
import {
|
import {
|
||||||
CONTROLNET_MODELS,
|
CONTROLNET_MODELS,
|
||||||
@ -9,45 +10,71 @@ import {
|
|||||||
} from 'features/controlNet/store/constants';
|
} from 'features/controlNet/store/constants';
|
||||||
import { controlNetModelChanged } from 'features/controlNet/store/controlNetSlice';
|
import { controlNetModelChanged } from 'features/controlNet/store/controlNetSlice';
|
||||||
import { map } from 'lodash-es';
|
import { map } from 'lodash-es';
|
||||||
import { memo, useCallback } from 'react';
|
import { ChangeEvent, memo, useCallback } from 'react';
|
||||||
|
|
||||||
type ParamControlNetModelProps = {
|
type ParamControlNetModelProps = {
|
||||||
controlNetId: string;
|
controlNetId: string;
|
||||||
model: ControlNetModelName;
|
model: ControlNetModelName;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DATA: IAICustomSelectOption[] = map(CONTROLNET_MODELS, (m) => ({
|
const DATA = map(CONTROLNET_MODELS, (m) => ({
|
||||||
|
key: m.label,
|
||||||
value: m.type,
|
value: m.type,
|
||||||
label: m.label,
|
|
||||||
tooltip: m.type,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// const DATA: IAICustomSelectOption[] = map(CONTROLNET_MODELS, (m) => ({
|
||||||
|
// value: m.type,
|
||||||
|
// label: m.label,
|
||||||
|
// tooltip: m.type,
|
||||||
|
// }));
|
||||||
|
|
||||||
const ParamControlNetModel = (props: ParamControlNetModelProps) => {
|
const ParamControlNetModel = (props: ParamControlNetModelProps) => {
|
||||||
const { controlNetId, model } = props;
|
const { controlNetId, model } = props;
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const isReady = useIsReadyToInvoke();
|
const isReady = useIsReadyToInvoke();
|
||||||
|
|
||||||
const handleModelChanged = useCallback(
|
const handleModelChanged = useCallback(
|
||||||
(val: string | null | undefined) => {
|
(e: ChangeEvent<HTMLSelectElement>) => {
|
||||||
// TODO: do not cast
|
// TODO: do not cast
|
||||||
const model = val as ControlNetModelName;
|
const model = e.target.value 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 (
|
||||||
<IAICustomSelect
|
<IAISelect
|
||||||
tooltip={model}
|
tooltip={model}
|
||||||
tooltipProps={{ placement: 'top', hasArrow: true }}
|
tooltipProps={{ placement: 'top', hasArrow: true }}
|
||||||
data={DATA}
|
validValues={DATA}
|
||||||
value={model}
|
value={model}
|
||||||
onChange={handleModelChanged}
|
onChange={handleModelChanged}
|
||||||
isDisabled={!isReady}
|
isDisabled={!isReady}
|
||||||
ellipsisPosition="start"
|
// ellipsisPosition="start"
|
||||||
withCheckIcon
|
// withCheckIcon
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
// return (
|
||||||
|
// <IAICustomSelect
|
||||||
|
// tooltip={model}
|
||||||
|
// tooltipProps={{ placement: 'top', hasArrow: true }}
|
||||||
|
// data={DATA}
|
||||||
|
// value={model}
|
||||||
|
// onChange={handleModelChanged}
|
||||||
|
// isDisabled={!isReady}
|
||||||
|
// ellipsisPosition="start"
|
||||||
|
// withCheckIcon
|
||||||
|
// />
|
||||||
|
// );
|
||||||
};
|
};
|
||||||
|
|
||||||
export default memo(ParamControlNetModel);
|
export default memo(ParamControlNetModel);
|
||||||
|
@ -1,39 +1,47 @@
|
|||||||
import IAICustomSelect, {
|
import IAICustomSelect, {
|
||||||
IAICustomSelectOption,
|
IAICustomSelectOption,
|
||||||
} from 'common/components/IAICustomSelect';
|
} from 'common/components/IAICustomSelect';
|
||||||
import { memo, useCallback } from 'react';
|
import { ChangeEvent, memo, useCallback } from 'react';
|
||||||
import {
|
import {
|
||||||
ControlNetProcessorNode,
|
ControlNetProcessorNode,
|
||||||
ControlNetProcessorType,
|
ControlNetProcessorType,
|
||||||
} from '../../store/types';
|
} from '../../store/types';
|
||||||
import { controlNetProcessorTypeChanged } from '../../store/controlNetSlice';
|
import { controlNetProcessorTypeChanged } from '../../store/controlNetSlice';
|
||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch } from 'app/store/storeHooks';
|
||||||
import { CONTROLNET_PROCESSORS } from '../../store/constants';
|
import { CONTROLNET_PROCESSORS } from '../../store/constants';
|
||||||
import { map } from 'lodash-es';
|
import { map } from 'lodash-es';
|
||||||
import { isProcessingSelector } from 'features/system/store/systemSelectors';
|
|
||||||
import { useIsReadyToInvoke } from 'common/hooks/useIsReadyToInvoke';
|
import { useIsReadyToInvoke } from 'common/hooks/useIsReadyToInvoke';
|
||||||
|
import IAISelect from 'common/components/IAISelect';
|
||||||
|
|
||||||
type ParamControlNetProcessorSelectProps = {
|
type ParamControlNetProcessorSelectProps = {
|
||||||
controlNetId: string;
|
controlNetId: string;
|
||||||
processorNode: ControlNetProcessorNode;
|
processorNode: ControlNetProcessorNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
const CONTROLNET_PROCESSOR_TYPES: IAICustomSelectOption[] = map(
|
const CONTROLNET_PROCESSOR_TYPES = map(CONTROLNET_PROCESSORS, (p) => ({
|
||||||
CONTROLNET_PROCESSORS,
|
value: p.type,
|
||||||
(p) => ({
|
key: p.label,
|
||||||
value: p.type,
|
})).sort((a, b) =>
|
||||||
label: p.label,
|
|
||||||
tooltip: p.description,
|
|
||||||
})
|
|
||||||
).sort((a, b) =>
|
|
||||||
// sort 'none' to the top
|
// sort 'none' to the top
|
||||||
a.value === 'none'
|
a.value === 'none' ? -1 : b.value === 'none' ? 1 : a.key.localeCompare(b.key)
|
||||||
? -1
|
|
||||||
: b.value === 'none'
|
|
||||||
? 1
|
|
||||||
: a.label.localeCompare(b.label)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// const CONTROLNET_PROCESSOR_TYPES: IAICustomSelectOption[] = map(
|
||||||
|
// CONTROLNET_PROCESSORS,
|
||||||
|
// (p) => ({
|
||||||
|
// value: p.type,
|
||||||
|
// label: p.label,
|
||||||
|
// tooltip: p.description,
|
||||||
|
// })
|
||||||
|
// ).sort((a, b) =>
|
||||||
|
// // sort 'none' to the top
|
||||||
|
// a.value === 'none'
|
||||||
|
// ? -1
|
||||||
|
// : b.value === 'none'
|
||||||
|
// ? 1
|
||||||
|
// : a.label.localeCompare(b.label)
|
||||||
|
// );
|
||||||
|
|
||||||
const ParamControlNetProcessorSelect = (
|
const ParamControlNetProcessorSelect = (
|
||||||
props: ParamControlNetProcessorSelectProps
|
props: ParamControlNetProcessorSelectProps
|
||||||
) => {
|
) => {
|
||||||
@ -42,26 +50,46 @@ const ParamControlNetProcessorSelect = (
|
|||||||
const isReady = useIsReadyToInvoke();
|
const isReady = useIsReadyToInvoke();
|
||||||
|
|
||||||
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 | undefined) => {
|
||||||
|
// dispatch(
|
||||||
|
// controlNetProcessorTypeChanged({
|
||||||
|
// controlNetId,
|
||||||
|
// processorType: v as ControlNetProcessorType,
|
||||||
|
// })
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// [controlNetId, dispatch]
|
||||||
|
// );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IAICustomSelect
|
<IAISelect
|
||||||
label="Processor"
|
label="Processor"
|
||||||
value={processorNode.type ?? 'canny_image_processor'}
|
value={processorNode.type ?? 'canny_image_processor'}
|
||||||
data={CONTROLNET_PROCESSOR_TYPES}
|
validValues={CONTROLNET_PROCESSOR_TYPES}
|
||||||
onChange={handleProcessorTypeChanged}
|
onChange={handleProcessorTypeChanged}
|
||||||
withCheckIcon
|
|
||||||
isDisabled={!isReady}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
// return (
|
||||||
|
// <IAICustomSelect
|
||||||
|
// label="Processor"
|
||||||
|
// value={processorNode.type ?? 'canny_image_processor'}
|
||||||
|
// data={CONTROLNET_PROCESSOR_TYPES}
|
||||||
|
// onChange={handleProcessorTypeChanged}
|
||||||
|
// withCheckIcon
|
||||||
|
// isDisabled={!isReady}
|
||||||
|
// />
|
||||||
|
// );
|
||||||
};
|
};
|
||||||
|
|
||||||
export default memo(ParamControlNetProcessorSelect);
|
export default memo(ParamControlNetProcessorSelect);
|
||||||
|
@ -3,10 +3,11 @@ import { Scheduler } from 'app/constants';
|
|||||||
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 IAICustomSelect from 'common/components/IAICustomSelect';
|
import IAICustomSelect from 'common/components/IAICustomSelect';
|
||||||
|
import IAISelect from 'common/components/IAISelect';
|
||||||
import { generationSelector } from 'features/parameters/store/generationSelectors';
|
import { generationSelector } from 'features/parameters/store/generationSelectors';
|
||||||
import { setScheduler } from 'features/parameters/store/generationSlice';
|
import { setScheduler } from 'features/parameters/store/generationSlice';
|
||||||
import { uiSelector } from 'features/ui/store/uiSelectors';
|
import { uiSelector } from 'features/ui/store/uiSelectors';
|
||||||
import { memo, useCallback } from 'react';
|
import { ChangeEvent, memo, useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
const selector = createSelector(
|
const selector = createSelector(
|
||||||
@ -35,24 +36,39 @@ const ParamScheduler = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const handleChange = useCallback(
|
const handleChange = useCallback(
|
||||||
(v: string | null | undefined) => {
|
(e: ChangeEvent<HTMLSelectElement>) => {
|
||||||
if (!v) {
|
dispatch(setScheduler(e.target.value as Scheduler));
|
||||||
return;
|
|
||||||
}
|
|
||||||
dispatch(setScheduler(v as Scheduler));
|
|
||||||
},
|
},
|
||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
|
// const handleChange = useCallback(
|
||||||
|
// (v: string | null | undefined) => {
|
||||||
|
// if (!v) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// dispatch(setScheduler(v as Scheduler));
|
||||||
|
// },
|
||||||
|
// [dispatch]
|
||||||
|
// );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IAICustomSelect
|
<IAISelect
|
||||||
label={t('parameters.scheduler')}
|
label={t('parameters.scheduler')}
|
||||||
value={scheduler}
|
value={scheduler}
|
||||||
data={allSchedulers}
|
validValues={allSchedulers}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
withCheckIcon
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <IAICustomSelect
|
||||||
|
// label={t('parameters.scheduler')}
|
||||||
|
// value={scheduler}
|
||||||
|
// data={allSchedulers}
|
||||||
|
// onChange={handleChange}
|
||||||
|
// withCheckIcon
|
||||||
|
// />
|
||||||
|
// );
|
||||||
};
|
};
|
||||||
|
|
||||||
export default memo(ParamScheduler);
|
export default memo(ParamScheduler);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { memo, useCallback } from 'react';
|
import { ChangeEvent, memo, useCallback } from 'react';
|
||||||
import { isEqual } from 'lodash-es';
|
import { isEqual } from 'lodash-es';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
@ -11,6 +11,7 @@ import { generationSelector } from 'features/parameters/store/generationSelector
|
|||||||
import IAICustomSelect, {
|
import IAICustomSelect, {
|
||||||
IAICustomSelectOption,
|
IAICustomSelectOption,
|
||||||
} from 'common/components/IAICustomSelect';
|
} from 'common/components/IAICustomSelect';
|
||||||
|
import IAISelect from 'common/components/IAISelect';
|
||||||
|
|
||||||
const selector = createSelector(
|
const selector = createSelector(
|
||||||
[(state: RootState) => state, generationSelector],
|
[(state: RootState) => state, generationSelector],
|
||||||
@ -18,12 +19,18 @@ const selector = createSelector(
|
|||||||
const selectedModel = selectModelsById(state, generation.model);
|
const selectedModel = selectModelsById(state, generation.model);
|
||||||
|
|
||||||
const modelData = selectModelsAll(state)
|
const modelData = selectModelsAll(state)
|
||||||
.map<IAICustomSelectOption>((m) => ({
|
.map((m) => ({
|
||||||
value: m.name,
|
value: m.name,
|
||||||
label: m.name,
|
key: m.name,
|
||||||
tooltip: m.description,
|
|
||||||
}))
|
}))
|
||||||
.sort((a, b) => a.label.localeCompare(b.label));
|
.sort((a, b) => a.key.localeCompare(b.key));
|
||||||
|
// const modelData = selectModelsAll(state)
|
||||||
|
// .map<IAICustomSelectOption>((m) => ({
|
||||||
|
// value: m.name,
|
||||||
|
// label: m.name,
|
||||||
|
// tooltip: m.description,
|
||||||
|
// }))
|
||||||
|
// .sort((a, b) => a.label.localeCompare(b.label));
|
||||||
return {
|
return {
|
||||||
selectedModel,
|
selectedModel,
|
||||||
modelData,
|
modelData,
|
||||||
@ -41,26 +48,43 @@ const ModelSelect = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { selectedModel, modelData } = useAppSelector(selector);
|
const { selectedModel, modelData } = useAppSelector(selector);
|
||||||
const handleChangeModel = useCallback(
|
const handleChangeModel = useCallback(
|
||||||
(v: string | null | undefined) => {
|
(e: ChangeEvent<HTMLSelectElement>) => {
|
||||||
if (!v) {
|
dispatch(modelSelected(e.target.value));
|
||||||
return;
|
|
||||||
}
|
|
||||||
dispatch(modelSelected(v));
|
|
||||||
},
|
},
|
||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
|
// const handleChangeModel = useCallback(
|
||||||
|
// (v: string | null | undefined) => {
|
||||||
|
// if (!v) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// dispatch(modelSelected(v));
|
||||||
|
// },
|
||||||
|
// [dispatch]
|
||||||
|
// );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IAICustomSelect
|
<IAISelect
|
||||||
label={t('modelManager.model')}
|
label={t('modelManager.model')}
|
||||||
tooltip={selectedModel?.description}
|
tooltip={selectedModel?.description}
|
||||||
data={modelData}
|
validValues={modelData}
|
||||||
value={selectedModel?.name ?? ''}
|
value={selectedModel?.name ?? ''}
|
||||||
onChange={handleChangeModel}
|
onChange={handleChangeModel}
|
||||||
withCheckIcon={true}
|
|
||||||
tooltipProps={{ placement: 'top', hasArrow: true }}
|
tooltipProps={{ placement: 'top', hasArrow: true }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <IAICustomSelect
|
||||||
|
// label={t('modelManager.model')}
|
||||||
|
// tooltip={selectedModel?.description}
|
||||||
|
// data={modelData}
|
||||||
|
// value={selectedModel?.name ?? ''}
|
||||||
|
// onChange={handleChangeModel}
|
||||||
|
// withCheckIcon={true}
|
||||||
|
// tooltipProps={{ placement: 'top', hasArrow: true }}
|
||||||
|
// />
|
||||||
|
// );
|
||||||
};
|
};
|
||||||
|
|
||||||
export default memo(ModelSelect);
|
export default memo(ModelSelect);
|
||||||
|
Loading…
Reference in New Issue
Block a user