Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): various error toast optimizations #6409

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions invokeai/frontend/web/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@
"metadataLoadFailed": "Failed to load metadata",
"modelAddedSimple": "Model Added to Queue",
"modelImportCanceled": "Model Import Canceled",
"outOfMemoryError": "Out of Memory Error",
"outOfMemoryDescription": "Your current generation settings exceed system capacity. Please adjust your settings and try again.",
"parameters": "Parameters",
"parameterNotSet": "{{parameter}} not set",
"parameterSet": "{{parameter}} set",
Expand All @@ -1114,6 +1116,7 @@
"resetInitialImage": "Reset Initial Image",
"sentToImageToImage": "Sent To Image To Image",
"sentToUnifiedCanvas": "Sent to Unified Canvas",
"sessionReference": "Session Reference",
"serverError": "Server Error",
"setAsCanvasInitialImage": "Set as canvas initial image",
"setCanvasInitialImage": "Set canvas initial image",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Flex, IconButton, Text } from '@invoke-ai/ui-library';
import { t } from 'i18next';
import { PiCopyBold } from 'react-icons/pi';

function handleCopy(sessionId: string) {
navigator.clipboard.writeText(sessionId);
}

export default function ToastDescription({ message, sessionId }: { message: string; sessionId: string }) {
return (
<Flex flexDir="column">
<Text fontSize="md">{message}</Text>
<Flex gap="2" alignItems="center">
<Text fontSize="sm">
{t('toast.sessionReference')}: {sessionId}
</Text>
<IconButton
size="sm"
aria-label="Copy"
colorScheme="error"
icon={<PiCopyBold />}
onClick={handleCopy.bind(null, sessionId)}
/>
</Flex>
</Flex>
);
}
33 changes: 25 additions & 8 deletions invokeai/frontend/web/src/features/system/store/systemSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type { UseToastOptions } from '@invoke-ai/ui-library';
import type { PayloadAction } from '@reduxjs/toolkit';
import { createSlice, isAnyOf } from '@reduxjs/toolkit';
import type { PersistConfig, RootState } from 'app/store/store';
import { toast } from 'common/util/toast';
import ToastDescription from 'features/system/components/ToastDescription';
import { calculateStepPercentage } from 'features/system/util/calculateStepPercentage';
import { makeToast } from 'features/system/util/makeToast';
import { t } from 'i18next';
import { startCase } from 'lodash-es';
import type { LogLevelName } from 'roarr';
Expand Down Expand Up @@ -169,13 +170,29 @@ export const systemSlice = createSlice({
* Any server error
*/
builder.addMatcher(isAnyServerError, (state, action) => {
state.toastQueue.push(
makeToast({
title: t('toast.serverError'),
status: 'error',
description: startCase(action.payload.data.error_type),
})
);
const errorType = startCase(action.payload.data.error_type);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we aren't using state, maybe this would be better as a listener?

const errorId = `toast-${errorType}`;
const sessionId = action.payload.data.graph_execution_state_id;

if (!toast.isActive(errorId)) {
if (errorType === 'OutOfMemoryError') {
toast({
id: errorId,
title: t('toast.outOfMemoryError'),
status: 'error',
description: ToastDescription({ message: t('toast.outOfMemoryDescription'), sessionId }),
duration: null,
});
} else {
toast({
id: errorId,
title: t('toast.serverError'),
status: 'error',
description: ToastDescription({ message: startCase(action.payload.data.error_type), sessionId }),
duration: null,
});
}
}
});
},
});
Expand Down
Loading