Skip to content

Commit

Permalink
fix(app-file-manager): remove weird actions booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Apr 25, 2024
1 parent 412cfd6 commit 6fd5e9c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import { GetFileByUrl } from "./GetFileByUrl";
import { UpdateFile } from "./UpdateFile";
import { useFileManagerApi } from "~/modules/FileManagerApiProvider/FileManagerApiContext";
import { useFileModel } from "~/hooks/useFileModel";
import { FileDetailsActions } from "~/components/FileDetails/components/Actions";

interface EditFileRenderProp {
editFile: (url: string) => void;
}

interface EditFileUsingUrlProps {
onUpdate?: (file: FileItem) => void;
actions?: Partial<FileDetailsActions>;
children: (params: EditFileRenderProp) => React.ReactNode;
}

Expand All @@ -28,7 +26,7 @@ const voidOnUpdate = () => {
};

export const EditFileUsingUrl = observer(
({ actions, children, onUpdate = voidOnUpdate }: EditFileUsingUrlProps) => {
({ children, onUpdate = voidOnUpdate }: EditFileUsingUrlProps) => {
const client = useApolloClient();
const { showSnackbar } = useSnackbar();
const fileManagerApi = useFileManagerApi();
Expand Down Expand Up @@ -64,17 +62,18 @@ export const EditFileUsingUrl = observer(
}, [vm.errorMessage]);

return (
<FileManagerProvider>
<FileDetails
loading={vm.loadingMessage}
file={vm.file}
onClose={presenter.closeDrawer}
open={vm.isOpened}
onSave={onSave}
actions={{ delete: false, ...actions }}
/>
{children(renderPropParams)}
</FileManagerProvider>
<>
<FileManagerProvider>
<FileDetails
loading={vm.loadingMessage}
file={vm.file}
onClose={presenter.closeDrawer}
open={vm.isOpened}
onSave={onSave}
/>
{children(renderPropParams)}
</FileManagerProvider>
</>
);
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useRef } from "react";
import ReactDOM from "react-dom";
// @ts-expect-error
// @ts-expect-error This package has no types.
import { useHotkeys } from "react-hotkeyz";
import styled from "@emotion/styled";
import { FileItem } from "@webiny/app-admin/types";
Expand All @@ -13,7 +13,7 @@ import { Tab, Tabs } from "@webiny/ui/Tabs";
import { FileDetailsProvider } from "~/components/FileDetails/FileDetailsProvider";
import { Preview } from "./components/Preview";
import { PreviewMeta } from "./components/PreviewMeta";
import { Actions, FileDetailsActions } from "./components/Actions";
import { Actions } from "./components/Actions";
import { Header } from "./components/Header";
import { Elevation } from "@webiny/ui/Elevation";
import { Content } from "./components/Content";
Expand Down Expand Up @@ -47,10 +47,9 @@ interface FileDetailsInnerProps {
file: FileItem;
onClose: () => void;
onSubmit: (fileData: FileItem) => void;
actions: FileDetailsActions;
}

const FileDetailsInner = ({ file, actions, ...props }: FileDetailsInnerProps) => {
const FileDetailsInner = ({ file, ...props }: FileDetailsInnerProps) => {
const fileModel = useFileModel();
const { fileDetails } = useFileManagerViewConfig();

Expand Down Expand Up @@ -90,7 +89,7 @@ const FileDetailsInner = ({ file, actions, ...props }: FileDetailsInnerProps) =>
<Content>
<Content.Panel flex={parseFloat(leftPanel)}>
<Elevation z={2} style={{ margin: 20 }}>
<Actions actions={actions} />
<Actions />
<Preview />
<PreviewMeta />
</Elevation>
Expand Down Expand Up @@ -142,17 +141,9 @@ export interface FileDetailsProps {
loading: string | null;
onClose: () => void;
onSave: (file: FileItem) => void;
actions?: Partial<FileDetailsActions>;
}

export const FileDetails = ({
open,
onClose,
onSave,
loading,
file,
...props
}: FileDetailsProps) => {
export const FileDetails = ({ open, onClose, onSave, loading, file }: FileDetailsProps) => {
useHotkeys({
zIndex: 55,
disabled: !open,
Expand All @@ -161,17 +152,6 @@ export const FileDetails = ({
}
});

const actions: FileDetailsActions = Object.assign(
{
copyUrl: true,
delete: true,
moveToFolder: true,
download: true,
edit: true
},
props.actions
);

const { fileDetails } = useFileManagerViewConfig();

const drawerWidth = fileDetails.width.split(",")[0];
Expand All @@ -190,12 +170,7 @@ export const FileDetails = ({
{file && (
<FileProvider file={file}>
<FileDetailsProvider hideFileDetails={onClose}>
<FileDetailsInner
file={file}
onClose={onClose}
onSubmit={onSave}
actions={actions}
/>
<FileDetailsInner file={file} onClose={onClose} onSubmit={onSave} />
</FileDetailsProvider>
</FileProvider>
)}
Expand Down

0 comments on commit 6fd5e9c

Please sign in to comment.