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

Add 'Manage' tab to Digital Twins page preview #957

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Render images, tables and mathematical notation in DetailsDialog
  • Loading branch information
VanessaScherma committed Oct 8, 2024
commit 32a99148926d6740353f576be49c0c90c13db19a
2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.33.2",
"katex": "^0.16.11",
"oidc-client-ts": "^2.2.2",
"prop-types": "^15.8.1",
"react": "^18.2.0",
Expand All @@ -84,6 +85,7 @@
"react-tabs": "^6.0.2",
"redux": "^4.2.1",
"remarkable": "^2.0.1",
"remarkable-katex": "^1.2.1",
"resize-observer-polyfill": "^1.5.1",
"serve": "^14.2.1",
"styled-components": "^6.1.1",
Expand Down
30 changes: 29 additions & 1 deletion client/src/preview/route/digitaltwins/manage/DetailsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as React from 'react';
import { Dispatch, SetStateAction } from 'react';
import { Dialog, DialogContent, DialogActions, Button } from '@mui/material';
import { Remarkable } from 'remarkable';
import 'katex/dist/katex.min.css';
// @ts-expect-error: Ignoring TypeScript error due to missing type definitions for 'remarkable-katex'.
import RemarkableKatex from 'remarkable-katex';
import { useSelector } from 'react-redux';
import { selectDigitalTwinByName } from '../../../store/digitalTwin.slice';

Expand All @@ -17,10 +20,11 @@ const handleCloseLog = (setShowLog: Dispatch<SetStateAction<boolean>>) => {

function DetailsDialog({ showLog, setShowLog, name }: DetailsDialogProps) {
const digitalTwin = useSelector(selectDigitalTwinByName(name));

const md = new Remarkable({
html: true,
typographer: true,
});
}).use(RemarkableKatex);

return (
<Dialog open={showLog} maxWidth="md">
Expand All @@ -29,13 +33,37 @@ function DetailsDialog({ showLog, setShowLog, name }: DetailsDialogProps) {
dangerouslySetInnerHTML={{
__html: md.render(digitalTwin.fullDescription),
}}
style={{
maxWidth: '100%',
}}
/>
</DialogContent>
<DialogActions>
<Button onClick={() => handleCloseLog(setShowLog)} color="primary">
Close
</Button>
</DialogActions>
<style>{`
img {
max-width: 100%;
height: auto;
display: block;
margin: 0 auto;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
border: 1px solid #ccc;
padding: 8px;
text-align: left;
}
th {
background-color: #f0f0f0;
}
`}</style>
</Dialog>
);
}
Expand Down
8 changes: 7 additions & 1 deletion client/src/preview/util/gitlabDigitalTwin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getAuthority } from 'util/envUtil';
import GitlabInstance from './gitlab';

const RUNNER_TAG = 'linux';
Expand Down Expand Up @@ -38,20 +39,25 @@ class DigitalTwin {
async getFullDescription(): Promise<void> {
if (this.gitlabInstance.projectId) {
const readmePath = `digital_twins/${this.DTName}/README.md`;
const imagesPath = `digital_twins/${this.DTName}/`; // Path per le immagini
try {
const fileData = await this.gitlabInstance.api.RepositoryFiles.show(
this.gitlabInstance.projectId,
readmePath,
'main',
);
this.fullDescription = atob(fileData.content);
this.fullDescription = atob(fileData.content).replace(/(!\[[^\]]*\])\(([^)]+)\)/g, (match, altText, imagePath) => {
const fullUrl = `${getAuthority()}/dtaas/${sessionStorage.getItem('username')}/-/raw/main/${imagesPath}${imagePath}`;
return `${altText}(${fullUrl})`;
});
} catch (error) {
this.fullDescription = `There is no README.md file in the ${this.DTName} GitLab folder`;
}
} else {
this.fullDescription = 'Error fetching description, retry.';
}
}


isValidInstance(): boolean {
return !!(
Expand Down
Loading