Skip to content

Commit

Permalink
Added view of notes and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wkwong-ribose committed Oct 8, 2021
1 parent 87eecb3 commit 8903be4
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/smart/model/editormodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,13 @@ export function getEditorDataClassById(
export function getEditorProvisionById(
model: EditorModel,
id: string
): MMELProvision | null {
if (id === '') {
return null;
}
const r = model.provisions[id];
return r ?? null;
): MMELProvision | null {
return model.provisions[id] ?? null;
}

export function getEditorNoteById(
model: EditorModel,
id: string
): MMELNote | null {
return model.notes[id]??null;
}
22 changes: 22 additions & 0 deletions src/smart/ui/common/description/ComponentDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EditorTimerEvent,
} from '../../../model/editormodel';
import {
MMELNote,
MMELProvision,
MMELReference,
} from '../../../serialize/interface/supportinterface';
Expand Down Expand Up @@ -84,6 +85,27 @@ export const DescribeProvision: React.FC<{
);
};

export const DescribeNote: React.FC<{
note: MMELNote;
getRefById?: (id: string) => MMELReference | null;
}> = function ({ note, getRefById }) {
const minimal = getRefById === undefined;
return (
<>
{!minimal && (
<DescriptionItem label="Type" value={note.type} />
)}
<DescriptionItem
label={minimal ? undefined : 'Message'}
value={minimal ? `${note.type} ${note.message}` : note.message}
/>
{getRefById !== undefined && (
<ReferenceList refs={note.ref} getRefById={getRefById} />
)}
</>
);
};

export const DescribeEdge: React.FC<{
edge: MMELEdge;
}> = function ({ edge }) {
Expand Down
36 changes: 35 additions & 1 deletion src/smart/ui/common/description/ComponentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { EditorRegistry } from '../../../model/editormodel';
import { MMELDataAttribute } from '../../../serialize/interface/datainterface';
import { MMELEdge } from '../../../serialize/interface/flowcontrolinterface';
import {
MMELNote,
MMELProvision,
MMELReference,
} from '../../../serialize/interface/supportinterface';
import { toRefSummary } from '../../../utils/ModelFunctions';
import { DescribeEdge, DescribeProvision } from './ComponentDescription';
import { DescribeEdge, DescribeNote, DescribeProvision } from './ComponentDescription';
import { DescribeAttribute } from './data';

export const ApprovalRecordList: React.FC<{
Expand Down Expand Up @@ -152,6 +153,39 @@ export const ProvisionList: React.FC<{
);
};

export const NotesList: React.FC<{
notes: Set<string>;
getNoteById: (id: string) => MMELNote | null;
getRefById?: (id: string) => MMELReference | null;
}> = function ({ notes, getNoteById, getRefById }) {
const ns: MMELNote[] = [];
notes.forEach(r => {
const ret = getNoteById(r);
if (ret !== null) {
ns.push(ret);
}
});
return (
<>
{ns.length > 0 ? (
<>
{getRefById !== undefined && <p>Notes</p>}
<ul>
{ns.map(note => (
<li key={note.id}>
<DescribeNote
note={note}
getRefById={getRefById}
/>
</li>
))}
</ul>
</>
) : null}
</>
);
};

export const MeasurementList: React.FC<{
measurements: string[];
}> = function ({ measurements }) {
Expand Down
10 changes: 9 additions & 1 deletion src/smart/ui/common/description/process.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import { jsx } from '@emotion/react';
import React from 'react';
import { EditorProcess } from '../../../model/editormodel';
import {
MMELNote,
MMELProvision,
MMELReference,
MMELRole,
} from '../../../serialize/interface/supportinterface';
import { ActorDescription, DescriptionItem } from './fields';
import { MeasurementList, ProvisionList } from './ComponentList';
import { MeasurementList, NotesList, ProvisionList } from './ComponentList';

export const DescribeProcess: React.FC<{
process: EditorProcess;
getRoleById: (id: string) => MMELRole | null;
getRefById?: (id: string) => MMELReference | null;
getProvisionById: (id: string) => MMELProvision | null;
getNoteById: (id: string) => MMELNote | null;
CustomProvision?: React.FC<{
provision: MMELProvision;
getRefById?: (id: string) => MMELReference | null;
Expand All @@ -26,6 +28,7 @@ export const DescribeProcess: React.FC<{
getProvisionById,
getRefById,
getRoleById,
getNoteById,
CustomProvision,
}) => {
return (
Expand All @@ -39,6 +42,11 @@ export const DescribeProcess: React.FC<{
getRefById={getRefById}
CustomProvision={CustomProvision}
/>
<NotesList
notes={process.notes}
getNoteById={getNoteById}
getRefById={getRefById}
/>
<MeasurementList measurements={process.measure} />
</>
);
Expand Down
3 changes: 2 additions & 1 deletion src/smart/ui/edit/processedit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,13 @@ function save(
oldProcess.provision,
provisions
);
process.provision = new Set(Object.values(provisions).map(p => p.id));
model.notes = updateNotes(
model.notes,
oldProcess.notes,
notes
);
process.provision = new Set(Object.values(provisions).map(p => p.id));
process.notes = new Set(Object.values(notes).map(n => n.id));
return model;
}

Expand Down
10 changes: 10 additions & 0 deletions src/smart/ui/flowui/nodeUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ export const ProcessComponent: FC<NodeProps> = function ({ data }) {
</Tooltip2>
</div>
)}
{process.page !== '' && (
<div css={flownode_top_left_button_layout}>
<Tooltip2 content="View subprocess" position="top">
<MGDButton
onClick={() => callback.onProcessClick(process.page, process.id)}
icon="plus"
/>
</Tooltip2>
</div>
)}
{callback.hasMapping !== undefined &&
callback.hasMapping(process.id) &&
callback.MappingList !== undefined && (
Expand Down
10 changes: 9 additions & 1 deletion src/smart/ui/sidebar/SimulationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Button, Text } from '@blueprintjs/core';
import { MainFlowNodeTypes } from '../../utils/constants';
import { DataType } from '../../serialize/interface/baseinterface';
import {
MMELNote,
MMELProvision,
MMELRole,
} from '../../serialize/interface/supportinterface';
Expand Down Expand Up @@ -52,6 +53,10 @@ const SimulationDetails: React.FC<{
return model.provisions[id] ?? null;
}

function getNoteById(id: string): MMELNote | null {
return model.notes[id] ?? null;
}

function getRoleById(id: string): MMELRole | null {
return model.roles[id] ?? null;
}
Expand Down Expand Up @@ -84,6 +89,7 @@ const SimulationDetails: React.FC<{
node={elm}
getProvisionById={getProvisionById}
getRoleById={getRoleById}
getNoteById={getNoteById}
/>
)}
<fieldset>
Expand Down Expand Up @@ -148,6 +154,7 @@ const NODE_SIMULATION_SUMMARY: Record<
node: EditorNode;
getProvisionById: (id: string) => MMELProvision | null;
getRoleById: (id: string) => MMELRole | null;
getNoteById: (id: string) => MMELNote | null;
}>
> = {
[DataType.STARTEVENT]: () => <DescribeStart />,
Expand All @@ -164,12 +171,13 @@ const NODE_SIMULATION_SUMMARY: Record<
) : (
<></>
),
[DataType.PROCESS]: ({ node, getProvisionById, getRoleById }) =>
[DataType.PROCESS]: ({ node, getProvisionById, getRoleById, getNoteById }) =>
isEditorProcess(node) ? (
<DescribeProcess
process={node}
getProvisionById={getProvisionById}
getRoleById={getRoleById}
getNoteById={getNoteById}
/>
) : (
<></>
Expand Down
10 changes: 10 additions & 0 deletions src/smart/ui/sidebar/ViewComponentDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EditorRegistry,
EditorSubprocess,
getEditorDataClassById,
getEditorNoteById,
getEditorProvisionById,
getEditorRefById,
getEditorRegistryById,
Expand All @@ -25,6 +26,7 @@ import { DataType } from '../../serialize/interface/baseinterface';
import { MMELDataAttribute } from '../../serialize/interface/datainterface';
import { MMELEdge } from '../../serialize/interface/flowcontrolinterface';
import {
MMELNote,
MMELProvision,
MMELReference,
} from '../../serialize/interface/supportinterface';
Expand All @@ -48,6 +50,7 @@ const NODE_DETAIL_VIEWS: Record<
getRegistryById: (id: string) => EditorRegistry | null;
getDCById: (id: string) => EditorDataClass | null;
getProvisionById: (id: string) => MMELProvision | null;
getNoteById: (id: string) => MMELNote | null;
getOutgoingEdgesById: (id: string) => MMELEdge[];
CustomAttribute?: React.FC<{
att: MMELDataAttribute;
Expand Down Expand Up @@ -108,13 +111,15 @@ const NODE_DETAIL_VIEWS: Record<
node,
getProvisionById,
getRefById,
getNoteById,
CustomProvision,
}) =>
isEditorProcess(node) ? (
<DescribeProcess
process={node}
getProvisionById={getProvisionById}
getRefById={getRefById}
getNoteById={getNoteById}
CustomProvision={CustomProvision}
{...node}
/>
Expand Down Expand Up @@ -153,6 +158,10 @@ export const Describe: React.FC<{
return getEditorProvisionById(model, id);
}

function getNoteById(id: string): MMELNote | null {
return getEditorNoteById(model, id);
}

function getOutgoingEdgesById(id: string): MMELEdge[] {
return Object.values(page.edges).filter(e => e.from === id);
}
Expand All @@ -166,6 +175,7 @@ export const Describe: React.FC<{
getDCById={getDCById}
getProvisionById={getProvisionById}
getOutgoingEdgesById={getOutgoingEdgesById}
getNoteById={getNoteById}
CustomAttribute={CustomAttribute}
CustomProvision={CustomProvision}
/>
Expand Down

0 comments on commit 8903be4

Please sign in to comment.