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 1 commit
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
Prev Previous commit
Next Next commit
refactor: pass type as repo dependency
  • Loading branch information
leopuleo committed Oct 17, 2024
commit 11f093ed580394d8f7347cfd7b045c93f83b35c6
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { FolderDto } from "./FolderDto";
export class CreateFolderRepository implements ICreateFolderRepository {
private cache: FoldersCache;
private gateway: ICreateFolderGateway;
private type: string;

constructor(cache: FoldersCache, gateway: ICreateFolderGateway) {
constructor(cache: FoldersCache, gateway: ICreateFolderGateway, type: string) {
this.cache = cache;
this.gateway = gateway;
this.type = type;
makeAutoObservable(this);
}

Expand All @@ -20,7 +22,7 @@ export class CreateFolderRepository implements ICreateFolderRepository {
title: folder.title,
slug: folder.slug,
permissions: folder.permissions,
type: folder.type,
type: this.type,
parentId: folder.parentId
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const useCreateFolder = (cache: FoldersCache, loading: LoadingRepository,
}, [client]);

const repository = useMemo(() => {
return new CreateFolderRepository(cache, gateway);
}, [cache, gateway]);
return new CreateFolderRepository(cache, gateway, type);
}, [cache, gateway, type]);

const useCase = useMemo(() => {
const createFolderUseCase = new CreateFolderUseCase(repository);
Expand All @@ -26,7 +26,7 @@ export const useCreateFolder = (cache: FoldersCache, loading: LoadingRepository,

const createFolder = useCallback(
(params: CreateFolderParams) => {
return useCase.execute({ ...params, type });
return useCase.execute(params);
},
[useCase]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DeleteFolderUseCase } from "./DeleteFolderUseCase";
import { DeleteFolderUseCaseWithLoading } from "./DeleteFolderUseCaseWithLoading";
import { DeleteFolderParams } from "./IDeleteFolderUseCase";

export const useDeleteFolder = (cache: FoldersCache, loading: LoadingRepository, type: string) => {
export const useDeleteFolder = (cache: FoldersCache, loading: LoadingRepository) => {
const client = useApolloClient();

const gateway = useMemo(() => {
Expand All @@ -26,7 +26,7 @@ export const useDeleteFolder = (cache: FoldersCache, loading: LoadingRepository,

const deleteFolder = useCallback(
(params: DeleteFolderParams) => {
return useCase.execute({ ...params, type });
return useCase.execute(params);
},
[useCase]
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface IListFoldersRepository {
execute: (type: string) => Promise<void>;
execute: () => Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
export interface ListFoldersParams {
type: string;
}

export interface IListFoldersUseCase {
execute: (params: ListFoldersParams) => Promise<void>;
execute: () => Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import { IListFoldersRepository } from "./IListFoldersRepository";
export class ListFoldersRepository implements IListFoldersRepository {
private cache: FoldersCache;
private gateway: IListFoldersGateway;
private type: string;

constructor(cache: FoldersCache, gateway: IListFoldersGateway) {
constructor(cache: FoldersCache, gateway: IListFoldersGateway, type: string) {
this.cache = cache;
this.gateway = gateway;
this.type = type;
makeAutoObservable(this);
}

async execute(type: string) {
const items = await this.gateway.execute(type);
async execute() {
const items = await this.gateway.execute(this.type);
await this.cache.setMultiple(items.map(item => Folder.create(item)));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IListFoldersUseCase, ListFoldersParams } from "./IListFoldersUseCase";
import { IListFoldersUseCase } from "./IListFoldersUseCase";
import { IListFoldersRepository } from "./IListFoldersRepository";

export class ListFoldersUseCase implements IListFoldersUseCase {
Expand All @@ -8,7 +8,7 @@ export class ListFoldersUseCase implements IListFoldersUseCase {
this.repository = repository;
}

async execute(params: ListFoldersParams) {
await this.repository.execute(params.type);
async execute() {
await this.repository.execute();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ILoadingRepository } from "@webiny/app-utils";
import { LoadingActionsEnum } from "~/types";
import { IListFoldersUseCase, ListFoldersParams } from "./IListFoldersUseCase";
import { IListFoldersUseCase } from "./IListFoldersUseCase";

export class ListFoldersUseCaseWithLoading implements IListFoldersUseCase {
private loadingRepository: ILoadingRepository;
Expand All @@ -11,10 +11,7 @@ export class ListFoldersUseCaseWithLoading implements IListFoldersUseCase {
this.useCase = useCase;
}

async execute(params: ListFoldersParams) {
await this.loadingRepository.runCallBack(
this.useCase.execute(params),
LoadingActionsEnum.list
);
async execute() {
await this.loadingRepository.runCallBack(this.useCase.execute(), LoadingActionsEnum.list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ export const useListFolders = (cache: FoldersCache, loading: LoadingRepository,
}, [client]);

const repository = useMemo(() => {
return new ListFoldersRepository(cache, gateway);
}, [cache, gateway]);
return new ListFoldersRepository(cache, gateway, type);
}, [cache, gateway, type]);

const useCase = useMemo(() => {
const listFolderUseCase = new ListFoldersUseCase(repository);
return new ListFoldersUseCaseWithLoading(loading, listFolderUseCase);
}, [repository, loading]);

const listFolders = useCallback(() => {
return useCase.execute({ type });
return useCase.execute();
}, [useCase]);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UpdateFolderUseCase } from "./UpdateFolderUseCase";
import { UpdateFolderUseCaseWithLoading } from "./UpdateFolderUseCaseWithLoading";
import { UpdateFolderParams } from "./IUpdateFolderUseCase";

export const useUpdateFolder = (cache: FoldersCache, loading: LoadingRepository, type: string) => {
export const useUpdateFolder = (cache: FoldersCache, loading: LoadingRepository) => {
const client = useApolloClient();

const gateway = useMemo(() => {
Expand All @@ -26,7 +26,7 @@ export const useUpdateFolder = (cache: FoldersCache, loading: LoadingRepository,

const updateFolder = useCallback(
(params: UpdateFolderParams) => {
return useCase.execute({ ...params, type });
return useCase.execute(params);
},
[useCase]
);
Expand Down
4 changes: 2 additions & 2 deletions packages/app-aco/src/hooks/useFolders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export const useFolders = () => {
}, [type]);

const { createFolder } = useCreateFolder(foldersCache, loadingRepository, type);
const { deleteFolder } = useDeleteFolder(foldersCache, loadingRepository, type);
const { deleteFolder } = useDeleteFolder(foldersCache, loadingRepository);
const { listFolders } = useListFolders(foldersCache, loadingRepository, type);
const { updateFolder } = useUpdateFolder(foldersCache, loadingRepository, type);
const { updateFolder } = useUpdateFolder(foldersCache, loadingRepository);
const { getDescendantFolders } = useGetDescendantFolders(foldersCache);
const { getFolder } = useGetFolder(foldersCache, loadingRepository);

Expand Down