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

Ms2/process editor #126

Merged
merged 12 commits into from
Oct 23, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Modeler from '@/components/modeler';
import cn from 'classnames';
import Content from '@/components/content';
import Overlay from './overlay';
import { useGetAsset } from '@/lib/fetch-data';
import { useGetAsset, useInvalidateAsset } from '@/lib/fetch-data';
import {
Breadcrumb,
BreadcrumbProps,
Expand All @@ -20,9 +20,10 @@ import {
} from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import useModelerStateStore from '@/lib/use-modeler-state-store';
import { createNewProcessVersion } from '@/lib/helpers';
import { createNewProcessVersion } from '@/lib/helpers/processVersioning';
import VersionCreationButton from '@/components/version-creation-button';
import Auth from '@/lib/AuthCanWrapper';
import ProcessCreationButton from '@/components/process-creation-button';

type ProcessProps = {
params: { processId: string };
Expand All @@ -39,24 +40,23 @@ const Processes: FC<ProcessProps> = () => {
const [closed, setClosed] = useState(false);
const router = useRouter();
const modeler = useModelerStateStore((state) => state.modeler);
const {
isSuccess,
data: process,
refetch: refetchProcess,
isLoading: processIsLoading,
} = useGetAsset('/process/{definitionId}', {
const { data: process, isLoading: processIsLoading } = useGetAsset('/process/{definitionId}', {
params: { path: { definitionId: processId as string } },
});
const {
data: processes,
isLoading: processesIsLoading,
isError: processesIsError,
isSuccess: processesIsSuccess,
} = useGetAsset('/process', {
const { data: processes } = useGetAsset('/process', {
params: {
query: { noBpmn: true },
},
});

const invalidateVersions = useInvalidateAsset('/process/{definitionId}/versions', {
params: { path: { definitionId: processId as string } },
});

const invalidateProcesses = useInvalidateAsset('/process/{definitionId}', {
params: { path: { definitionId: processId as string } },
});

const {
token: { fontSizeHeading1 },
} = theme.useToken();
Expand All @@ -75,10 +75,6 @@ const Processes: FC<ProcessProps> = () => {
}
}, [minimized]);

const createProcess = () => {
console.log('create process');
};

const createProcessVersion = async (values: {
versionName: string;
versionDescription: string;
Expand All @@ -91,6 +87,8 @@ const Processes: FC<ProcessProps> = () => {
values.versionName,
values.versionDescription,
);
await invalidateVersions();
await invalidateProcesses();
}
};

Expand Down Expand Up @@ -119,9 +117,9 @@ const Processes: FC<ProcessProps> = () => {
{menu}
<Divider style={{ margin: '4px 0' }} />
<Space style={{ display: 'flex', justifyContent: 'center' }}>
<Button type="text" icon={<PlusOutlined />} onClick={createProcess}>
<ProcessCreationButton type="text" icon={<PlusOutlined />}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permission check is missing (AuthCan)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also the case in version-toolbar.tsx:199

Create new process
</Button>
</ProcessCreationButton>
</Space>
</>
)}
Expand Down
74 changes: 74 additions & 0 deletions src/management-system-v2/components/ProcessSider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use client';

import { FC, PropsWithChildren } from 'react';
import { Menu } from 'antd';
const { SubMenu, Item, ItemGroup } = Menu;
import { EditOutlined, ProfileOutlined, FileAddOutlined, StarOutlined } from '@ant-design/icons';
import { usePathname, useRouter } from 'next/navigation';
import { useAuthStore } from '@/lib/iam';
import ProcessCreationButton from './process-creation-button';

const ProcessSider: FC<PropsWithChildren> = () => {
const router = useRouter();
const activeSegment = usePathname().slice(1) || 'processes';
const ability = useAuthStore((state) => state.ability);

return (
<>
<ItemGroup key="processes" title="Processes">
{ability.can('view', 'Process') ? (
<SubMenu
key="processes"
title={
<span
onClick={() => {
router.push(`/processes`);
}}
>
Process List
</span>
}
className={activeSegment === 'processes' ? 'SelectedSegment' : ''}
icon={
<EditOutlined
onClick={() => {
router.push(`/processes`);
}}
/>
}
>
<Item
key="newProcess"
icon={<FileAddOutlined />}
hidden={!ability.can('create', 'Process')}
>
<ProcessCreationButton
wrapperElement={<span>New Process</span>}
></ProcessCreationButton>
</Item>
<Item key="processFavorites" icon={<StarOutlined />}>
Favorites
</Item>
</SubMenu>
) : null}

{ability.can('view', 'Template') ? (
<SubMenu key="templates" title="Templates" icon={<ProfileOutlined />}>
<Item
key="newTemplate"
icon={<FileAddOutlined />}
hidden={!ability.can('create', 'Template')}
>
New Template
</Item>
<Item key="templateFavorites" icon={<StarOutlined />}>
Favorites
</Item>
</SubMenu>
) : null}
</ItemGroup>
</>
);
};

export default ProcessSider;
102 changes: 7 additions & 95 deletions src/management-system-v2/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,15 @@

import styles from './layout.module.scss';
import { FC, PropsWithChildren, useState } from 'react';
import { Layout as AntLayout, Grid, Menu, MenuProps } from 'antd';
const { SubMenu, Item, Divider, ItemGroup } = Menu;
import Logo from '@/public/proceed.svg';
import {
EditOutlined,
UnorderedListOutlined,
ProfileOutlined,
FileAddOutlined,
SettingOutlined,
ApiOutlined,
UserOutlined,
StarOutlined,
UnlockOutlined,
} from '@ant-design/icons';
import { Layout as AntLayout, Grid, Menu } from 'antd';
const { Item, Divider, ItemGroup } = Menu;
import { SettingOutlined, ApiOutlined, UserOutlined, UnlockOutlined } from '@ant-design/icons';
import Image from 'next/image';
import { usePathname, useRouter } from 'next/navigation';
import { usePathname } from 'next/navigation';
import cn from 'classnames';
import { useAuthStore } from '@/lib/iam';
import Link from 'next/link';

const items: MenuProps['items'] = [
{
key: 'processes',
icon: <EditOutlined />,
label: 'Processes',
},
{
key: 'projects',
icon: <UnorderedListOutlined />,
label: 'Projects',
},
{
key: 'templates',
icon: <ProfileOutlined />,
label: 'Templates',
disabled: true,
},
];
import ProcessSider from './ProcessSider';

/**
* The main layout of the application. It defines the sidebar and footer. Note
Expand All @@ -51,7 +22,6 @@ const items: MenuProps['items'] = [
* page content in parallel routes.
*/
const Layout: FC<PropsWithChildren> = ({ children }) => {
const router = useRouter();
const activeSegment = usePathname().slice(1) || 'processes';
const [collapsed, setCollapsed] = useState(false);
const ability = useAuthStore((state) => state.ability);
Expand Down Expand Up @@ -88,68 +58,10 @@ const Layout: FC<PropsWithChildren> = ({ children }) => {
</Link>
</div>
{loggedIn ? (
<Menu
theme="light"
mode="inline"
selectedKeys={[activeSegment]}
onClick={({ key }) => {
const path = key.split(':').at(-1);
router.push(`/${path}`);
}}
>
<Menu theme="light" mode="inline" selectedKeys={[activeSegment]}>
{ability.can('view', 'Process') || ability.can('view', 'Template') ? (
<>
<ItemGroup key="processes" title="Processes">
{ability.can('view', 'Process') ? (
<SubMenu
key="processes"
title={
<span
onClick={() => {
router.push(`/processes`);
}}
>
Process List
</span>
}
className={activeSegment === 'processes' ? 'SelectedSegment' : ''}
icon={
<EditOutlined
onClick={() => {
router.push(`/processes`);
}}
/>
}
>
<Item
key="newProcess"
icon={<FileAddOutlined />}
hidden={!ability.can('create', 'Process')}
>
New Process
</Item>
<Item key="processFavorites" icon={<StarOutlined />}>
Favorites
</Item>
</SubMenu>
) : null}

{ability.can('view', 'Template') ? (
<SubMenu key="templates" title="Templates" icon={<ProfileOutlined />}>
<Item
key="newTemplate"
icon={<FileAddOutlined />}
hidden={!ability.can('create', 'Template')}
>
New Template
</Item>
<Item key="templateFavorites" icon={<StarOutlined />}>
Favorites
</Item>
</SubMenu>
) : null}
</ItemGroup>

<ProcessSider></ProcessSider>
<Divider />
</>
) : null}
Expand Down
17 changes: 15 additions & 2 deletions src/management-system-v2/components/modeler-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import { useParams, useSearchParams } from 'next/navigation';

import ProcessExportModal from './process-export';

import { createNewProcessVersion } from '@/lib/helpers';
import { createNewProcessVersion } from '@/lib/helpers/processVersioning';
import VersionCreationButton from './version-creation-button';
import { useQueryClient } from '@tanstack/react-query';
import { useInvalidateAsset } from '@/lib/fetch-data';

type ModelerToolbarProps = {
onOpenXmlEditor: () => void;
Expand All @@ -41,9 +43,18 @@ const ModelerToolbar: React.FC<ModelerToolbarProps> = ({ onOpenXmlEditor }) => {
const modeler = useModelerStateStore((state) => state.modeler);
const selectedElementId = useModelerStateStore((state) => state.selectedElementId);

// const [index, setIndex] = useState(0);
const { processId } = useParams();

const invalidateVersions = useInvalidateAsset('/process/{definitionId}/versions', {
params: { path: { definitionId: processId as string } },
});

const invalidateProcesses = useInvalidateAsset('/process/{definitionId}', {
params: { path: { definitionId: processId as string } },
});

// const [index, setIndex] = useState(0);

let selectedElement;

if (modeler) {
Expand All @@ -66,6 +77,8 @@ const ModelerToolbar: React.FC<ModelerToolbarProps> = ({ onOpenXmlEditor }) => {
values.versionName,
values.versionDescription,
);
await invalidateVersions();
await invalidateProcesses();
}
};
const handlePropertiesPanelToggle = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/management-system-v2/components/modeler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Modeler: FC<ModelerProps> = ({ minimized, ...props }) => {
// This is not the most recent instance, so don't do anything.
if (active !== modeler.current) return;

if (editingDisabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editingDisabled seems to be unused

if (selectedVersionId !== null) {
modeler.current = new Viewer!({
container: canvas.current!,
moddleExtensions: {
Expand Down Expand Up @@ -103,7 +103,7 @@ const Modeler: FC<ModelerProps> = ({ minimized, ...props }) => {
modeler.current?.destroy();
};
// only reset the modeler if we switch between editing being enabled or disabled
}, [setModeler, editingDisabled, processId, updateProcessMutation]);
}, [setModeler, editingDisabled, selectedVersionId, processId, updateProcessMutation]);

const { data: processBpmn } = useProcessBpmn(processId as string, selectedVersionId);

Expand Down
Loading