Skip to content

Commit

Permalink
Modified the app to support specific items in BS 6004
Browse files Browse the repository at this point in the history
Example, commentary and some bug fix
  • Loading branch information
wkwong-ribose committed Oct 18, 2021
1 parent e065387 commit ecf6409
Show file tree
Hide file tree
Showing 15 changed files with 387 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/smart/serialize/interface/supportinterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export enum VarType {
BOOLEAN = 'TRUE/FALSE',
}

export const NOTE_TYPES = ['NOTE', 'EXAMPLE', 'DEFINITION'] as const;
export const NOTE_TYPES = [
'NOTE',
'EXAMPLE',
'DEFINITION',
'COMMENTARY',
] as const;
export type NOTE_TYPE = typeof NOTE_TYPES[number];

export interface MMELMetadata extends MMELObject {
Expand Down
4 changes: 3 additions & 1 deletion src/smart/serialize/util/serailizeformater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ function toApprovalModel(app: MMELApproval): string {
if (app.actor !== '') {
out += ' actor ' + app.actor + '\n';
}
out += ' modality ' + app.modality + '\n';
if (app.modality !== '') {
out += ' modality ' + app.modality + '\n';
}
if (app.approver !== '') {
out += ' approve_by ' + app.approver + '\n';
}
Expand Down
1 change: 1 addition & 0 deletions src/smart/ui/edit/components/DataTypeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const DataTypeSelector: React.FC<{
className="bp3-popover-content-sizing"
style={{
maxHeight: '35vh',
maxWidth: '30vw',
overflowY: 'auto',
}}
>
Expand Down
1 change: 1 addition & 0 deletions src/smart/ui/edit/components/ReferenceSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const SimpleReferenceSelector: React.FC<{
className="bp3-popover-content-sizing"
style={{
maxHeight: '35vh',
maxWidth: '30vw',
overflowY: 'auto',
}}
>
Expand Down
1 change: 1 addition & 0 deletions src/smart/ui/edit/components/RegistrySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const RegistrySelector: React.FC<{
className="bp3-popover-content-sizing"
style={{
maxHeight: '35vh',
maxWidth: '30vw',
overflowY: 'auto',
}}
>
Expand Down
5 changes: 4 additions & 1 deletion src/smart/ui/edit/egateedit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ const EditEGatePage: React.FC<{
onNewID,
};

useEffect(() => setEditing(egate), [egate]);
useEffect(() => {
setEditing(egate);
setEdges([...Object.values(page.edges).filter(e => e.from === id)]);
}, [egate]);
useEffect(
() => setEdges([...Object.values(page.edges).filter(e => e.from === id)]),
[page.edges]
Expand Down
1 change: 1 addition & 0 deletions src/smart/ui/edit/processedit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ const EditProcessPage: React.FC<{
useEffect(() => {
setEditing(process);
setProvisions(getInitProvisions(model, process));
setNotes(getInitNotes(model, process));
setMeasurements(getInitMeasurement(process));
}, [process]);

Expand Down
8 changes: 8 additions & 0 deletions src/smart/ui/editFunctions/EditWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const EditWrapper: React.FC<{
const [selected, setSelected] = useState<string | undefined>(undefined);
const [copied, setCopied] = useState<string | undefined>(undefined);
const [toaster] = useState<IToaster>(Toaster.create());
const [isBSI, setIsBSI] = useState<boolean>(false);

const hotkeys = [
{
Expand All @@ -85,6 +86,12 @@ const EditWrapper: React.FC<{
label: 'Paste',
onKeyDown: paste,
},
{
combo: 'ctrl+b',
global: true,
label: 'BSI',
onKeyDown: () => setIsBSI(x => !x),
},
];

function updateState(newState: EditorState, requireHistory: boolean) {
Expand Down Expand Up @@ -195,6 +202,7 @@ const EditWrapper: React.FC<{
copy={selected !== undefined ? copy : undefined}
paste={copied !== undefined ? paste : undefined}
setSelectedId={setSelectedId}
isBSIEnabled={isBSI}
/>
</HotkeysTarget2>
</HotkeysProvider>
Expand Down
3 changes: 3 additions & 0 deletions src/smart/ui/maineditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const ModelEditor: React.FC<{
copy?: () => void;
paste?: () => void;
setSelectedId: (id: string | undefined) => void;
isBSIEnabled?: boolean;
}> = ({
isVisible,
className,
Expand All @@ -146,6 +147,7 @@ const ModelEditor: React.FC<{
copy,
paste,
setSelectedId,
isBSIEnabled,
}) => {
const { logger } = useContext(DatasetContext);

Expand Down Expand Up @@ -458,6 +460,7 @@ const ModelEditor: React.FC<{
content={
<EditorReferenceMenu
setReference={setReference}
isBSIEnabled={isBSIEnabled}
isCloseEnabled={reference !== undefined}
/>
}
Expand Down
17 changes: 16 additions & 1 deletion src/smart/ui/menu/EditorReferenceMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import { indexModel } from '../../model/mapmodel';

const EditorReferenceMenu: React.FC<{
setReference: (x: ReferenceContent | undefined) => void;
isBSIEnabled?: boolean;
isCloseEnabled: boolean;
}> = function ({ setReference, isCloseEnabled }) {
}> = function ({ setReference, isBSIEnabled = false, isCloseEnabled }) {
const { useDecodedBlob, requestFileFromFilesystem } =
useContext(DatasetContext);

Expand Down Expand Up @@ -61,6 +62,20 @@ const EditorReferenceMenu: React.FC<{
}
icon="document-open"
/>
{isBSIEnabled && (
<MenuItem
text="Open XML Document"
onClick={() =>
handleDocumentOpen({
setDocument: setReference,
useDecodedBlob,
requestFileFromFilesystem,
fileType: FILE_TYPE.BSI,
})
}
icon="document-open"
/>
)}
<MenuItem
text="Close Reference"
disabled={!isCloseEnabled}
Expand Down
7 changes: 6 additions & 1 deletion src/smart/ui/popover/AskIDForSaveMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button } from '@blueprintjs/core';
import { jsx } from '@emotion/react';
import React, { useState } from 'react';
import { popover_panel_container } from '../../../css/layout';
import { removeSpace } from '../../utils/ModelFunctions';
import { NormalTextField } from '../common/fields';

const AskIDForSaveMenu: React.FC<{
Expand All @@ -27,7 +28,11 @@ const AskIDForSaveMenu: React.FC<{

return (
<div css={popover_panel_container}>
<NormalTextField text={title} value={id} onChange={x => setID(x)} />
<NormalTextField
text={title}
value={id}
onChange={x => setID(removeSpace(x))}
/>
{value !== undefined && (
<NormalTextField
text={valueTitle}
Expand Down
15 changes: 13 additions & 2 deletions src/smart/utils/IOFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SMARTWorkspace } from '../model/workspace';
import { textToMMEL } from '../serialize/MMEL';
import { LoggerInterface, OpenFileInterface } from './constants';
import { textToDoc } from './DocumentFunctions';
import { bsiToDocument } from './xml/BSIXML';
import { xmlToDocument } from './xml/XMLDocumentFunctions';

export interface FileTypeDescriptionInterface {
Expand All @@ -24,6 +25,7 @@ export enum FILE_TYPE {
Document = 'doc',
XML = 'xml',
CSV = 'csv',
BSI = 'bsi',
}

export const FileTypeDescription: Record<
Expand Down Expand Up @@ -69,6 +71,11 @@ export const FileTypeDescription: Record<
extension: 'csv',
openPrompt: 'Choose a CSV file to open',
},
[FILE_TYPE.BSI]: {
filtername: 'BSI XML files',
extension: 'xml',
openPrompt: 'Choose a BSI XML file to open',
},
};

// Open
Expand Down Expand Up @@ -122,15 +129,19 @@ export function handleDocumentOpen(props: {
setDocument: (doc: MMELDocument) => void;
useDecodedBlob?: Hooks.UseDecodedBlob;
requestFileFromFilesystem?: OpenFileInterface;
fileType: FILE_TYPE.Document | FILE_TYPE.XML;
fileType: FILE_TYPE.Document | FILE_TYPE.XML | FILE_TYPE.BSI;
}) {
const { setDocument, fileType } = props;
handleFileOpen({
...props,
type: fileType,
postProcessing: data =>
setDocument(
fileType === FILE_TYPE.Document ? textToDoc(data) : xmlToDocument(data)
fileType === FILE_TYPE.Document
? textToDoc(data)
: fileType === FILE_TYPE.XML
? xmlToDocument(data)
: bsiToDocument(data)
),
});
}
Expand Down
8 changes: 6 additions & 2 deletions src/smart/utils/ModelAddComponentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../model/editormodel';
import { ModelWrapper } from '../model/modelwrapper';
import { DataType } from '../serialize/interface/baseinterface';
import { findUniqueID } from './ModelFunctions';
import { capitalizeString, findUniqueID, trydefaultID } from './ModelFunctions';
import { NewComponentTypes } from './constants';
import {
createApproval,
Expand Down Expand Up @@ -61,7 +61,11 @@ export function addComponentToModel(
}

function newProcess(model: EditorModel, title?: string): EditorProcess {
const process = createProcess(findUniqueID('Process', model.elements));
const id =
title !== undefined
? trydefaultID(capitalizeString(title), model.elements)
: findUniqueID('Process', model.elements);
const process = createProcess(id);
if (title !== undefined) {
process.name = title;
}
Expand Down
9 changes: 9 additions & 0 deletions src/smart/utils/ModelFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ export function findUniqueID(prefix: string, ids: Record<string, MMELObject>) {
return name;
}

function capital(data: string): string {
return capital.length > 0 ? data[0].toUpperCase() + data.slice(1) : '';
}

export function capitalizeString(data: string): string {
const parts = data.split(/\s+/);
return parts.map(x => capital(x)).join('');
}

export function trydefaultID(name: string, ids: Record<string, MMELObject>) {
if (ids[name] !== undefined) {
return findUniqueID(name, ids);
Expand Down
Loading

0 comments on commit ecf6409

Please sign in to comment.