Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: folders FTA #4345

Draft
wants to merge 36 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
65f7c3f
refactor(app-aco): use FTA in app-aco - folder entity
leopuleo Jun 24, 2024
f30304a
refactor(app-aco): use FTA in app-aco - folder entity
leopuleo Jun 25, 2024
0702593
Merge branch 'refs/heads/next' into leo/refactor/app-aco-fta
leopuleo Aug 15, 2024
ea0e4d5
refactor(app-aco): implement useCase and controller layers
leopuleo Aug 27, 2024
ce1bfe2
refactor(app-aco): implement presenter
leopuleo Aug 27, 2024
a5be5e1
refactor(app-aco): add loading use case decoration
leopuleo Aug 27, 2024
2370f07
refactor(app-aco): move Graphql interface to gateway
leopuleo Aug 27, 2024
bf1e730
chore: wip
leopuleo Sep 18, 2024
9851745
Merge branch 'next' into leo/refactor/app-aco-fta
leopuleo Oct 15, 2024
171d1ad
wip: folders FTA
leopuleo Oct 17, 2024
292441e
wip: retrieve data from gateway
leopuleo Oct 17, 2024
d87bf4f
fix: loading folders
leopuleo Oct 17, 2024
f155108
fix: move folderLevelPermissions into new hook
leopuleo Oct 17, 2024
11f093e
refactor: pass type as repo dependency
leopuleo Oct 17, 2024
7309428
refactor: flp FTA
leopuleo Oct 17, 2024
4ee8d25
fix: revert the folder tree state in case of error on drop
leopuleo Oct 18, 2024
295039a
fix: remove previous implementation files
leopuleo Oct 18, 2024
c6c467c
feat: move vm into listFolders
leopuleo Oct 18, 2024
ba5011d
refactor: create separate folders useCases
leopuleo Oct 19, 2024
22bd689
wip: create instance class
leopuleo Oct 21, 2024
1b8b210
refactor: introduce GetFolderLevelPermission feature
leopuleo Oct 21, 2024
0c5b524
refactor: introduce GetFolderLevelPermission feature
leopuleo Oct 21, 2024
603aa5e
refactor: add loading namespace
leopuleo Oct 21, 2024
581ab8e
Merge branch 'next' into leo/refactor/app-aco-fta
leopuleo Oct 21, 2024
22c5c9c
chore: run adio
leopuleo Oct 21, 2024
a478e6f
Merge branch 'next' into leo/refactor/app-aco-fta
leopuleo Nov 8, 2024
9cd7c33
Merge branch 'next' into leo/refactor/app-aco-fta
leopuleo Nov 12, 2024
d5b66bf
Merge branch 'next' into leo/refactor/app-aco-fta
leopuleo Nov 18, 2024
a885839
Merge remote-tracking branch 'origin/leo/refactor/app-aco-fta' into l…
leopuleo Jan 9, 2025
7e63836
refactor: replace FolderCache with generic ListCache
leopuleo Jan 9, 2025
b963e3a
refactor: remove unused makeAutoObservable
leopuleo Jan 9, 2025
c04bfea
test: add tests
leopuleo Jan 10, 2025
b3770d1
refactor: remove useFolders
leopuleo Jan 10, 2025
12f2b8b
Merge branch 'next' into leo/refactor/app-aco-fta
leopuleo Jan 10, 2025
226af4d
fix: omit all inherited permissions
leopuleo Jan 10, 2025
40a483d
refactor: add listing params
leopuleo Jan 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/app-aco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@webiny/app-admin": "0.0.0",
"@webiny/app-headless-cms-common": "0.0.0",
"@webiny/app-security": "0.0.0",
"@webiny/app-utils": "0.0.0",
"@webiny/app-wcp": "0.0.0",
"@webiny/form": "0.0.0",
"@webiny/plugins": "0.0.0",
Expand Down
21 changes: 0 additions & 21 deletions packages/app-aco/src/Folders.tsx

This file was deleted.

21 changes: 10 additions & 11 deletions packages/app-aco/src/components/FolderTree/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Node } from "../Node";
import { NodePreview } from "../NodePreview";
import { Placeholder } from "../Placeholder";
import { createInitialOpenList, createTreeData } from "./utils";
import { useFolders } from "~/hooks";
import { useGetFolderLevelPermission, useUpdateFolder } from "~/features";
import { ROOT_FOLDER } from "~/constants";
import { DndFolderItemData, FolderItem } from "~/types";
import { FolderProvider } from "~/contexts/folder";
Expand All @@ -33,7 +33,9 @@ export const List = ({
hiddenFolderIds,
enableActions
}: ListProps) => {
const { updateFolder, folderLevelPermissions: flp } = useFolders();
const { updateFolder } = useUpdateFolder();
const { getFolderLevelPermission: canManageStructure } =
useGetFolderLevelPermission("canManageStructure");
const { showSnackbar } = useSnackbar();
const [treeData, setTreeData] = useState<NodeModel<DndFolderItemData>[]>([]);
const [initialOpenList, setInitialOpenList] = useState<undefined | InitialOpen>();
Expand Down Expand Up @@ -67,13 +69,10 @@ export const List = ({

setTreeData(newTree);

await updateFolder(
{
...item,
parentId: dropTargetId !== ROOT_FOLDER ? (dropTargetId as string) : null
},
{ refetchFoldersList: true }
);
await updateFolder({
...item,
parentId: dropTargetId !== ROOT_FOLDER ? (dropTargetId as string) : null
});
} catch (error) {
// If an error occurred, revert the tree back to its previous state
setTreeData(oldTree);
Expand All @@ -98,9 +97,9 @@ export const List = ({
const canDrag = useCallback(
(folderId: string) => {
const isRootFolder = folderId === ROOT_FOLDER;
return !isRootFolder && flp.canManageStructure(folderId);
return !isRootFolder && canManageStructure(folderId);
},
[flp.canManageStructure]
[canManageStructure]
);

return (
Expand Down
6 changes: 3 additions & 3 deletions packages/app-aco/src/components/FolderTree/List/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { DndFolderItemData, FolderItem } from "~/types";
import { ROOT_FOLDER } from "~/constants";

/**
* Transform an array of folders returned by useFolders hook into an array of elements for the tree component.
* Transform an array of folders returned by folders cache into an array of elements for the tree component.
*
* @param folders list of folders returned by useFolders hook.
* @param folders list of folders returned by folders cache.
* @param focusedNodeId id of the current folder selected/focused.
* @param hiddenFolderIds list ids of the folder you don't want to show within the list.
* @return array of elements to render the tree component.
Expand Down Expand Up @@ -37,7 +37,7 @@ export const createTreeData = (
* Return an array of ids of open folders, based on the current focused folder id, its parent folders and the folders
* opened by user interaction.
*
* @param folders list of folders returned by useFolders hook.
* @param folders list of folders returned by folders cache.
* @param openIds list of open folders ids.
* @param focusedId id of the current folder selected/focused.
* @return array of ids of open folders.
Expand Down
11 changes: 7 additions & 4 deletions packages/app-aco/src/components/FolderTree/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo } from "react";
import { Tooltip } from "@webiny/ui/Tooltip";
import { useFolders } from "~/hooks/useFolders";
import { useGetFolderLevelPermission, useListFolders } from "~/features";
import { CreateButton } from "./ButtonCreate";
import { Empty } from "./Empty";
import { Loader } from "./Loader";
Expand Down Expand Up @@ -29,7 +29,10 @@ export const FolderTree = ({
onFolderClick,
rootFolderLabel
}: FolderTreeProps) => {
const { folders, folderLevelPermissions: flp } = useFolders();
const { loading, folders } = useListFolders();
const { getFolderLevelPermission: canManageStructure } =
useGetFolderLevelPermission("canManageStructure");

const localFolders = useMemo(() => {
if (!folders) {
return [];
Expand All @@ -44,13 +47,13 @@ export const FolderTree = ({
}, [folders]);

const renderList = () => {
if (!folders) {
if (loading.INIT || loading.LIST) {
return <Loader />;
}

let createButton = null;
if (enableCreate) {
const canCreate = flp.canManageStructure(focusedFolderId!);
const canCreate = canManageStructure(focusedFolderId!);

createButton = <CreateButton disabled={!canCreate} />;

Expand Down
Loading
Loading