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/share modal improvements #437

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import { App, Button, Checkbox, Col, Flex, Input, QRCode, Row } from 'antd';
import { App, Button, Checkbox, Col, Flex, Input, QRCode, Row, Select, Space } from 'antd';
import { DownloadOutlined, CopyOutlined } from '@ant-design/icons';
import { useEffect, useRef, useState } from 'react';
import { useParams, useSearchParams } from 'next/navigation';
Expand All @@ -10,21 +10,24 @@ import {
import { useEnvironment } from '@/components/auth-can';

import styles from './modeler-share-modal-option-public-link.module.scss';
import { Process } from '@/lib/data/process-schema';

type ModelerShareModalOptionPublicLinkProps = {
sharedAs: 'public' | 'protected';
shareTimestamp: number;
refresh: () => void;
processVersions: Process['versions'];
};

const ModelerShareModalOptionPublicLink = ({
sharedAs,
shareTimestamp,
refresh,
processVersions,
}: ModelerShareModalOptionPublicLinkProps) => {
const { processId } = useParams();
const query = useSearchParams();
const selectedVersionId = query.get('version');
const [selectedVersionId, setSelectedVersionId] = useState<string | null>(query.get('version'));
const environment = useEnvironment();

const [shareLink, setShareLink] = useState('');
Expand Down Expand Up @@ -185,95 +188,104 @@ const ModelerShareModalOptionPublicLink = ({
};

return (
<>
<div style={{ marginBottom: '5px' }}>
<Space direction="vertical">
<Select
defaultValue={selectedVersionId || '-1'}
options={[
{ value: '-1', label: 'latest version' },
...processVersions.map((version) => ({ value: version.id, label: version.name })),
]}
onChange={(value) => {
setSelectedVersionId(value === '-1' ? null : value);
}}
/>

<div>
<Checkbox checked={isShareLinkChecked} onChange={handleShareLinkChecked}>
Share Process with Public Link
</Checkbox>
</div>
<div>
<Row>
<Col span={18} style={{ paddingBottom: '10px', paddingLeft: '25px' }}>
<Flex vertical gap="small" justify="left" align="left">
<Checkbox
checked={registeredUsersonlyChecked}
onChange={handlePermissionChanged}
disabled={isShareLinkEmpty}
>
Visible only for registered user
</Checkbox>
</Flex>
</Col>
<Col span={18}>
<Input
type={'text'}
value={shareLink}
<Row>
<Col span={18} style={{ paddingBottom: '10px', paddingLeft: '25px' }}>
<Flex vertical gap="small" justify="left" align="left">
<Checkbox
checked={registeredUsersonlyChecked}
onChange={handlePermissionChanged}
disabled={isShareLinkEmpty}
name="generated share link"
style={{ border: '1px solid #000' }}
/>
</Col>
<Col span={12}>
<Flex
vertical={false}
style={{ paddingTop: '10px', flexWrap: 'wrap-reverse' }}
justify="center"
align="center"
>
{isShareLinkChecked && (
<div id="qrcode" ref={canvasRef}>
<QRCode
style={{
border: '1px solid #000',
}}
value={shareLink}
size={130}
/>
</div>
)}
</Flex>
</Col>
<Col span={6} style={{ paddingTop: '10px' }}>
<Flex vertical gap={10}>
<Button
className={styles.OptionButton}
onClick={handleCopyLink}
disabled={isShareLinkEmpty}
>
Copy link
</Button>
<Button
className={styles.OptionButton}
onClick={handleOpenSharedPage}
disabled={isShareLinkEmpty}
>
Open
</Button>
<Button
icon={<DownloadOutlined />}
title="Save as PNG"
className={styles.OptionButton}
hidden={isShareLinkEmpty}
onClick={() => handleQRCodeAction('download')}
disabled={isShareLinkEmpty}
>
Save QR Code
</Button>
<Button
icon={<CopyOutlined />}
title="Copy as PNG"
className={styles.OptionButton}
hidden={isShareLinkEmpty}
onClick={() => handleQRCodeAction('copy')}
disabled={isShareLinkEmpty}
>
Copy QR Code
</Button>
</Flex>
</Col>
</Row>
</div>
</>
Visible only for registered user
</Checkbox>
</Flex>
</Col>
<Col span={18}>
<Input
type={'text'}
value={shareLink}
disabled={isShareLinkEmpty}
name="generated share link"
style={{ border: '1px solid #000' }}
/>
</Col>
<Col span={12}>
<Flex
vertical={false}
style={{ paddingTop: '10px', flexWrap: 'wrap-reverse' }}
justify="center"
align="center"
>
{isShareLinkChecked && (
<div id="qrcode" ref={canvasRef}>
<QRCode
style={{
border: '1px solid #000',
}}
value={shareLink}
size={130}
/>
</div>
)}
</Flex>
</Col>
<Col span={6} style={{ paddingTop: '10px' }}>
<Flex vertical gap={10}>
<Button
className={styles.OptionButton}
onClick={handleCopyLink}
disabled={isShareLinkEmpty}
>
Copy link
</Button>
<Button
className={styles.OptionButton}
onClick={handleOpenSharedPage}
disabled={isShareLinkEmpty}
>
Open
</Button>
<Button
icon={<DownloadOutlined />}
title="Save as PNG"
className={styles.OptionButton}
hidden={isShareLinkEmpty}
onClick={() => handleQRCodeAction('download')}
disabled={isShareLinkEmpty}
>
Save QR Code
</Button>
<Button
icon={<CopyOutlined />}
title="Copy as PNG"
className={styles.OptionButton}
hidden={isShareLinkEmpty}
onClick={() => handleQRCodeAction('copy')}
disabled={isShareLinkEmpty}
>
Copy QR Code
</Button>
</Flex>
</Col>
</Row>
</Space>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ import { set } from 'zod';
type ShareModalProps = {
onExport: () => void;
onExportMobile: (type: ProcessExportOptions['type']) => void;
versions: Process['versions'];
};
type SharedAsType = 'public' | 'protected';

const ModelerShareModalButton: FC<ShareModalProps> = ({ onExport, onExportMobile }) => {
const ModelerShareModalButton: FC<ShareModalProps> = ({
onExport,
onExportMobile,
versions: processVersions,
}) => {
const { processId } = useParams();
const environment = useEnvironment();
const [isOpen, setIsOpen] = useState(false);
Expand Down Expand Up @@ -276,6 +281,7 @@ const ModelerShareModalButton: FC<ShareModalProps> = ({ onExport, onExportMobile
sharedAs={sharedAs as SharedAsType}
shareTimestamp={shareTimestamp}
refresh={checkIfProcessShared}
processVersions={processVersions}
/>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ const ModelerToolbar = ({
<ModelerShareModalButton
onExport={handleProcessExportModalToggle}
onExportMobile={handleProcessExportModalToggleMobile}
versions={versions}
/>
<Tooltip title="Open Documentation">
<Button icon={<FilePdfOutlined />} onClick={handleOpenDocumentation} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { toCaslResource } from '@/lib/ability/caslAbility';
import AddUserControls from '@/components/add-user-controls';
import { getProcess, getProcesses } from '@/lib/data/DTOs';
import { getProcessBPMN } from '@/lib/data/processes';
import { UnauthorizedError } from '@/lib/ability/abilityHelper';

type ProcessProps = {
params: { processId: string; environmentId: string };
Expand All @@ -25,7 +26,7 @@ const Process = async ({ params: { processId, environmentId }, searchParams }: P
const processes = await getProcesses(userId, ability, false);

if (!ability.can('view', toCaslResource('Process', process))) {
throw new Error('Forbidden.');
throw new UnauthorizedError();
}

const selectedVersionBpmn = selectedVersionId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const ProcessDocument: React.FC<ProcessDocumentProps> = ({

// transform the document data into the respective pages of the document
useEffect(() => {
processHierarchy && getContent(processHierarchy, processPages);
processHierarchy && getContent(processHierarchy, []);
}, [processHierarchy]);

return (
Expand All @@ -256,7 +256,7 @@ const ProcessDocument: React.FC<ProcessDocumentProps> = ({
<div className={cn(styles.Title, { [styles.TitlePage]: settings.titlepage })}>
<Title>{processData.name}</Title>
<div className={styles.TitleInfos}>
<div>Owner: {processData.creatorId.split('|').pop()}</div>
<div>Owner: {processData.creatorId?.split('|').pop()}</div>
{version.id ? (
<>
<div>Version: {version.name || version.id}</div>
Expand Down
16 changes: 12 additions & 4 deletions src/management-system-v2/lib/data/legacy/_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export function getProcessMetaObjects() {
return processMetaObjects;
}

function parseDates<T extends ProcessMetadata>(process: T) {
// The type says these fields are dates, but they're turned into a string when stored
process.lastEditedOn = new Date(process.lastEditedOn);
process.createdOn = new Date(process.createdOn);

return process;
}

/** Returns all processes for a user */
export async function getProcesses(userId: string, ability: Ability, includeBPMN = false) {
const processes = Object.values(processMetaObjects);
Expand All @@ -69,7 +77,7 @@ export async function getProcesses(userId: string, ability: Ability, includeBPMN
),
);

return userProcesses;
return userProcesses.map(parseDates);
}

export async function getProcess(processDefinitionsId: string, includeBPMN = false) {
Expand All @@ -79,7 +87,7 @@ export async function getProcess(processDefinitionsId: string, includeBPMN = fal
}

const bpmn = includeBPMN ? await getProcessBpmn(processDefinitionsId) : null;
return { ...process, bpmn };
return parseDates({ ...process, bpmn });
}

/**
Expand Down Expand Up @@ -213,7 +221,7 @@ export function moveProcess({

if (!dontUpdateOldFolder) {
const oldFolder = foldersMetaObject.folders[process.folderId];
if (!oldFolder) throw new Error("Consistensy Error: Process' folder not found");
if (!oldFolder) throw new Error("Consistency Error: Process' folder not found");
const processOldFolderIdx = oldFolder.children.findIndex(
(item) => 'type' in item && item.type === 'process' && item.id === processDefinitionsId,
);
Expand All @@ -239,7 +247,7 @@ export async function updateProcessMetaData(

const newMetaData = {
...processMetaObjects[processDefinitionsId],
lastEdited: new Date().toUTCString(),
lastEditedOn: new Date(),
};

mergeIntoObject(newMetaData, metaChanges, true, true, true);
Expand Down
Loading