Skip to content

Commit

Permalink
feat(ui): progress alert config setting
Browse files Browse the repository at this point in the history
- Add `invocationProgressAlert` as a disable-able feature. Hide the alert and the setting in system settings when disabled.
- Fix merge conflict
  • Loading branch information
psychedelicious committed Nov 14, 2024
1 parent 5effa8f commit 283a966
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
3 changes: 2 additions & 1 deletion invokeai/frontend/web/src/app/types/invokeai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export type AppFeature =
| 'invocationCache'
| 'bulkDownload'
| 'starterModels'
| 'hfToken';
| 'hfToken'
| 'invocationProgressAlert';

/**
* A disable-able Stable Diffusion feature
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
import { Alert, AlertDescription, AlertIcon, AlertTitle } from '@invoke-ai/ui-library';
import { useStore } from '@nanostores/react';
import { useAppSelector } from 'app/store/storeHooks';
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
import { selectSystemShouldShowInvocationProgressDetail } from 'features/system/store/systemSlice';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { $canvasProgressMessage } from 'services/events/stores';
import { $invocationProgressMessage } from 'services/events/stores';

export const CanvasAlertsInvocationProgress = memo(() => {
const CanvasAlertsInvocationProgressContent = memo(() => {
const { t } = useTranslation();
const progressEventMessage = useStore($canvasProgressMessage);
const shouldShowInvocationProgressDetail = useAppSelector(selectSystemShouldShowInvocationProgressDetail);
const invocationProgressMessage = useStore($invocationProgressMessage);

if (!shouldShowInvocationProgressDetail || !progressEventMessage) {
if (!invocationProgressMessage) {
return null;
}

return (
<Alert status="loading" borderRadius="base" fontSize="sm" shadow="md" w="fit-content">
<AlertIcon />
<AlertTitle>{t('common.generating')}</AlertTitle>
<AlertDescription>{progressEventMessage}</AlertDescription>
<AlertDescription>{invocationProgressMessage}</AlertDescription>
</Alert>
);
});
CanvasAlertsInvocationProgressContent.displayName = 'CanvasAlertsInvocationProgressContent';

export const CanvasAlertsInvocationProgress = memo(() => {
const isProgressMessageAlertEnabled = useFeatureStatus('invocationProgressAlert');
const shouldShowInvocationProgressDetail = useAppSelector(selectSystemShouldShowInvocationProgressDetail);

// The alert is disabled at the system level
if (!isProgressMessageAlertEnabled) {
return null;
}

// The alert is disabled at the user level
if (!shouldShowInvocationProgressDetail) {
return null;
}

return <CanvasAlertsInvocationProgressContent />;
});

CanvasAlertsInvocationProgress.displayName = 'CanvasAlertsInvocationProgress';
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const CurrentImagePreview = () => {
pointerEvents="none"
alignItems="flex-start"
>
<CanvasAlertsInvocationProgress />
<CanvasAlertsSendingToCanvas />
<CanvasAlertsInvocationProgress />
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const SettingsMenu = () => {
{t('common.hotkeysLabel')}
</MenuItem>
</HotkeysModal>
<SettingsModal config={{ shouldShowInvocationProgressDetailToggle: false }}>
<SettingsModal>
<MenuItem as="button" icon={<PiToggleRightFill />}>
{t('common.settingsLabel')}
</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { SettingsDeveloperLogLevel } from 'features/system/components/SettingsMo
import { SettingsDeveloperLogNamespaces } from 'features/system/components/SettingsModal/SettingsDeveloperLogNamespaces';
import { useClearIntermediates } from 'features/system/components/SettingsModal/useClearIntermediates';
import { StickyScrollable } from 'features/system/components/StickyScrollable';
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
import {
selectSystemShouldAntialiasProgressImage,
selectSystemShouldConfirmOnDelete,
Expand Down Expand Up @@ -58,15 +59,13 @@ type ConfigOptions = {
shouldShowResetWebUiText?: boolean;
shouldShowClearIntermediates?: boolean;
shouldShowLocalizationToggle?: boolean;
shouldShowInvocationProgressDetailToggle?: boolean;
};

const defaultConfig: ConfigOptions = {
shouldShowDeveloperSettings: true,
shouldShowResetWebUiText: true,
shouldShowClearIntermediates: true,
shouldShowLocalizationToggle: true,
shouldShowInvocationProgressDetailToggle: true,
};

type SettingsModalProps = {
Expand Down Expand Up @@ -108,6 +107,7 @@ const SettingsModal = ({ config = defaultConfig, children }: SettingsModalProps)
const shouldEnableModelDescriptions = useAppSelector(selectSystemShouldEnableModelDescriptions);
const shouldConfirmOnNewSession = useAppSelector(selectSystemShouldConfirmOnNewSession);
const shouldShowInvocationProgressDetail = useAppSelector(selectSystemShouldShowInvocationProgressDetail);
const isInvocationProgressAlertEnabled = useFeatureStatus('invocationProgressAlert');
const onToggleConfirmOnNewSession = useCallback(() => {
dispatch(shouldConfirmOnNewSessionToggled());
}, [dispatch]);
Expand Down Expand Up @@ -233,7 +233,7 @@ const SettingsModal = ({ config = defaultConfig, children }: SettingsModalProps)
onChange={handleChangeShouldAntialiasProgressImage}
/>
</FormControl>
{Boolean(config?.shouldShowInvocationProgressDetailToggle) && (
{isInvocationProgressAlertEnabled && (
<FormControl>
<FormLabel>{t('settings.showDetailedInvocationProgress')}</FormLabel>
<Switch
Expand Down
2 changes: 1 addition & 1 deletion invokeai/frontend/web/src/services/events/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const $lastProgressEvent = atom<S['InvocationProgressEvent'] | null>(null
export const $progressImage = computed($lastProgressEvent, (val) => val?.image ?? null);
export const $hasProgressImage = computed($lastProgressEvent, (val) => Boolean(val?.image));
export const $isProgressFromCanvas = computed($lastProgressEvent, (val) => val?.destination === 'canvas');
export const $canvasProgressMessage = computed($lastProgressEvent, (val) => {
export const $invocationProgressMessage = computed($lastProgressEvent, (val) => {
if (!val) {
return null;
}
Expand Down

0 comments on commit 283a966

Please sign in to comment.