Skip to content

Commit

Permalink
Merge pull request #67 from paneron/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
wkwong-ribose authored Nov 12, 2021
2 parents 244a7df + c4ce859 commit 497b427
Show file tree
Hide file tree
Showing 35 changed files with 281 additions and 257 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paneron/extension-hls",
"version": "1.0.0-dev15",
"version": "1.0.0-dev16",
"description": "Paneron extension for SMART model editing",
"main": "plugin.js",
"repository": "https://github.com/paneron/extension-hls",
Expand Down Expand Up @@ -44,7 +44,7 @@
"@blueprintjs/select": "^3.17.0",
"@emotion/react": "^11.4.0",
"@emotion/styled": "^11.3.0",
"@riboseinc/paneron-extension-kit": "2.0.0-alpha17",
"@riboseinc/paneron-extension-kit": "2.0.0-alpha22",
"@types/node": "^14.11.2",
"@types/react": "16.9.49",
"@types/webpack-env": "^1.16.0",
Expand Down
12 changes: 4 additions & 8 deletions src/smart/ui/application/pas2060/ConfigurePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,10 @@ const EmissionItem: React.FC<{
onDelete: () => void;
overlapped: boolean;
}> = function ({ item, onChange, onDelete, index, overlapped }) {
const { useDecodedBlob, requestFileFromFilesystem } =
useContext(DatasetContext);
const { requestFileFromFilesystem } = useContext(DatasetContext);

function handleOpen() {
if (requestFileFromFilesystem && useDecodedBlob) {
if (requestFileFromFilesystem) {
requestFileFromFilesystem(
{
prompt: 'Choose a file to open',
Expand All @@ -147,11 +146,8 @@ const EmissionItem: React.FC<{
},
selectedFiles => {
const fileData = Object.values(selectedFiles ?? {})[0];
if (fileData) {
const fileDataAsString = useDecodedBlob({
blob: fileData,
}).asString;
const parsed = JSON.parse(fileDataAsString);
if (fileData && fileData['asText'] !== undefined) {
const parsed = JSON.parse(fileData['asText']);
const [minx, miny, minz] = (parsed.Polygon[0].Coordinates as string)
.split(' ')
.map(x => parseInt(x));
Expand Down
4 changes: 1 addition & 3 deletions src/smart/ui/edit/figure/FigureItemEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ const FigItemEditPage: React.FC<{
object: MMELFigure;
setObject: (obj: MMELFigure) => void;
}> = ({ object: fig, setObject: setFig }) => {
const { useDecodedBlob, requestFileFromFilesystem } =
useContext(DatasetContext);
const { requestFileFromFilesystem } = useContext(DatasetContext);

function loadImg() {
handleFileOpen({
useDecodedBlob,
requestFileFromFilesystem,
type: FILE_TYPE.IMG,
postProcessing: x => setFig({ ...fig, data: x }),
Expand Down
9 changes: 2 additions & 7 deletions src/smart/ui/edit/table/TableItemEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ const TableItemEditPage: React.FC<{
}> = ({ object: table, setObject: setTable }) => {
const [mode, setMode] = useState<TabType>('table');

const {
getBlob,
writeFileToFilesystem,
useDecodedBlob,
requestFileFromFilesystem,
} = useContext(DatasetContext);
const { getBlob, writeFileToFilesystem, requestFileFromFilesystem } =
useContext(DatasetContext);

function saveCSV() {
const fileData = table.data.map(row => row.join(',')).join('\n');
Expand All @@ -51,7 +47,6 @@ const TableItemEditPage: React.FC<{

function loadCSV() {
handleFileOpen({
useDecodedBlob,
requestFileFromFilesystem,
type: FILE_TYPE.CSV,
postProcessing: x => parseTable(x),
Expand Down
4 changes: 1 addition & 3 deletions src/smart/ui/maineditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,7 @@ const ModelEditor: React.FC<{
{...{ setModelWrapper, onMetaChanged, showMsg }}
modelwrapper={state.modelWrapper}
callback={dialogPack.callback}
cancel={() => {
setDialogType(null);
}}
cancel={() => setDialogType(null)}
repo={repo}
msg={dialogPack.msg}
/>
Expand Down
44 changes: 21 additions & 23 deletions src/smart/ui/mainmapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,31 +180,29 @@ const ModelMapper: React.FC<{
repoData !== undefined &&
!repoModelFile.isUpdating
) {
if (repo.ns !== mainRepo) {
const json = repoData as MMELJSON;
const model = JSONToMMEL(json);
const mw = createEditorModelWrapper(model);
indexModel(mw.model);
setImplProps({
...implementProps,
history: createPageHistory(mw),
modelWrapper: mw,
historyMap: buildHistoryMap(mw),
const json = repoData as MMELJSON;
const model = JSONToMMEL(json);
const mw = createEditorModelWrapper(model);
indexModel(mw.model);
setImplProps({
...implementProps,
history: createPageHistory(mw),
modelWrapper: mw,
historyMap: buildHistoryMap(mw),
});
if (mapData !== undefined && mapData !== null) {
const mapPro = mapData as MapProfile;
setMapProfile(mapPro);
} else {
setMapProfile({
'@context': JSONContext,
'@type': 'MMEL_MAP',
id: getNamespace(mw.model),
mapSet: {},
docs: {},
});
if (mapData !== undefined && mapData !== null) {
const mapPro = mapData as MapProfile;
setMapProfile(mapPro);
} else {
setMapProfile({
'@context': JSONContext,
'@type': 'MMEL_MAP',
id: getNamespace(mw.model),
mapSet: {},
docs: {},
});
}
setMainRepo(repo.ns);
}
setMainRepo(repo.ns);
}
}, [repoData, repoModelFile.isUpdating]);

Expand Down
3 changes: 1 addition & 2 deletions src/smart/ui/mainviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const ModelViewer: React.FC<{
linktoAnotherRepo: (x: MMELRepo) => void;
popHis?: () => void;
}> = ({ isVisible, className, repo, index, linktoAnotherRepo, popHis }) => {
const { logger, useObjectData, useDecodedBlob, requestFileFromFilesystem } =
const { logger, useObjectData, requestFileFromFilesystem } =
useContext(DatasetContext);
Logger.logger = logger;

Expand Down Expand Up @@ -459,7 +459,6 @@ const ModelViewer: React.FC<{
onClick={() =>
handleModelOpen({
setModelWrapper,
useDecodedBlob,
requestFileFromFilesystem,
logger,
indexModel: buildModelLinks,
Expand Down
5 changes: 1 addition & 4 deletions src/smart/ui/mapper/AutoMapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const AutoMapper: React.FC<{
mapProfile,
setMapProfile,
}) {
const { useDecodedBlob, requestFileFromFilesystem, logger } =
useContext(DatasetContext);
const { requestFileFromFilesystem, logger } = useContext(DatasetContext);

const [mw, setMW] = useState<ModelWrapper | undefined>(undefined);
const [mapping, setMapping] = useState<MapProfile | undefined>(undefined);
Expand All @@ -46,7 +45,6 @@ const AutoMapper: React.FC<{
async function handleOpenModel() {
handleModelOpen({
setModelWrapper: setMW,
useDecodedBlob,
requestFileFromFilesystem,
logger,
});
Expand All @@ -55,7 +53,6 @@ const AutoMapper: React.FC<{
async function handleOpenMapping() {
handleMappingOpen({
onMapProfileChanged: setMapping,
useDecodedBlob,
requestFileFromFilesystem,
});
}
Expand Down
4 changes: 1 addition & 3 deletions src/smart/ui/mapper/ModelDiagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ const ModelDiagram: React.FC<{
setRefRepo,
index,
}) => {
const { logger, useDecodedBlob, requestFileFromFilesystem } =
useContext(DatasetContext);
const { logger, requestFileFromFilesystem } = useContext(DatasetContext);

const modelType = modelProps.modelType;
const mw = modelProps.modelWrapper;
Expand Down Expand Up @@ -194,7 +193,6 @@ const ModelDiagram: React.FC<{
onClick={() => {
handleModelOpen({
setModelWrapper,
useDecodedBlob,
requestFileFromFilesystem,
logger,
indexModel,
Expand Down
1 change: 1 addition & 0 deletions src/smart/ui/mapper/document/ParagraphView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ParagraphView: React.FC<{
diffDocMap?: DocMapIndex;
MappingList?: React.FC<{ id: string }>;
setSelected?: (id: string) => void;
isHeader: boolean;
}> = function (props) {
const { para, showSection, statements, docMap, diffDocMap } = props;
return (
Expand Down
1 change: 1 addition & 0 deletions src/smart/ui/mapper/document/SectionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const SectionView: React.FC<{
para={para}
showSection={index === 0 ? sec.id : undefined}
title={sec.title ?? ''}
isHeader={sec.id === 'h'}
/>
))}
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/smart/ui/mapper/document/StatementView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const StatementView: React.FC<{
MappingList?: React.FC<{ id: string }>;
setSelected?: (id: string) => void;
title: string;
isHeader: boolean;
}> = function ({
statement,
showSection,
Expand All @@ -25,6 +26,7 @@ const StatementView: React.FC<{
MappingList,
setSelected,
title,
isHeader,
}) {
const [hover, setHover] = useState<boolean>(false);
const hasMap = froms !== undefined && froms.length > 0;
Expand Down Expand Up @@ -53,7 +55,11 @@ const StatementView: React.FC<{
const content =
(showSection !== undefined ? `${showSection}. ` : '') + statement.text;

return (
return isHeader ? (
<div style={{ textAlign: 'center' }}>
<h4>{statement.text}</h4>
</div>
) : (
<>
<span
style={{
Expand Down
6 changes: 1 addition & 5 deletions src/smart/ui/mapper/repo/RepoExternalFileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const RepoExternalFileMenu: React.FC<{
setDocument: (x: MMELDocument) => void;
setModelWrapper: (x: ModelWrapper) => void;
}> = function ({ setDocument, setModelWrapper }) {
const { useDecodedBlob, requestFileFromFilesystem } =
useContext(DatasetContext);
const { requestFileFromFilesystem } = useContext(DatasetContext);

return (
<Menu>
Expand All @@ -25,7 +24,6 @@ const RepoExternalFileMenu: React.FC<{
onClick={() => {
handleModelOpen({
setModelWrapper,
useDecodedBlob,
requestFileFromFilesystem,
indexModel,
});
Expand All @@ -36,7 +34,6 @@ const RepoExternalFileMenu: React.FC<{
onClick={() =>
handleDocumentOpen({
setDocument,
useDecodedBlob,
requestFileFromFilesystem,
fileType: FILE_TYPE.Document,
})
Expand All @@ -47,7 +44,6 @@ const RepoExternalFileMenu: React.FC<{
onClick={() =>
handleDocumentOpen({
setDocument,
useDecodedBlob,
requestFileFromFilesystem,
fileType: FILE_TYPE.XML,
})
Expand Down
12 changes: 3 additions & 9 deletions src/smart/ui/menu/EditorFileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@ const EditorFileMenu: React.FC<{
isRepoMode,
onRepoSave,
}) {
const {
logger,
getBlob,
useDecodedBlob,
writeFileToFilesystem,
requestFileFromFilesystem,
} = useContext(DatasetContext);
const { logger, getBlob, writeFileToFilesystem, requestFileFromFilesystem } =
useContext(DatasetContext);

const canOpen = requestFileFromFilesystem && useDecodedBlob;
const canOpen = requestFileFromFilesystem;
const canSave = getBlob && writeFileToFilesystem;

// Settings
Expand Down Expand Up @@ -90,7 +85,6 @@ const EditorFileMenu: React.FC<{
onClick={() =>
handleModelOpen({
setModelWrapper,
useDecodedBlob,
requestFileFromFilesystem,
logger,
})
Expand Down
9 changes: 2 additions & 7 deletions src/smart/ui/menu/EditorReferenceMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ const EditorReferenceMenu: React.FC<{
isRepo,
setType,
}) {
const { useDecodedBlob, requestFileFromFilesystem } =
useContext(DatasetContext);
const { requestFileFromFilesystem } = useContext(DatasetContext);

const canOpen = requestFileFromFilesystem && useDecodedBlob;
const canOpen = requestFileFromFilesystem;

const FileModelButton = () => (
<MenuItem
Expand All @@ -35,7 +34,6 @@ const EditorReferenceMenu: React.FC<{
onClick={() =>
handleModelOpen({
setModelWrapper: setReference,
useDecodedBlob,
requestFileFromFilesystem,
indexModel,
})
Expand All @@ -50,7 +48,6 @@ const EditorReferenceMenu: React.FC<{
onClick={() =>
handleDocumentOpen({
setDocument: setReference,
useDecodedBlob,
requestFileFromFilesystem,
fileType: FILE_TYPE.Document,
})
Expand All @@ -65,7 +62,6 @@ const EditorReferenceMenu: React.FC<{
onClick={() =>
handleDocumentOpen({
setDocument: setReference,
useDecodedBlob,
requestFileFromFilesystem,
fileType: FILE_TYPE.XML,
})
Expand All @@ -80,7 +76,6 @@ const EditorReferenceMenu: React.FC<{
onClick={() =>
handleDocumentOpen({
setDocument: setReference,
useDecodedBlob,
requestFileFromFilesystem,
fileType: FILE_TYPE.BSI,
})
Expand Down
4 changes: 1 addition & 3 deletions src/smart/ui/menu/MapperCompareMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ const MapperCompareMenu: React.FC<{
opponent: MapProfile | undefined;
setDiffMap: (x: MapProfile | undefined) => void;
}> = function ({ opponent, setDiffMap }) {
const { useDecodedBlob, requestFileFromFilesystem } =
useContext(DatasetContext);
const { requestFileFromFilesystem } = useContext(DatasetContext);

function onClick() {
handleMappingOpen({
onMapProfileChanged: setDiffMap,
useDecodedBlob,
requestFileFromFilesystem,
fileType: FILE_TYPE.JSON,
});
Expand Down
5 changes: 1 addition & 4 deletions src/smart/ui/menu/MapperDocumentMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { MMELDocument } from '../../model/document';
const MapperDocumentMenu: React.FC<{
setDocument: (x: MMELDocument) => void;
}> = function ({ setDocument }) {
const { useDecodedBlob, requestFileFromFilesystem } =
useContext(DatasetContext);
const { requestFileFromFilesystem } = useContext(DatasetContext);

return (
<Menu>
Expand All @@ -17,7 +16,6 @@ const MapperDocumentMenu: React.FC<{
onClick={() =>
handleDocumentOpen({
setDocument,
useDecodedBlob,
requestFileFromFilesystem,
fileType: FILE_TYPE.Document,
})
Expand All @@ -29,7 +27,6 @@ const MapperDocumentMenu: React.FC<{
onClick={() =>
handleDocumentOpen({
setDocument,
useDecodedBlob,
requestFileFromFilesystem,
fileType: FILE_TYPE.XML,
})
Expand Down
Loading

0 comments on commit 497b427

Please sign in to comment.