feat(ui): add badges for advanced settings

This commit is contained in:
psychedelicious 2024-01-03 09:23:10 +11:00
parent b1b5c0d3b2
commit 930de51910
4 changed files with 43 additions and 7 deletions

View File

@ -3,12 +3,19 @@ import {
Spacer, Spacer,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { InvBadge } from 'common/components/InvBadge/wrapper'; import { InvBadge } from 'common/components/InvBadge/wrapper';
import { truncate } from 'lodash-es';
import { useMemo } from 'react';
import type { InvAccordionButtonProps } from './types'; import type { InvAccordionButtonProps } from './types';
import { InvAccordionIcon } from './wrapper'; import { InvAccordionIcon } from './wrapper';
export const InvAccordionButton = (props: InvAccordionButtonProps) => { export const InvAccordionButton = (props: InvAccordionButtonProps) => {
const { children, badges, ...rest } = props; const { children, badges: _badges, ...rest } = props;
const badges = useMemo<string[] | undefined>(
() =>
_badges?.map((b) => truncate(String(b), { length: 24, omission: '...' })),
[_badges]
);
return ( return (
<ChakraAccordionButton {...rest}> <ChakraAccordionButton {...rest}>
{children} {children}

View File

@ -1,7 +1,7 @@
import { defineStyle, defineStyleConfig } from '@chakra-ui/react'; import { defineStyle, defineStyleConfig } from '@chakra-ui/react';
const baseStyle = defineStyle((props) => ({ const baseStyle = defineStyle((props) => ({
fontSize: '10px', fontSize: '9px',
px: 2, px: 2,
py: 1, py: 1,
minW: 4, minW: 4,
@ -11,6 +11,10 @@ const baseStyle = defineStyle((props) => ({
color: 'base.900', color: 'base.900',
fontWeight: 'bold', fontWeight: 'bold',
letterSpacing: 0.5, letterSpacing: 0.5,
wordBreak: 'break-all',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden'
})); }));
export const badgeTheme = defineStyleConfig({ export const badgeTheme = defineStyleConfig({

View File

@ -1,4 +1,7 @@
import { Flex } from '@chakra-ui/layout'; import { Flex } from '@chakra-ui/layout';
import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
import { stateSelector } from 'app/store/store';
import { useAppSelector } from 'app/store/storeHooks';
import { InvControlGroup } from 'common/components/InvControl/InvControlGroup'; import { InvControlGroup } from 'common/components/InvControl/InvControlGroup';
import type { InvLabelProps } from 'common/components/InvControl/types'; import type { InvLabelProps } from 'common/components/InvControl/types';
import { InvSingleAccordion } from 'common/components/InvSingleAccordion/InvSingleAccordion'; import { InvSingleAccordion } from 'common/components/InvSingleAccordion/InvSingleAccordion';
@ -19,11 +22,35 @@ const labelProps2: InvLabelProps = {
flexGrow: 1, flexGrow: 1,
}; };
const selectBadges = createMemoizedSelector(stateSelector, (state) => {
const badges: (string | number)[] = [];
if (state.generation.vae) {
let vaeBadge = state.generation.vae.model_name;
if (state.generation.vaePrecision === 'fp16') {
vaeBadge += ` ${state.generation.vaePrecision}`;
}
badges.push(vaeBadge);
} else if (state.generation.vaePrecision === 'fp16') {
badges.push(`VAE ${state.generation.vaePrecision}`);
}
if (state.generation.clipSkip) {
badges.push(`Skip ${state.generation.clipSkip}`);
}
if (state.generation.cfgRescaleMultiplier) {
badges.push(`Rescale ${state.generation.cfgRescaleMultiplier}`);
}
if (state.generation.seamlessXAxis || state.generation.seamlessYAxis) {
badges.push('seamless');
}
return badges;
});
export const AdvancedSettingsAccordion = memo(() => { export const AdvancedSettingsAccordion = memo(() => {
const badges = useAppSelector(selectBadges);
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
<InvSingleAccordion label={t('accordions.advanced.title')}> <InvSingleAccordion label={t('accordions.advanced.title')} badges={badges}>
<Flex gap={4} alignItems="center" p={4} flexDir="column"> <Flex gap={4} alignItems="center" p={4} flexDir="column">
<Flex gap={4} w="full"> <Flex gap={4} w="full">
<ParamVAEModelSelect /> <ParamVAEModelSelect />

View File

@ -20,7 +20,7 @@ import ParamCFGScale from 'features/parameters/components/Core/ParamCFGScale';
import ParamScheduler from 'features/parameters/components/Core/ParamScheduler'; import ParamScheduler from 'features/parameters/components/Core/ParamScheduler';
import ParamSteps from 'features/parameters/components/Core/ParamSteps'; import ParamSteps from 'features/parameters/components/Core/ParamSteps';
import ParamMainModelSelect from 'features/parameters/components/MainModel/ParamMainModelSelect'; import ParamMainModelSelect from 'features/parameters/components/MainModel/ParamMainModelSelect';
import { size, truncate } from 'lodash-es'; import { size } from 'lodash-es';
import { memo } from 'react'; import { memo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -34,9 +34,7 @@ const badgesSelector = createMemoizedSelector(
const loraTabBadges = size(lora.loras) ? [size(lora.loras)] : []; const loraTabBadges = size(lora.loras) ? [size(lora.loras)] : [];
const accordionBadges: (string | number)[] = []; const accordionBadges: (string | number)[] = [];
if (generation.model) { if (generation.model) {
accordionBadges.push( accordionBadges.push(generation.model.model_name);
truncate(generation.model.model_name, { length: 24, omission: '...' })
);
accordionBadges.push(generation.model.base_model); accordionBadges.push(generation.model.base_model);
} }