fix(ui): Clean up manual add forms

This commit is contained in:
blessedcoolant 2023-03-19 19:09:22 +13:00 committed by psychedelicious
parent 5906888477
commit 2aefa06ef1
4 changed files with 250 additions and 221 deletions

View File

@ -333,6 +333,7 @@
"addNewModel": "Add New Model", "addNewModel": "Add New Model",
"addCheckpointModel": "Add Checkpoint / Safetensor Model", "addCheckpointModel": "Add Checkpoint / Safetensor Model",
"addDiffuserModel": "Add Diffusers", "addDiffuserModel": "Add Diffusers",
"scanForModels": "Scan For Models",
"addManually": "Add Manually", "addManually": "Add Manually",
"manual": "Manual", "manual": "Manual",
"name": "Name", "name": "Name",

View File

@ -0,0 +1,23 @@
import { Flex } from '@chakra-ui/react';
import { ReactElement } from 'react';
export function IAIFormItemWrapper({
children,
}: {
children: ReactElement | ReactElement[];
}) {
return (
<Flex
sx={{
flexDirection: 'column',
padding: 4,
rowGap: 4,
borderRadius: 'base',
width: 'full',
bg: 'base.900',
}}
>
{children}
</Flex>
);
}

View File

@ -1,4 +1,5 @@
import { import {
Flex,
FormControl, FormControl,
FormErrorMessage, FormErrorMessage,
FormHelperText, FormHelperText,
@ -28,6 +29,7 @@ import type { RootState } from 'app/store';
import { setAddNewModelUIOption } from 'features/ui/store/uiSlice'; import { setAddNewModelUIOption } from 'features/ui/store/uiSlice';
import type { FieldInputProps, FormikProps } from 'formik'; import type { FieldInputProps, FormikProps } from 'formik';
import IAIForm from 'common/components/IAIForm'; import IAIForm from 'common/components/IAIForm';
import { IAIFormItemWrapper } from 'common/components/IAIForms/IAIFormItemWrapper';
const MIN_MODEL_SIZE = 64; const MIN_MODEL_SIZE = 64;
const MAX_MODEL_SIZE = 2048; const MAX_MODEL_SIZE = 2048;
@ -71,14 +73,20 @@ export default function AddCheckpointModel() {
return ( return (
<VStack gap={2} alignItems="flex-start"> <VStack gap={2} alignItems="flex-start">
<SearchModels /> <Flex columnGap={4}>
<IAICheckbox
isChecked={!addManually}
label={t('modelManager.scanForModels')}
onChange={() => setAddmanually(!addManually)}
/>
<IAICheckbox <IAICheckbox
label={t('modelManager.addManually')} label={t('modelManager.addManually')}
isChecked={addManually} isChecked={addManually}
onChange={() => setAddmanually(!addManually)} onChange={() => setAddmanually(!addManually)}
/> />
</Flex>
{addManually && ( {addManually ? (
<Formik <Formik
initialValues={addModelFormValues} initialValues={addModelFormValues}
onSubmit={addModelFormSubmitHandler} onSubmit={addModelFormSubmitHandler}
@ -90,6 +98,7 @@ export default function AddCheckpointModel() {
{t('modelManager.manual')} {t('modelManager.manual')}
</Text> </Text>
{/* Name */} {/* Name */}
<IAIFormItemWrapper>
<FormControl <FormControl
isInvalid={!!errors.name && touched.name} isInvalid={!!errors.name && touched.name}
isRequired isRequired
@ -115,8 +124,10 @@ export default function AddCheckpointModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</IAIFormItemWrapper>
{/* Description */} {/* Description */}
<IAIFormItemWrapper>
<FormControl <FormControl
isInvalid={!!errors.description && touched.description} isInvalid={!!errors.description && touched.description}
isRequired isRequired
@ -133,7 +144,9 @@ export default function AddCheckpointModel() {
width="full" width="full"
/> />
{!!errors.description && touched.description ? ( {!!errors.description && touched.description ? (
<FormErrorMessage>{errors.description}</FormErrorMessage> <FormErrorMessage>
{errors.description}
</FormErrorMessage>
) : ( ) : (
<FormHelperText margin={0}> <FormHelperText margin={0}>
{t('modelManager.descriptionValidationMsg')} {t('modelManager.descriptionValidationMsg')}
@ -141,8 +154,10 @@ export default function AddCheckpointModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</IAIFormItemWrapper>
{/* Config */} {/* Config */}
<IAIFormItemWrapper>
<FormControl <FormControl
isInvalid={!!errors.config && touched.config} isInvalid={!!errors.config && touched.config}
isRequired isRequired
@ -167,8 +182,10 @@ export default function AddCheckpointModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</IAIFormItemWrapper>
{/* Weights */} {/* Weights */}
<IAIFormItemWrapper>
<FormControl <FormControl
isInvalid={!!errors.weights && touched.weights} isInvalid={!!errors.weights && touched.weights}
isRequired isRequired
@ -193,8 +210,10 @@ export default function AddCheckpointModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</IAIFormItemWrapper>
{/* VAE */} {/* VAE */}
<IAIFormItemWrapper>
<FormControl isInvalid={!!errors.vae && touched.vae}> <FormControl isInvalid={!!errors.vae && touched.vae}>
<FormLabel htmlFor="vae" fontSize="sm"> <FormLabel htmlFor="vae" fontSize="sm">
{t('modelManager.vaeLocation')} {t('modelManager.vaeLocation')}
@ -216,9 +235,11 @@ export default function AddCheckpointModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</IAIFormItemWrapper>
<HStack width="100%" gap={8}> <HStack width="100%">
{/* Width */} {/* Width */}
<IAIFormItemWrapper>
<FormControl isInvalid={!!errors.width && touched.width}> <FormControl isInvalid={!!errors.width && touched.width}>
<FormLabel htmlFor="width" fontSize="sm"> <FormLabel htmlFor="width" fontSize="sm">
{t('modelManager.width')} {t('modelManager.width')}
@ -255,8 +276,10 @@ export default function AddCheckpointModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</IAIFormItemWrapper>
{/* Height */} {/* Height */}
<IAIFormItemWrapper>
<FormControl isInvalid={!!errors.height && touched.height}> <FormControl isInvalid={!!errors.height && touched.height}>
<FormLabel htmlFor="height" fontSize="sm"> <FormLabel htmlFor="height" fontSize="sm">
{t('modelManager.height')} {t('modelManager.height')}
@ -293,6 +316,7 @@ export default function AddCheckpointModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</IAIFormItemWrapper>
</HStack> </HStack>
<IAIButton <IAIButton
@ -306,6 +330,8 @@ export default function AddCheckpointModel() {
</IAIForm> </IAIForm>
)} )}
</Formik> </Formik>
) : (
<SearchModels />
)} )}
</VStack> </VStack>
); );

View File

@ -17,29 +17,8 @@ import { Field, Formik } from 'formik';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import type { RootState } from 'app/store'; import type { RootState } from 'app/store';
import type { ReactElement } from 'react';
import IAIForm from 'common/components/IAIForm'; import IAIForm from 'common/components/IAIForm';
import { IAIFormItemWrapper } from 'common/components/IAIForms/IAIFormItemWrapper';
function FormItemWrapper({
children,
}: {
children: ReactElement | ReactElement[];
}) {
return (
<Flex
sx={{
flexDirection: 'column',
padding: 4,
rowGap: 4,
borderRadius: 'base',
width: 'full',
bg: 'base.900',
}}
>
{children}
</Flex>
);
}
export default function AddDiffusersModel() { export default function AddDiffusersModel() {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -95,7 +74,7 @@ export default function AddDiffusersModel() {
{({ handleSubmit, errors, touched }) => ( {({ handleSubmit, errors, touched }) => (
<IAIForm onSubmit={handleSubmit}> <IAIForm onSubmit={handleSubmit}>
<VStack rowGap={2}> <VStack rowGap={2}>
<FormItemWrapper> <IAIFormItemWrapper>
{/* Name */} {/* Name */}
<FormControl <FormControl
isInvalid={!!errors.name && touched.name} isInvalid={!!errors.name && touched.name}
@ -123,9 +102,9 @@ export default function AddDiffusersModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</FormItemWrapper> </IAIFormItemWrapper>
<FormItemWrapper> <IAIFormItemWrapper>
{/* Description */} {/* Description */}
<FormControl <FormControl
isInvalid={!!errors.description && touched.description} isInvalid={!!errors.description && touched.description}
@ -152,9 +131,9 @@ export default function AddDiffusersModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</FormItemWrapper> </IAIFormItemWrapper>
<FormItemWrapper> <IAIFormItemWrapper>
<Text fontWeight="bold" fontSize="sm"> <Text fontWeight="bold" fontSize="sm">
{t('modelManager.formMessageDiffusersModelLocation')} {t('modelManager.formMessageDiffusersModelLocation')}
</Text> </Text>
@ -213,9 +192,9 @@ export default function AddDiffusersModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</FormItemWrapper> </IAIFormItemWrapper>
<FormItemWrapper> <IAIFormItemWrapper>
{/* VAE Path */} {/* VAE Path */}
<Text fontWeight="bold"> <Text fontWeight="bold">
{t('modelManager.formMessageDiffusersVAELocation')} {t('modelManager.formMessageDiffusersVAELocation')}
@ -277,7 +256,7 @@ export default function AddDiffusersModel() {
)} )}
</VStack> </VStack>
</FormControl> </FormControl>
</FormItemWrapper> </IAIFormItemWrapper>
<IAIButton type="submit" isLoading={isProcessing}> <IAIButton type="submit" isLoading={isProcessing}>
{t('modelManager.addModel')} {t('modelManager.addModel')}