Skip to content

Commit

Permalink
Breakpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Oct 30, 2024
1 parent 993c4c2 commit 6e1ef87
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 174 deletions.
57 changes: 35 additions & 22 deletions web/src/core/usecases/fileExplorer/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,41 @@ const currentWorkingDirectoryView = createSelector(
if (directoryPath === undefined) {
return undefined;
}
const items = objects.map(object => {
const isBeingUploaded = ongoingOperations.some(
op => op.operation === "create" && op.object.basename === object.basename
);

const isBeingDeleted = ongoingOperations.some(
op => op.operation === "delete" && op.object.basename === object.basename
);

const isPolicyChanging = ongoingOperations.some(
op =>
op.operation === "modifyPolicy" &&
op.object.basename === object.basename
);

return {
...object,
isBeingUploaded,
isBeingDeleted,
isPolicyChanging
};
});
const items = objects
.map(object => {
const isBeingUploaded = ongoingOperations.some(
op =>
op.operation === "create" &&
op.object.basename === object.basename
);

const isBeingDeleted = ongoingOperations.some(
op =>
op.operation === "delete" &&
op.object.basename === object.basename
);

const isPolicyChanging = ongoingOperations.some(
op =>
op.operation === "modifyPolicy" &&
op.object.basename === object.basename
);

return {
...object,
isBeingUploaded,
isBeingDeleted,
isPolicyChanging
};
})
.sort((a, b) => {
// Sort directories first
if (a.kind === "directory" && b.kind !== "directory") return -1;
if (a.kind !== "directory" && b.kind === "directory") return 1;

// Sort alphabetically by basename
return a.basename.localeCompare(b.basename);
});

return {
directoryPath,
Expand Down
72 changes: 40 additions & 32 deletions web/src/core/usecases/fileExplorer/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,50 @@ export declare namespace ExplorersCreateParams {

const privateThunks = {
"createOperation":
(params: { operation: "create" | "delete" | "modifyPolicy"; object: S3Object }) =>
(params: {
operation: "create" | "delete" | "modifyPolicy";
object: S3Object;
directoryPath: string;
}) =>
async (...args) => {
const [dispatch, ,] = args;

const { operation, object } = params;
const { operation, object, directoryPath } = params;

const operationId = `${operation}-${Date.now()}`;

dispatch(actions.operationStarted({ operationId, object, operation }));

await dispatch(
privateThunks.waitForNoOngoingOperation({
"kind": object.kind,
directoryPath,
"basename": object.basename,
"ignoreOperationId": operationId
})
);
return operationId;
},
"waitForNoOngoingOperation":
(params: {
kind: "file" | "directory";
basename: string;
directoryPath: string;
ignoreOperationId?: string;
}) =>
async (...args) => {
const [, getState, { evtAction }] = args;

const { kind, basename, directoryPath } = params;
const { kind, basename, directoryPath, ignoreOperationId } = params;

const { ongoingOperations } = getState()[name];

const ongoingOperation = ongoingOperations.find(
o =>
o.object.kind === kind &&
o.object.basename === basename &&
o.directoryPath === directoryPath
o.directoryPath === directoryPath &&
o.operationId !== ignoreOperationId
);

if (ongoingOperation === undefined) {
Expand Down Expand Up @@ -257,16 +272,20 @@ export const thunks = {

const [dispatch, getState] = args;

const object = getState()[name].objects.find(
o => o.basename === basename && o.kind === kind
);
const state = getState()[name];

const { directoryPath, objects } = state;

const object = objects.find(o => o.basename === basename && o.kind === kind);

assert(object !== undefined);
assert(directoryPath !== undefined);

const operationId = await dispatch(
privateThunks.createOperation({
operation: "modifyPolicy",
object: { ...object, policy }
object: { ...object, policy },
directoryPath
})
);
const s3Client = await dispatch(
Expand All @@ -276,10 +295,6 @@ export const thunks = {
return r.s3Client;
});

const { directoryPath } = getState()[name];

assert(directoryPath !== undefined);

const filePath = pathJoin(directoryPath, basename);
const s3Prefix = pathJoin("s3", filePath);

Expand Down Expand Up @@ -358,14 +373,6 @@ export const thunks = {

assert(directoryPath !== undefined);

await dispatch(
privateThunks.waitForNoOngoingOperation({
"kind": params.createWhat,
directoryPath,
"basename": params.basename
})
);

const operationId = await dispatch(
privateThunks.createOperation({
object: {
Expand All @@ -375,6 +382,7 @@ export const thunks = {
size: undefined,
lastModified: undefined
},
directoryPath,
operation: "create"
})
);
Expand Down Expand Up @@ -498,16 +506,12 @@ export const thunks = {

assert(directoryPath !== undefined);

await dispatch(
privateThunks.waitForNoOngoingOperation({
"kind": s3Object.kind,
directoryPath,
basename: s3Object.basename
})
);

const operationId = await dispatch(
privateThunks.createOperation({ operation: "delete", object: s3Object })
privateThunks.createOperation({
operation: "delete",
object: s3Object,
directoryPath
})
);

const s3Client = await dispatch(
Expand Down Expand Up @@ -542,13 +546,17 @@ export const thunks = {
{
const { crawl } = crawlFactory({
"list": async ({ directoryPath }) => {
const { directories, files } = await s3Client.list({
const { objects } = await s3Client.listObjects({
"path": directoryPath
});

return {
"fileBasenames": files,
"directoryBasenames": directories
"fileBasenames": objects
.filter(object => object.kind === "file")
.map(object => object.basename),
"directoryBasenames": objects
.filter(object => object.kind === "directory")
.map(object => object.basename)
};
}
});
Expand Down
6 changes: 5 additions & 1 deletion web/src/ui/pages/myFiles/Explorer/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ export const Explorer = memo((props: ExplorerProps) => {
);

const itemsOnDeleteItem = useConstCallback(
async ({ item }: Parameters<ItemsProps["onDeleteItem"]>[0]) => {
async (
{ item }: Parameters<ItemsProps["onDeleteItem"]>[0],
onDeleteConfirmed?: () => void // Callback optionnelle pour après la suppression
) => {
if (doShowDeletionDialogNextTime) {
const dDoProceedToDeletion = new Deferred();

Expand All @@ -269,6 +272,7 @@ export const Explorer = memo((props: ExplorerProps) => {
}

onDeleteItem({ item });
onDeleteConfirmed?.();
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export const FileSelected: Story = {
policy: "private",
className: css({ "width": "160px", "height": "160px" }),
isSelected: true,
isCircularProgressShown: false, // Valeur par défaut pour l'animation
isPolicyChanging: false, // Pas de changement de politique en cours
onPolicyChange: action("onPolicyChange"), // Action pour les changements de politique
onClick: action("onClick"),
onDoubleClick: action("onDoubleClick")
}
Expand All @@ -30,9 +33,12 @@ export const DirectoryUnselected: Story = {
kind: "directory",
basename: "example-directory",
size: undefined,
"policy": "public",
policy: "public",
className: css({ "width": "160px", "height": "160px" }),
isSelected: false,
isCircularProgressShown: false, // Valeur par défaut pour l'animation
isPolicyChanging: false, // Pas de changement de politique en cours
onPolicyChange: action("onPolicyChange"), // Action pour les changements de politique
onClick: action("onClick"),
onDoubleClick: action("onDoubleClick")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tss } from "tss";
import { Text } from "onyxia-ui/Text";
import { memo, useState } from "react";
import { memo } from "react";
import { Icon } from "onyxia-ui/Icon";
import { MuiIconComponentName } from "onyxia-ui/MuiIconComponentName";
import { id } from "tsafe";
Expand All @@ -24,6 +24,7 @@ export type ExplorerItemProps = {
isSelected: boolean;

isCircularProgressShown: boolean;
isPolicyChanging: boolean;

/** File size in bytes */
size: number | undefined;
Expand All @@ -44,7 +45,8 @@ export const ExplorerItem = memo((props: ExplorerItemProps) => {
size,
onDoubleClick,
onPolicyChange,
onClick
onClick,
isPolicyChanging
} = props;

const prettySize = size ? fileSizePrettyPrint({ bytes: size }) : null;
Expand Down Expand Up @@ -99,6 +101,7 @@ export const ExplorerItem = memo((props: ExplorerItemProps) => {
policy={policy}
className={classes.policyIcon}
changePolicy={onPolicyChange}
isPolicyChanging={isPolicyChanging}
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,54 @@ export default meta;

type Story = StoryObj<typeof meta>;

const itemsSample = [
const itemsSample: Item[] = [
{
kind: "file",
basename: "document.pdf",
size: 1024000, // in bytes
size: 1024000, // en bytes
lastModified: new Date("2023-10-01"),
policy: "private"
policy: "private",
isBeingUploaded: false,
isBeingDeleted: false,
isPolicyChanging: false
},
{
kind: "file",
basename: "photo.png",
size: 2048000, // in bytes
size: 2048000, // en bytes
lastModified: new Date("2023-09-15"),
policy: "public"
policy: "public",
isBeingUploaded: false,
isBeingDeleted: false,
isPolicyChanging: false
},
{
kind: "directory",
basename: "Projects",
policy: "private"
policy: "private",
isBeingUploaded: false,
isBeingDeleted: false,
isPolicyChanging: false
},
{
kind: "file",
basename: "presentation.pptx",
size: 5120000, // in bytes
size: 5120000, // en bytes
lastModified: new Date("2023-09-20"),
policy: "private"
policy: "private",
isBeingUploaded: false,
isBeingDeleted: false,
isPolicyChanging: false
},
{
kind: "directory",
basename: "Photos",
policy: "public"
policy: "public",
isBeingUploaded: false,
isBeingDeleted: false,
isPolicyChanging: false
}
] satisfies Item[];
];

export const Default: Story = {
args: {
Expand All @@ -56,6 +71,7 @@ export const Default: Story = {
onDeleteItem: action("Delete item"),
onCopyPath: action("Copy path"),
onSelectedItemKindValueChange: action("Selected item kind changed"),
onPolicyChange: action("Policy change"),
evtAction: Evt.create<"DELETE SELECTED ITEM" | "COPY SELECTED ITEM PATH">()
}
};
Expand All @@ -68,6 +84,7 @@ export const EmptyDirectory: Story = {
onOpenFile: action("Open file"),
onDeleteItem: action("Delete item"),
onCopyPath: action("Copy path"),
onPolicyChange: action("Policy change"),
onSelectedItemKindValueChange: action("Selected item kind changed"),
evtAction: Evt.create<"DELETE SELECTED ITEM" | "COPY SELECTED ITEM PATH">()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ export const ExplorerItems = memo((props: ExplorerItemsProps) => {
onClick={handleItemClick(item)}
onDoubleClick={handleItemDoubleClick(item)}
isCircularProgressShown={
isBeingDeleted || isBeingUploaded || isPolicyChanging
isBeingDeleted || isBeingUploaded
}
isPolicyChanging={isPolicyChanging}
/>
);
})}
Expand Down
Loading

0 comments on commit 6e1ef87

Please sign in to comment.