import { ContextMenuPosition, ContextMenuResource } from "./context-menu-reducer";
import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
import { Dispatch } from 'redux';
+import { RootState } from '~/store/store';
+import { getResource } from '../resources/resources';
+import { ProjectResource } from '~/models/project';
+import { UserResource } from '../../models/user';
+import { isSidePanelTreeCategory } from '~/store/side-panel-tree/side-panel-tree-actions';
+import { extractUuidKind, ResourceKind } from '~/models/resource';
export const contextMenuActions = unionize({
OPEN_CONTEXT_MENU: ofType<{ position: ContextMenuPosition, resource: ContextMenuResource }>(),
resource
})
);
- };
\ No newline at end of file
+ };
+
+export const openRootProjectContextMenu = (event: React.MouseEvent<HTMLElement>, projectUuid: string) =>
+ (dispatch: Dispatch, getState: () => RootState) => {
+ const userResource = getResource<UserResource>(projectUuid)(getState().resources);
+ if (userResource) {
+ dispatch<any>(openContextMenu(event, {
+ name: '',
+ uuid: userResource.uuid,
+ kind: ContextMenuKind.ROOT_PROJECT
+ }));
+ }
+ };
+
+export const openProjectContextMenu = (event: React.MouseEvent<HTMLElement>, projectUuid: string) =>
+ (dispatch: Dispatch, getState: () => RootState) => {
+ const projectResource = getResource<ProjectResource>(projectUuid)(getState().resources);
+ if (projectResource) {
+ dispatch<any>(openContextMenu(event, {
+ name: projectResource.name,
+ uuid: projectResource.uuid,
+ kind: ContextMenuKind.PROJECT
+ }));
+ }
+ };
+
+export const openSidePanelContextMenu = (event: React.MouseEvent<HTMLElement>, id: string) =>
+ (dispatch: Dispatch, getState: () => RootState) => {
+ if (!isSidePanelTreeCategory(id)) {
+ const kind = extractUuidKind(id);
+ if (kind === ResourceKind.USER) {
+ dispatch<any>(openRootProjectContextMenu(event, id));
+ } else if (kind === ResourceKind.PROJECT) {
+ dispatch<any>(openProjectContextMenu(event, id));
+ }
+ }
+ };
export type ResourcesState = { [key: string]: Resource };
-export const getResource = <T extends Resource>(id: string) =>
- (state: ResourcesState): Resource | undefined =>
- state[id];
+export const getResource = <T extends Resource = Resource>(id: string) =>
+ (state: ResourcesState): T | undefined =>
+ state[id] as T;
export const setResource = <T extends Resource>(id: string, data: T) =>
(state: ResourcesState) => ({
import { isSidePanelTreeCategory, SidePanelTreeCategory } from '~/store/side-panel-tree/side-panel-tree-actions';
import { navigateToFavorites, navigateTo } from '../navigation/navigation-action';
import { snackbarActions } from '~/store/snackbar/snackbar-actions';
+import { RootState } from '~/store/store';
+import { extractUuidKind, ResourceKind } from '~/models/resource';
+import { openProjectContextMenu } from '~/store/context-menu/context-menu-actions';
+import { openRootProjectContextMenu } from '../context-menu/context-menu-actions';
export const navigateFromSidePanel = (id: string) =>
(dispatch: Dispatch) => {
export const snackbarReducer = (state = initialState, action: SnackbarAction) => {
return snackbarActions.match(action, {
- OPEN_SNACKBAR: data => ({ ...data, open: true }),
+ OPEN_SNACKBAR: data => ({ ...initialState, ...data, open: true }),
CLOSE_SNACKBAR: () => initialState,
default: () => state,
});
import { navigateTo } from '~/store/navigation/navigation-action';
import { getProperty } from '../../store/properties/properties';
import { ResourceBreadcrumb, BREADCRUMBS } from '../../store/breadcrumbs/breadcrumbs-actions';
-
-
+import { openSidePanelContextMenu } from '~/store/context-menu/context-menu-actions';
type BreadcrumbsDataProps = Pick<BreadcrumbsProps, 'items'>;
type BreadcrumbsActionProps = Pick<BreadcrumbsProps, 'onClick' | 'onContextMenu'>;
onClick: ({ uuid }: ResourceBreadcrumb) => {
dispatch<any>(navigateTo(uuid));
},
- onContextMenu: () => { return; }
+ onContextMenu: (event, breadcrumb: ResourceBreadcrumb) => {
+ dispatch<any>(openSidePanelContextMenu(event, breadcrumb.uuid));
+ }
});
export const Breadcrumbs = connect(mapStateToProps(), mapDispatchToProps)(BreadcrumbsComponent);
\ No newline at end of file
import { ServiceRepository } from "~/services/services";
import { FilterBuilder } from "~/common/api/filter-builder";
-type ProjectTreePickerProps = Pick<TreePickerProps, 'toggleItemActive' | 'toggleItemOpen'>;
+type ProjectTreePickerProps = Pick<TreePickerProps, 'onContextMenu' | 'toggleItemActive' | 'toggleItemOpen'>;
const mapDispatchToProps = (dispatch: Dispatch, props: { onChange: (projectUuid: string) => void }): ProjectTreePickerProps => ({
+ onContextMenu: () => { return; },
toggleItemActive: (nodeId, status, pickerId) => {
getNotSelectedTreePickerKind(pickerId)
.forEach(pickerId => dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ nodeId: '', pickerId })));
import { ProjectIcon, FavoriteIcon, ProjectsIcon, ShareMeIcon, TrashIcon } from '~/components/icon/icon';
import { RecentIcon, WorkflowIcon } from '~/components/icon/icon';
import { activateSidePanelTreeItem, toggleSidePanelTreeItemCollapse, SIDE_PANEL_TREE, SidePanelTreeCategory } from '~/store/side-panel-tree/side-panel-tree-actions';
+import { openSidePanelContextMenu } from '~/store/context-menu/context-menu-actions';
export interface SidePanelTreeProps {
onItemActivation: (id: string) => void;
}
-type SidePanelTreeActionProps = Pick<TreePickerProps, 'toggleItemActive' | 'toggleItemOpen'>;
+type SidePanelTreeActionProps = Pick<TreePickerProps, 'onContextMenu' | 'toggleItemActive' | 'toggleItemOpen'>;
const mapDispatchToProps = (dispatch: Dispatch, props: SidePanelTreeProps): SidePanelTreeActionProps => ({
+ onContextMenu: (event, id) => {
+ dispatch<any>(openSidePanelContextMenu(event, id));
+ },
toggleItemActive: (nodeId) => {
dispatch<any>(activateSidePanelTreeItem(nodeId));
props.onItemActivation(nodeId);
export interface TreePickerProps {
pickerId: string;
+ onContextMenu: (event: React.MouseEvent<HTMLElement>, nodeId: string, pickerId: string) => void;
toggleItemOpen: (nodeId: string, status: TreeItemStatus, pickerId: string) => void;
toggleItemActive: (nodeId: string, status: TreeItemStatus, pickerId: string) => void;
}
};
const mapDispatchToProps = (dispatch: Dispatch, props: TreePickerProps): Pick<TreeProps<any>, 'onContextMenu' | 'toggleItemOpen' | 'toggleItemActive'> => ({
- onContextMenu: () => { return; },
+ onContextMenu: (event, item) => props.onContextMenu(event, item.id, props.pickerId),
toggleItemActive: (id, status) => props.toggleItemActive(id, status, props.pickerId),
toggleItemOpen: (id, status) => props.toggleItemOpen(id, status, props.pickerId)
});