Skip to content

Commit

Permalink
Merge branch 'main' into ms2/process-list-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OhKai authored May 31, 2024
2 parents 94852ba + b4afccd commit 6433457
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AuthOptions, getServerSession } from 'next-auth';
import Auth0Provider from 'next-auth/providers/auth0';
import EmailProvider from 'next-auth/providers/email';
import GoogleProvider from 'next-auth/providers/google';
import CredentialsProvider from 'next-auth/providers/credentials';
import { addUser, getUserById, updateUser, usersMetaObject } from '@/lib/data/legacy/iam/users';
import { CredentialInput, OAuthProviderButtonStyles } from 'next-auth/providers';
Expand Down Expand Up @@ -106,6 +107,20 @@ if (process.env.USE_AUTH0) {
};
},
}),
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
profile(profile) {
return {
id: profile.sub,
name: profile.name,
firstName: profile.given_name,
lastName: profile.family_name,
email: profile.email,
image: profile.picture,
};
},
}),
);
}

Expand Down
84 changes: 75 additions & 9 deletions src/management-system-v2/components/processes/context-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { create } from 'zustand';
import { ProcessActions, ProcessListProcess, canDeleteItems } from '.';
import { FC, PropsWithChildren } from 'react';
import { Dropdown, MenuProps } from 'antd';
import { App, Dropdown, MenuProps } from 'antd';
import { useAbilityStore } from '@/lib/abilityStore';
import { DeleteOutlined, CopyOutlined, FolderAddOutlined, EditOutlined } from '@ant-design/icons';
import { DeleteOutlined, CopyOutlined, FolderAddOutlined, LinkOutlined } from '@ant-design/icons';
import { Folder } from '@/lib/data/folder-schema';
import SpaceLink from '../space-link';
import { MdOpenWith } from 'react-icons/md';
import { IoOpenOutline } from 'react-icons/io5';
import { spaceURL } from '@/lib/utils';
import { useEnvironment } from '../auth-can';

export const contextMenuStore = create<{
setSelected: (id: ProcessListProcess[]) => void;
Expand All @@ -31,6 +36,8 @@ const ConextMenuArea: FC<
const setSelectedContextMenuItem = contextMenuStore((store) => store.setSelected);
const selectedContextMenuItems = contextMenuStore((store) => store.selected);
const ability = useAbilityStore((state) => state.ability);
const space = useEnvironment();
const { message } = App.useApp();

const contextMenuItems: MenuProps['items'] = [];
if (selectedContextMenuItems.length > 0) {
Expand All @@ -40,12 +47,39 @@ const ConextMenuArea: FC<
selectedContextMenuItems.length === 1 &&
canDeleteItems(selectedContextMenuItems, 'delete', ability)
)
children.push({
key: 'edit-selected',
label: 'Edit',
icon: <EditOutlined />,
onClick: () => editItem(selectedContextMenuItems[0]),
});
children.push(
{
key: 'open-selected',
icon: <MdOpenWith />,
label: (
<SpaceLink
href={
selectedContextMenuItems[0].type === 'folder'
? `/processes/folder/${selectedContextMenuItems[0].id}`
: `/processes/${selectedContextMenuItems[0].id}`
}
>
Open
</SpaceLink>
),
},
{
key: 'open-selected-new-tab',
icon: <IoOpenOutline />,
label: (
<SpaceLink
href={
selectedContextMenuItems[0].type === 'folder'
? `/processes/folder/${selectedContextMenuItems[0].id}`
: `/processes/${selectedContextMenuItems[0].id}`
}
target="_blank"
>
Open in new tab
</SpaceLink>
),
},
);

if (canDeleteItems(selectedContextMenuItems, 'delete', ability))
children.push({
Expand All @@ -56,7 +90,39 @@ const ConextMenuArea: FC<
});

if (
selectedContextMenuItems.some(({ id }) => id === folder.parentId) &&
selectedContextMenuItems.length === 1 &&
selectedContextMenuItems[0].type !== 'folder' &&
navigator.clipboard &&
'write' in navigator.clipboard
)
children.push({
key: 'copy-selected-id',
label: 'Copy Process Link',
icon: <LinkOutlined />,
onClick: async () => {
try {
const url = new URL(
spaceURL(space, `/processes/${selectedContextMenuItems[0].id}`),
window.location.origin,
);

await window.navigator.clipboard.writeText(url.toString());
message.open({
content: 'Link copied to clipboard',
type: 'success',
});
} catch (e) {
message.open({
content: 'Failed to copy link to clipboard',
type: 'error',
});
}
},
});

if (
folder.parentId !== null &&
!selectedContextMenuItems.some(({ id }) => id === folder.parentId) &&
canDeleteItems(selectedContextMenuItems, 'update', ability)
)
children.push({
Expand Down
17 changes: 9 additions & 8 deletions src/management-system-v2/components/processes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,12 @@ const Processes = ({
{ dependencies: [selectedRowKeys.length] },
);

const createProcessButton = <ProcessCreationButton wrapperElement="Create Process" />;
const defaultDropdownItems = [];
if (ability.can('create', 'Process'))
defaultDropdownItems.push({
key: 'create-process',
label: <ProcessCreationButton wrapperElement="create process" />,
label: createProcessButton,
icon: <FileOutlined />,
});

Expand Down Expand Up @@ -293,16 +294,16 @@ const Processes = ({
<span style={{ display: 'flex', justifyContent: 'flex-start' }}>
{!breakpoint.xs && (
<Space>
<Dropdown
trigger={['click']}
<Dropdown.Button
menu={{
items: defaultDropdownItems,
items: defaultDropdownItems.filter(
(item) => item.key !== 'create-process',
),
}}
type="primary"
>
<Button type="primary" icon={<PlusOutlined />}>
New
</Button>
</Dropdown>
{createProcessButton}
</Dropdown.Button>
<ProcessImportButton type="default">
{breakpoint.xl ? 'Import Process' : 'Import'}
</ProcessImportButton>
Expand Down
2 changes: 2 additions & 0 deletions src/management-system-v2/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace NodeJS {
AUTH0_clientCredentialScope?: string;
AUTH0_ISSUER?: string;
AUTH0_SCOPE?: string;
GOOGLE_CLIENT_ID?: string;
GOOGLE_CLIENT_SECRET?: string;

ENABLE_MACHINE_CONFIG?: string;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/ms2/process-list/process-list.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ export class ProcessListPage {
this.processDefinitionIds = this.processDefinitionIds.filter((id) => id !== definitionId);
}

async createProcess(options: { processName?: string; description?: string }) {
const page = this.page;
const { processName, description } = options;

// TODO: reuse other page models for these set ups.
// Add a new process.
await page.getByRole('button', { name: 'Create Process' }).click();
await page.getByRole('textbox', { name: '* Process Name :' }).fill(processName ?? 'My Process');
await page.getByLabel('Process Description').fill(description ?? 'Process Description');
await page.getByRole('button', { name: 'Create', exact: true }).click();
await page.waitForURL(/processes\/([a-zA-Z0-9-_]+)/);

return page.url().split('processes/').pop();
}

async removeAllProcesses() {
const { page, processListPageURL } = this;

Expand Down
25 changes: 8 additions & 17 deletions tests/ms2/process-list/process-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ import { test, expect } from './process-list.fixtures';
test('create a new process and remove it again', async ({ processListPage }) => {
const { page } = processListPage;

await page.getByRole('button', { name: 'plus New' }).click();
await page.getByRole('menuitem', { name: 'file Create Process' }).click();
await page.getByRole('textbox', { name: '* Process Name :' }).fill('Process Name');
await page.getByLabel('Process Description').click();
await page.getByLabel('Process Description').fill('Process Description');
await page.getByRole('button', { name: 'Create' }).click();
await page.waitForURL(/processes\/([a-zA-Z0-9-_]+)/);

const processDefinitionID = page.url().split('processes/').pop();
const processDefinitionID = await processListPage.createProcess({
processName: 'Process Name',
description: 'Process Description',
});

await processListPage.goto();

Expand Down Expand Up @@ -485,7 +480,8 @@ test('create a new folder with new button and remove it', async ({ processListPa
const { page } = processListPage;
const folderId = crypto.randomUUID();

await page.getByRole('button', { name: 'plus New' }).click();
// NOTE: this could easily break
await page.getByRole('button', { name: 'ellipsis' }).hover();
await page.getByRole('menuitem', { name: 'Create Folder' }).click();
await page.getByLabel('Folder name').fill(folderId);
await page.getByRole('button', { name: 'OK' }).click();
Expand All @@ -507,7 +503,7 @@ test('create a new folder and process, move process to folder and then delete bo

// create folder
const folderId = crypto.randomUUID();
await page.getByRole('button', { name: 'plus New' }).click();
await page.getByText('No data').click({ button: 'right' });
await page.getByRole('menuitem', { name: 'Create Folder' }).click();
await page.getByLabel('Folder name').fill(folderId);
await page.getByRole('button', { name: 'OK' }).click();
Expand All @@ -516,12 +512,7 @@ test('create a new folder and process, move process to folder and then delete bo

// create process
const processId = crypto.randomUUID();
await page.getByRole('button', { name: 'plus New' }).click();
await page.getByRole('menuitem', { name: 'file Create Process' }).click();
await page.getByRole('textbox', { name: '* Process Name :' }).fill(processId);
await page.getByRole('button', { name: 'Create' }).click();
await page.waitForURL(/\/processes\/([a-zA-Z0-9-_]+)/);
const processDefinitionID = page.url().split('processes/').pop();
const processDefinitionID = await processListPage.createProcess({ processName: processId });
await processListPage.goto();
const processLocator = page.locator(`tr[data-row-key="${processDefinitionID}"]`);
await expect(processLocator).toBeVisible();
Expand Down
5 changes: 2 additions & 3 deletions tests/process-modeler/process-modeler.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ export class ProcessModelerPage {

// TODO: reuse other page models for these set ups.
// Add a new process.
await page.getByRole('button', { name: 'plus New' }).click();
await page.getByRole('menuitem', { name: 'file Create Process' }).click();
await page.getByRole('button', { name: 'Create Process' }).click();
await page.getByRole('textbox', { name: '* Process Name :' }).fill('Process Name');
await page.getByLabel('Process Description').fill('Process Description');
await page.getByRole('button', { name: 'Create' }).click();
await page.getByRole('button', { name: 'Create', exact: true }).click();
await page.waitForURL(/processes\/([a-zA-Z0-9-_]+)/);

const pageURL = page.url();
Expand Down
5 changes: 2 additions & 3 deletions tests/properties-panel/properties-panel.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ export class PropertiesPanelPage {

// TODO: reuse other page models for these set ups.
// Add a new process.
await page.getByRole('button', { name: 'plus New' }).click();
await page.getByRole('menuitem', { name: 'file Create Process' }).click();
await page.getByRole('button', { name: 'Create Process' }).click();
await page.getByRole('textbox', { name: '* Process Name :' }).fill('Process Name');
await page.getByLabel('Process Description').click();
await page.getByLabel('Process Description').fill('Process Description');
await page.getByRole('button', { name: 'Create' }).click();
await page.getByRole('button', { name: 'Create', exact: true }).click();
await page.waitForURL(/processes\/([a-zA-Z0-9-_]+)/);

const pageURL = page.url();
Expand Down

0 comments on commit 6433457

Please sign in to comment.