Skip to content

Commit

Permalink
fix: #667 irrelevant warning when renaming a file shared with me by link
Browse files Browse the repository at this point in the history
  • Loading branch information
Monta authored and Monta committed Sep 29, 2024
1 parent 0aa23be commit 2f2b77a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useUserQuota } from 'features/users/hooks/use-user-quota';
* Returns the children of a drive item
* @returns
*/
export const useDriveActions = () => {
export const useDriveActions = (inPublicSharing?: boolean) => {
const companyId = useRouterCompany();
const sharedFilter = useRecoilValue(SharedWithMeFilterState);
const sortItem = useRecoilValue(DriveItemSort);
Expand Down Expand Up @@ -142,7 +142,7 @@ export const useDriveActions = () => {
try {
await DriveApiClient.update(companyId, id, update);
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);
} catch (e) {
ToasterService.error(Languages.t('hooks.use-drive-actions.unable_update_file'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default memo(

const selectedCount = Object.values(checked).filter(v => v).length;

const onBuildContextMenu = useOnBuildContextMenu(children, initialParentId);
const onBuildContextMenu = useOnBuildContextMenu(children, initialParentId, inPublicSharing);
const onBuildSortContextMenu = useOnBuildSortContextMenu();

const handleDragOver = (event: { preventDefault: () => void }) => {
Expand Down
22 changes: 14 additions & 8 deletions tdrive/frontend/src/app/views/client/body/drive/context-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import { hasAnyPublicLinkAccess } from '@features/files/utils/access-info-helper
/**
* 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 checked = children.filter(c => checkedIds[c.id]);

Expand All @@ -55,15 +59,15 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
const company = useRouterCompany();

function getIdsFromArray(arr: DriveItem[]): string[] {
return arr.map((obj) => obj.id);
return arr.map(obj => obj.id);
}

return useCallback(
async (parent?: Partial<DriveItemDetails> | null, item?: DriveItem) => {
if (!parent || !parent.access) return [];

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 selectedCount = checked.length;

Expand Down Expand Up @@ -144,7 +148,7 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
icon: 'file-edit-alt',
text: Languages.t('components.item_context_menu.rename'),
hide: access === 'read' || inTrash,
onClick: () => setPropertiesModalState({ open: true, id: item.id }),
onClick: () => setPropertiesModalState({ open: true, id: item.id, inPublicSharing }),
},
{
type: 'menu',
Expand Down Expand Up @@ -307,10 +311,12 @@ export const useOnBuildContextMenu = (children: DriveItem[], initialParentId?: s
if (parent.children && parent.children.length > 0) {
downloadZip([parent.item!.id]);
} else if (parent.item) {
console.log("Download folder itself");
console.log('Download folder itself');
download(parent.item.id);
} 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',
);
}
},
},
Expand All @@ -325,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',
text: Languages.t('components.item_context_menu.manage_users'),
hide: parent.item!.id != 'root',
onClick: () => setUsersModalState({ open: true }),
}
},
];
if (menu.length && newMenuActions.filter(a => !a.hide).length) {
menu = [...menu, { type: 'separator' }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import Languages from '@features/global/services/languages-service';
export type PropertiesModalType = {
open: boolean;
id: string;
inPublicSharing?: boolean;
};

export const PropertiesModalAtom = atom<PropertiesModalType>({
key: 'PropertiesModalAtom',
default: {
open: false,
id: '',
inPublicSharing: false,
},
});

Expand All @@ -27,15 +29,19 @@ export const PropertiesModal = () => {
return (
<Modal open={state.open} onClose={() => setState({ ...state, open: false })}>
{!!state.id && (
<PropertiesModalContent id={state.id} onClose={() => setState({ ...state, open: false })} />
<PropertiesModalContent
id={state.id}
onClose={() => setState({ ...state, open: false })}
inPublicSharing={state.inPublicSharing}
/>
)}
</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 { update } = useDriveActions();
const { update } = useDriveActions(inPublicSharing);
const [loading, setLoading] = useState(false);
const [name, setName] = useState('');

Expand Down
2 changes: 1 addition & 1 deletion tdrive/frontend/src/app/views/client/body/drive/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default () => {
</div>
<div className="h-full main-view public p-4 pb-16">
<AccessChecker folderId={documentId} token={token}>
<Drive initialParentId={documentId} inPublicSharing />
<Drive initialParentId={documentId} inPublicSharing={true} />
</AccessChecker>
</div>
<MenusBodyLayer />
Expand Down

0 comments on commit 2f2b77a

Please sign in to comment.