// SPDX-License-Identifier: AGPL-3.0
import { Dispatch } from 'redux';
-import { treePickerActions } from "~/store/tree-picker/tree-picker-actions";
-import { RootState } from '~/store/store';
-import { getUserUuid } from "~/common/getuser";
-import { ServiceRepository } from '~/services/services';
-import { FilterBuilder } from '~/services/api/filter-builder';
-import { resourcesActions } from '~/store/resources/resources-actions';
-import { getTreePicker, TreePicker } from '~/store/tree-picker/tree-picker';
-import { getNodeAncestors, getNodeAncestorsIds, getNode, TreeNode, initTreeNode, TreeNodeStatus } from '~/models/tree';
-import { ProjectResource } from '~/models/project';
-import { OrderBuilder } from '~/services/api/order-builder';
-import { ResourceKind } from '~/models/resource';
-import { GroupContentsResourcePrefix } from '~/services/groups-service/groups-service';
-import { GroupClass } from '~/models/group';
+import { treePickerActions } from "store/tree-picker/tree-picker-actions";
+import { RootState } from 'store/store';
+import { getUserUuid } from "common/getuser";
+import { ServiceRepository } from 'services/services';
+import { FilterBuilder } from 'services/api/filter-builder';
+import { resourcesActions } from 'store/resources/resources-actions';
+import { getTreePicker, TreePicker } from 'store/tree-picker/tree-picker';
+import { getNodeAncestors, getNodeAncestorsIds, getNode, TreeNode, initTreeNode, TreeNodeStatus } from 'models/tree';
+import { ProjectResource } from 'models/project';
+import { OrderBuilder } from 'services/api/order-builder';
+import { ResourceKind } from 'models/resource';
+import { CategoriesListReducer } from 'common/plugintypes';
+import { pluginConfig } from 'plugins';
+import { LinkClass } from 'models/link';
export enum SidePanelTreeCategory {
- PROJECTS = 'Projects',
+ PROJECTS = 'Home Projects',
SHARED_WITH_ME = 'Shared with me',
PUBLIC_FAVORITES = 'Public Favorites',
- WORKFLOWS = 'Workflows',
- FAVORITES = 'Favorites',
+ FAVORITES = 'My Favorites',
TRASH = 'Trash',
- ALL_PROCESSES = 'All Processes'
+ ALL_PROCESSES = 'All Processes',
+ GROUPS = 'Groups',
}
export const SIDE_PANEL_TREE = 'sidePanelTree';
+const TREE_NODE_LIMIT = 50
export const getSidePanelTree = (treePicker: TreePicker) =>
getTreePicker<ProjectResource | string>(SIDE_PANEL_TREE)(treePicker);
return [];
};
-const SIDE_PANEL_CATEGORIES = [
- SidePanelTreeCategory.ALL_PROCESSES,
+let SIDE_PANEL_CATEGORIES: string[] = [
+ SidePanelTreeCategory.PROJECTS,
+ SidePanelTreeCategory.SHARED_WITH_ME,
SidePanelTreeCategory.PUBLIC_FAVORITES,
- SidePanelTreeCategory.WORKFLOWS,
SidePanelTreeCategory.FAVORITES,
- SidePanelTreeCategory.TRASH,
+ SidePanelTreeCategory.GROUPS,
+ SidePanelTreeCategory.ALL_PROCESSES,
+ SidePanelTreeCategory.TRASH
];
+const reduceCatsFn: (a: string[],
+ b: CategoriesListReducer) => string[] = (a, b) => b(a);
+
+SIDE_PANEL_CATEGORIES = pluginConfig.sidePanelCategories.reduce(reduceCatsFn, SIDE_PANEL_CATEGORIES);
+
export const isSidePanelTreeCategory = (id: string) => SIDE_PANEL_CATEGORIES.some(category => category === id);
+
export const initSidePanelTree = () =>
(dispatch: Dispatch, getState: () => RootState, { authService }: ServiceRepository) => {
const rootProjectUuid = getUserUuid(getState());
if (!rootProjectUuid) { return; }
- const nodes = SIDE_PANEL_CATEGORIES.map(id => initTreeNode({ id, value: id }));
- const projectsNode = initTreeNode({ id: rootProjectUuid, value: SidePanelTreeCategory.PROJECTS });
- const sharedNode = initTreeNode({ id: SidePanelTreeCategory.SHARED_WITH_ME, value: SidePanelTreeCategory.SHARED_WITH_ME });
+ const nodes = SIDE_PANEL_CATEGORIES.map(id => {
+ if (id === SidePanelTreeCategory.PROJECTS) {
+ return initTreeNode({ id: rootProjectUuid, value: SidePanelTreeCategory.PROJECTS });
+ } else {
+ return initTreeNode({ id, value: id });
+ }
+ });
dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({
id: '',
pickerId: SIDE_PANEL_TREE,
- nodes: [projectsNode, sharedNode, ...nodes]
+ nodes
}));
SIDE_PANEL_CATEGORIES.forEach(category => {
- dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({
- id: category,
- pickerId: SIDE_PANEL_TREE,
- nodes: []
- }));
+ if (category !== SidePanelTreeCategory.PROJECTS && category !== SidePanelTreeCategory.FAVORITES && category !== SidePanelTreeCategory.PUBLIC_FAVORITES ) {
+ dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({
+ id: category,
+ pickerId: SIDE_PANEL_TREE,
+ nodes: []
+ }));
+ }
});
};
async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
const treePicker = getTreePicker(SIDE_PANEL_TREE)(getState().treePicker);
const node = treePicker ? getNode(projectUuid)(treePicker) : undefined;
- if (projectUuid === SidePanelTreeCategory.SHARED_WITH_ME) {
- await dispatch<any>(loadSharedRoot);
- } else if (node || projectUuid === '') {
+ if (projectUuid === SidePanelTreeCategory.PUBLIC_FAVORITES) {
+ await dispatch<any>(loadPublicFavorites);
+ } else if (projectUuid === SidePanelTreeCategory.FAVORITES) {
+ await dispatch<any>(loadFavorites);
+ } else if (node || projectUuid !== '') {
await dispatch<any>(loadProject(projectUuid));
}
};
dispatch(resourcesActions.SET_RESOURCES(items));
};
-const loadSharedRoot = async (dispatch: Dispatch, _: () => RootState, services: ServiceRepository) => {
- dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: SidePanelTreeCategory.SHARED_WITH_ME, pickerId: SIDE_PANEL_TREE }));
+const loadFavorites = async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: SidePanelTreeCategory.FAVORITES, pickerId: SIDE_PANEL_TREE }));
+
+ const params = {
+ filters: new FilterBuilder()
+ .addEqual("link_class", LinkClass.STAR)
+ .addEqual('tail_uuid', getUserUuid(getState()))
+ .addEqual('tail_kind', ResourceKind.USER)
+ .getFilters(),
+ order: new OrderBuilder<ProjectResource>()
+ .addDesc('createdAt')
+ .getOrder(),
+ limit: 50
+ }
+
+ const { items } = await services.linkService.list(params);
+
+ dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({
+ id: SidePanelTreeCategory.FAVORITES,
+ pickerId: SIDE_PANEL_TREE,
+ nodes: items.map(item => initTreeNode({ id: item.headUuid, value: item })),
+ }));
+
+ dispatch(resourcesActions.SET_RESOURCES(items));
+};
+
+const loadPublicFavorites = async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: SidePanelTreeCategory.PUBLIC_FAVORITES, pickerId: SIDE_PANEL_TREE }));
+
+ const uuidPrefix = getState().auth.config.uuidPrefix;
+ const publicProjectUuid = `${uuidPrefix}-j7d0g-publicfavorites`;
+ const typeFilters = [ResourceKind.COLLECTION, ResourceKind.CONTAINER_REQUEST, ResourceKind.GROUP, ResourceKind.WORKFLOW];
const params = {
- filters: `[${new FilterBuilder()
- .addIsA('uuid', ResourceKind.PROJECT)
- .addEqual('group_class', GroupClass.PROJECT)
- .getFilters()}]`,
+ filters: new FilterBuilder()
+ .addEqual('link_class', LinkClass.STAR)
+ .addEqual('owner_uuid', publicProjectUuid)
+ .addIsA('head_uuid', typeFilters)
+ .getFilters(),
order: new OrderBuilder<ProjectResource>()
- .addAsc('name', GroupContentsResourcePrefix.PROJECT)
+ .addDesc('createdAt')
.getOrder(),
- limit: 1000
+ limit: TREE_NODE_LIMIT
};
- const { items } = await services.groupsService.shared(params);
+ const { items } = await services.linkService.list(params);
+ console.log(items)
dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({
- id: SidePanelTreeCategory.SHARED_WITH_ME,
+ id: SidePanelTreeCategory.PUBLIC_FAVORITES,
pickerId: SIDE_PANEL_TREE,
- nodes: items.map(item => initTreeNode({ id: item.uuid, value: item })),
+ nodes: items.map(item => initTreeNode({ id: item.headUuid, value: item })),
}));
dispatch(resourcesActions.SET_RESOURCES(items));
export const activateSidePanelTreeItem = (id: string) =>
async (dispatch: Dispatch, getState: () => RootState) => {
const node = getSidePanelTreeNode(id)(getState().treePicker);
+ console.log(id)
if (node && !node.active) {
dispatch(treePickerActions.ACTIVATE_TREE_PICKER_NODE({ id, pickerId: SIDE_PANEL_TREE }));
}
const userUuid = getUserUuid(getState());
if (!userUuid) { return; }
const ancestors = await services.ancestorsService.ancestors(id, userUuid);
- const isShared = ancestors.every(({ uuid }) => uuid !== userUuid);
- if (isShared) {
- await dispatch<any>(loadSidePanelTreeProjects(SidePanelTreeCategory.SHARED_WITH_ME));
- }
for (const ancestor of ancestors) {
await dispatch<any>(loadSidePanelTreeProjects(ancestor.uuid));
}
dispatch(treePickerActions.EXPAND_TREE_PICKER_NODES({
- ids: [
- ...(isShared ? [SidePanelTreeCategory.SHARED_WITH_ME] : []),
- ...ancestors.map(ancestor => ancestor.uuid)
- ],
+ ids: ancestors.map(ancestor => ancestor.uuid),
pickerId: SIDE_PANEL_TREE
}));
dispatch(treePickerActions.ACTIVATE_TREE_PICKER_NODE({ id, pickerId: SIDE_PANEL_TREE }));