🐛 Bug fixes (#673)

This commit is contained in:
Montassar Ghanmy
2024-10-01 09:19:00 +01:00
committed by GitHub
parent 5bc7219421
commit 8d172b51f3
5 changed files with 35 additions and 20 deletions
@@ -13,7 +13,7 @@ import { useUserQuota } from 'features/users/hooks/use-user-quota';
* Returns the children of a drive item * Returns the children of a drive item
* @returns * @returns
*/ */
export const useDriveActions = () => { export const useDriveActions = (inPublicSharing?: boolean) => {
const companyId = useRouterCompany(); const companyId = useRouterCompany();
const sharedFilter = useRecoilValue(SharedWithMeFilterState); const sharedFilter = useRecoilValue(SharedWithMeFilterState);
const sortItem = useRecoilValue(DriveItemSort); const sortItem = useRecoilValue(DriveItemSort);
@@ -142,7 +142,7 @@ export const useDriveActions = () => {
try { try {
await DriveApiClient.update(companyId, id, update); await DriveApiClient.update(companyId, id, update);
await refresh(id || '', true); await refresh(id || '', true);
await refresh(parentId || '', true); if (!inPublicSharing) await refresh(parentId || '', true);
if (update?.parent_id !== parentId) await refresh(update?.parent_id || '', true); if (update?.parent_id !== parentId) await refresh(update?.parent_id || '', true);
} catch (e) { } catch (e) {
ToasterService.error(Languages.t('hooks.use-drive-actions.unable_update_file')); ToasterService.error(Languages.t('hooks.use-drive-actions.unable_update_file'));
@@ -160,7 +160,7 @@ export default memo(
const selectedCount = Object.values(checked).filter(v => v).length; const selectedCount = Object.values(checked).filter(v => v).length;
const onBuildContextMenu = useOnBuildContextMenu(children, initialParentId); const onBuildContextMenu = useOnBuildContextMenu(children, initialParentId, inPublicSharing);
const onBuildSortContextMenu = useOnBuildSortContextMenu(); const onBuildSortContextMenu = useOnBuildSortContextMenu();
const handleDragOver = (event: { preventDefault: () => void }) => { const handleDragOver = (event: { preventDefault: () => void }) => {
@@ -31,7 +31,11 @@ import { hasAnyPublicLinkAccess } from '@features/files/utils/access-info-helper
/** /**
* This will build the context menu in different contexts * This will build the context menu in different contexts
*/ */
export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: string) => { export const useOnBuildContextMenu = (
children: DriveItem[],
initialParentId?: string,
inPublicSharing?: boolean,
) => {
const [checkedIds, setChecked] = useRecoilState(DriveItemSelectedList); const [checkedIds, setChecked] = useRecoilState(DriveItemSelectedList);
const checked = children.filter(c => checkedIds[c.id]); const checked = children.filter(c => checkedIds[c.id]);
@@ -55,7 +59,7 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
const company = useRouterCompany(); const company = useRouterCompany();
function getIdsFromArray(arr: DriveItem[]): string[] { function getIdsFromArray(arr: DriveItem[]): string[] {
return arr.map((obj) => obj.id); return arr.map(obj => obj.id);
} }
return useCallback( return useCallback(
@@ -63,7 +67,7 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
if (!parent || !parent.access) return []; if (!parent || !parent.access) return [];
try { try {
const inTrash = parent.path?.[0]?.id.includes('trash') || viewId?.includes("trash"); const inTrash = parent.path?.[0]?.id.includes('trash') || viewId?.includes('trash');
const isPersonal = item?.scope === 'personal'; const isPersonal = item?.scope === 'personal';
const selectedCount = checked.length; const selectedCount = checked.length;
@@ -88,7 +92,7 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
hide: access === 'read' || getPublicLinkToken() || inTrash, hide: access === 'read' || getPublicLinkToken() || inTrash,
onClick: () => setAccessModalState({ open: true, id: item.id }), onClick: () => setAccessModalState({ open: true, id: item.id }),
}, },
{ type: 'separator' }, { type: 'separator', hide: inTrash },
{ {
type: 'menu', type: 'menu',
icon: 'download-alt', icon: 'download-alt',
@@ -100,7 +104,7 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
} else { } else {
download(item.id); download(item.id);
} }
} },
}, },
/*TODO: fix loading of preview in new window and uncomment. See https://github.com/linagora/twake-drive/issues/603 . /*TODO: fix loading of preview in new window and uncomment. See https://github.com/linagora/twake-drive/issues/603 .
{ {
@@ -144,13 +148,16 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
icon: 'file-edit-alt', icon: 'file-edit-alt',
text: Languages.t('components.item_context_menu.rename'), text: Languages.t('components.item_context_menu.rename'),
hide: access === 'read' || inTrash, hide: access === 'read' || inTrash,
onClick: () => setPropertiesModalState({ open: true, id: item.id }), onClick: () => setPropertiesModalState({ open: true, id: item.id, inPublicSharing }),
}, },
{ {
type: 'menu', type: 'menu',
icon: 'link', icon: 'link',
text: Languages.t('components.item_context_menu.copy_link'), text: Languages.t('components.item_context_menu.copy_link'),
hide: !item.access_info.public?.level || item.access_info.public?.level === 'none' || inTrash, hide:
!item.access_info.public?.level ||
item.access_info.public?.level === 'none' ||
inTrash,
onClick: () => { onClick: () => {
copyToClipboard(getPublicLink(item || parent?.item)); copyToClipboard(getPublicLink(item || parent?.item));
ToasterService.success( ToasterService.success(
@@ -165,7 +172,7 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
hide: item.is_directory || inTrash, hide: item.is_directory || inTrash,
onClick: () => setVersionModal({ open: true, id: item.id }), onClick: () => setVersionModal({ open: true, id: item.id }),
}, },
{ type: 'separator', hide: access !== 'manage' || inTrash, }, { type: 'separator', hide: access !== 'manage' || inTrash },
{ {
type: 'menu', type: 'menu',
icon: 'trash', icon: 'trash',
@@ -304,10 +311,12 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
if (parent.children && parent.children.length > 0) { if (parent.children && parent.children.length > 0) {
downloadZip([parent.item!.id]); downloadZip([parent.item!.id]);
} else if (parent.item) { } else if (parent.item) {
console.log("Download folder itself"); console.log('Download folder itself');
download(parent.item.id); download(parent.item.id);
} else { } else {
console.error("Very strange, everything is null, you are trying to download undefined"); console.error(
'Very strange, everything is null, you are trying to download undefined',
);
} }
}, },
}, },
@@ -322,13 +331,13 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
); );
}, },
}, },
{ type: 'separator', hide: parent.item!.id != 'root', }, { type: 'separator', hide: parent.item!.id != 'root' },
{ {
type: 'menu', type: 'menu',
text: Languages.t('components.item_context_menu.manage_users'), text: Languages.t('components.item_context_menu.manage_users'),
hide: parent.item!.id != 'root', hide: parent.item!.id != 'root',
onClick: () => setUsersModalState({ open: true }), onClick: () => setUsersModalState({ open: true }),
} },
]; ];
if (menu.length && newMenuActions.filter(a => !a.hide).length) { if (menu.length && newMenuActions.filter(a => !a.hide).length) {
menu = [...menu, { type: 'separator' }]; menu = [...menu, { type: 'separator' }];
@@ -11,6 +11,7 @@ import Languages from '@features/global/services/languages-service';
export type PropertiesModalType = { export type PropertiesModalType = {
open: boolean; open: boolean;
id: string; id: string;
inPublicSharing?: boolean;
}; };
export const PropertiesModalAtom = atom<PropertiesModalType>({ export const PropertiesModalAtom = atom<PropertiesModalType>({
@@ -18,6 +19,7 @@ export const PropertiesModalAtom = atom<PropertiesModalType>({
default: { default: {
open: false, open: false,
id: '', id: '',
inPublicSharing: false,
}, },
}); });
@@ -27,15 +29,19 @@ export const PropertiesModal = () => {
return ( return (
<Modal open={state.open} onClose={() => setState({ ...state, open: false })}> <Modal open={state.open} onClose={() => setState({ ...state, open: false })}>
{!!state.id && ( {!!state.id && (
<PropertiesModalContent id={state.id} onClose={() => setState({ ...state, open: false })} /> <PropertiesModalContent
id={state.id}
onClose={() => setState({ ...state, open: false })}
inPublicSharing={state.inPublicSharing}
/>
)} )}
</Modal> </Modal>
); );
}; };
const PropertiesModalContent = ({ id, onClose }: { id: string; onClose: () => void }) => { const PropertiesModalContent = ({ id, onClose, inPublicSharing }: { id: string; onClose: () => void, inPublicSharing?: boolean }) => {
const { item, refresh } = useDriveItem(id); const { item, refresh } = useDriveItem(id);
const { update } = useDriveActions(); const { update } = useDriveActions(inPublicSharing);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [name, setName] = useState(''); const [name, setName] = useState('');
@@ -68,7 +68,7 @@ export default () => {
<Avatar avatar={group.logo} className="inline-block mr-3" size="sm" type="square" /> <Avatar avatar={group.logo} className="inline-block mr-3" size="sm" type="square" />
)} )}
<span className="text-white font-semibold" style={{ lineHeight: '32px' }}> <span className="text-white font-semibold" style={{ lineHeight: '32px' }}>
{group.name} Twake Drive
</span> </span>
</div> </div>
<div className="shrink-0"> <div className="shrink-0">
@@ -82,7 +82,7 @@ export default () => {
</div> </div>
<div className="h-full main-view public p-4 pb-16"> <div className="h-full main-view public p-4 pb-16">
<AccessChecker folderId={documentId} token={token}> <AccessChecker folderId={documentId} token={token}>
<Drive initialParentId={documentId} inPublicSharing /> <Drive initialParentId={documentId} inPublicSharing={true} />
</AccessChecker> </AccessChecker>
</div> </div>
<MenusBodyLayer /> <MenusBodyLayer />