Skip to content

Commit 4ab382e

Browse files
[CP-3663] Refactored image preview (#2638)
Co-authored-by: slawomir-werner <[email protected]>
1 parent f5bf729 commit 4ab382e

File tree

16 files changed

+796
-569
lines changed

16 files changed

+796
-569
lines changed

libs/core/__deprecated__/renderer/locales/default/en-US.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,6 @@
10561056
"module.genericViews.filesManager.preview.unknownError": "Failed to load photo.\nPlease try again.",
10571057
"module.genericViews.filesManager.preview.backButton": "Back",
10581058
"module.genericViews.filesManager.preview.retryButton": "Try again",
1059-
10601059
"module.genericViews.appInstallation.progress.modalTitle": "Installing the App...",
10611060
"module.genericViews.appInstallation.error.modalTitle": "Installation failed",
10621061
"module.genericViews.appInstallation.error.globalMessage": "The installation process was interrupted.",

libs/core/core/components/root-wrapper.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,28 @@ import localeEn from "Core/__deprecated__/renderer/locales/default/en-US.json"
1515
import { ModalProvider } from "Core/__deprecated__/renderer/components/core/modal/modal.service"
1616
import modalService from "Core/__deprecated__/renderer/components/core/modal/modal.service"
1717
import AppsSwitch from "Core/core/components/apps-switch"
18+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
19+
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
1820

1921
const RootWrapper: FunctionComponent = () => {
22+
const queryClient = new QueryClient()
2023
return (
21-
<ThemeProvider theme={theme}>
22-
<IntlProvider
23-
defaultLocale={translationConfig.defaultLanguage}
24-
locale={translationConfig.defaultLanguage}
25-
messages={localeEn}
26-
>
27-
<ModalProvider service={modalService}>
28-
<Normalize />
29-
<GlobalStyle />
30-
<AppsSwitch />
31-
</ModalProvider>
32-
</IntlProvider>
33-
</ThemeProvider>
24+
<QueryClientProvider client={queryClient}>
25+
<ReactQueryDevtools initialIsOpen={false} />
26+
<ThemeProvider theme={theme}>
27+
<IntlProvider
28+
defaultLocale={translationConfig.defaultLanguage}
29+
locale={translationConfig.defaultLanguage}
30+
messages={localeEn}
31+
>
32+
<ModalProvider service={modalService}>
33+
<Normalize />
34+
<GlobalStyle />
35+
<AppsSwitch />
36+
</ModalProvider>
37+
</IntlProvider>
38+
</ThemeProvider>
39+
</QueryClientProvider>
3440
)
3541
}
3642

libs/generic-view/ui/src/lib/generated/mc-file-manager/file-export-button.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ export const generateFilesExportButtonActions = (
2222
{
2323
singleEntityId,
2424
entityType,
25-
exportActionId,
25+
exportActionId = entityType + "Export",
2626
}: Pick<McFileManagerConfig["categories"][number], "entityType"> & {
2727
singleEntityId?: string
28-
exportActionId: string
28+
exportActionId?: string
2929
}
3030
): ButtonTextConfig["actions"] => {
3131
return [
@@ -128,9 +128,17 @@ export const generateFileExportProcessButton: ComponentGenerator<
128128
"entityType" | "directoryPath"
129129
> & {
130130
singleEntityId?: string
131-
exportActionId: string
131+
exportActionId?: string
132132
}
133-
> = (key, { directoryPath, entityType, singleEntityId, exportActionId }) => {
133+
> = (
134+
key,
135+
{
136+
directoryPath,
137+
entityType,
138+
singleEntityId,
139+
exportActionId = entityType + "Export",
140+
}
141+
) => {
134142
return {
135143
[generateFilesExportProcessButtonKey(key)]: {
136144
component: "button-text",

libs/generic-view/ui/src/lib/generated/mc-file-manager/file-list.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ const generateFileList: ComponentGenerator<
3939
features,
4040
}
4141
) => {
42-
const isExportEnabled = features?.includes("export")
42+
const isExportEnabled = Boolean(features?.includes("export"))
43+
const isPreviewEnabled =
44+
Boolean(features?.includes("preview")) && entityType === "imageFiles"
4345
return {
4446
[`${key}${id}fileListContainer`]: {
4547
component: "conditional-renderer",
@@ -297,7 +299,6 @@ const generateFileList: ComponentGenerator<
297299
...generateFileExportProcessButton(`${key}${id}`, {
298300
directoryPath,
299301
entityType,
300-
exportActionId: entityType + "Export",
301302
}),
302303
[`${key}${id}deleteButton`]: {
303304
component: "button-text",
@@ -355,7 +356,7 @@ const generateFileList: ComponentGenerator<
355356
allIdsFieldName: "allItems",
356357
},
357358
previewOptions: {
358-
enabled: entityType === "imageFiles",
359+
enabled: isPreviewEnabled,
359360
entitiesType: entityType,
360361
entityIdFieldName: "id",
361362
entityPathFieldName: "filePath",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (c) Mudita sp. z o.o. All rights reserved.
3+
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
4+
*/
5+
6+
export enum FilePreviewErrorType {
7+
UnsupportedFileType = "unsupported-file-type",
8+
UnsupportedTransferMode = "unsupported-transfer-mode",
9+
FileNotFound = "file-not-found",
10+
Unknown = "unknown",
11+
}
12+
13+
export type FilePreviewError = {
14+
type: FilePreviewErrorType
15+
details?: string
16+
}
17+
18+
export const isFilePreviewError = (
19+
error: unknown
20+
): error is FilePreviewError => {
21+
return (
22+
typeof error === "object" &&
23+
"type" in (error as FilePreviewError) &&
24+
Object.values(FilePreviewErrorType).includes(
25+
(error as FilePreviewError).type
26+
)
27+
)
28+
}

libs/generic-view/ui/src/lib/predefined/file-preview/file-preview-error.types.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)