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
4 changes: 2 additions & 2 deletions client/config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ if (typeof window !== 'undefined') {
REACT_APP_WORKBENCHLINK_JUPYTERLAB: '/lab',
REACT_APP_WORKBENCHLINK_JUPYTERNOTEBOOK: '',

REACT_APP_CLIENT_ID: '1be55736756190b3ace4c2c4fb19bde386d1dcc748d20b47ea8cfb5935b8446c',
REACT_APP_AUTH_AUTHORITY: 'https://gitlab.com/',
REACT_APP_CLIENT_ID: '38bf4764fad5ebb2ebbf49b4f57c7720145b61266f13bf4891ff7851dd5c6563',
REACT_APP_AUTH_AUTHORITY: 'https://maestro.cps.digit.au.dk/gitlab',
REACT_APP_REDIRECT_URI: 'http://localhost:4000/Library',
REACT_APP_LOGOUT_REDIRECT_URI: 'http://localhost:4000/',
REACT_APP_GITLAB_SCOPES: 'openid profile read_user read_repository api',
Expand Down
6 changes: 6 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@
"@emotion/styled": "^11.11.0",
"@fontsource/roboto": "^5.0.8",
"@gitbeaker/rest": "^40.1.2",
"@monaco-editor/react": "^4.6.0",
"@mui/icons-material": "^5.14.8",
"@mui/material": "^5.14.8",
"@mui/x-tree-view": "^7.19.0",
"@reduxjs/toolkit": "^1.9.7",
"@types/react-syntax-highlighter": "^15.5.13",
"@types/remarkable": "^2.0.8",
"@types/styled-components": "^5.1.32",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
Expand All @@ -76,8 +80,10 @@
"react-redux": "^8.1.3",
"react-router-dom": "^6.20.0",
"react-scripts": "^5.0.1",
"react-syntax-highlighter": "^15.5.0",
"react-tabs": "^6.0.2",
"redux": "^4.2.1",
"remarkable": "^2.0.1",
"resize-observer-polyfill": "^1.5.1",
"serve": "^14.2.1",
"styled-components": "^6.1.1",
Expand Down
28 changes: 22 additions & 6 deletions client/src/preview/components/asset/AssetBoard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';
import { Grid } from '@mui/material';
import { useSelector } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import { RootState } from 'store/store';
import AssetCardExecute from './AssetCard';
import { deleteAsset } from 'preview/store/assets.slice';
import { AssetCardExecute, AssetCardManage } from './AssetCard';
import { Asset } from './Asset';

const outerGridContainerProps = {
Expand All @@ -24,7 +25,8 @@ interface AssetBoardProps {
const AssetGridItem: React.FC<{
asset: Asset;
tab: string;
}> = ({ asset }) => (
onDelete: (path: string) => void;
}> = ({ asset, tab, onDelete }) => (
<Grid
key={asset.path}
item
Expand All @@ -34,21 +36,35 @@ const AssetGridItem: React.FC<{
lg={3}
sx={{ minWidth: 250 }}
>
<AssetCardExecute asset={asset} />
{tab === 'Execute' ? (
<AssetCardExecute asset={asset} />
) : (
<AssetCardManage asset={asset} onDelete={() => onDelete(asset.path)} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also "details" and "reconfigure" buttons. Why are they treated differently from delete button?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The onDelete function is passed exclusively to AssetCardManage, which includes the Delete button. This is because it is the only button that, in addition to having an API call via gitlabDigitalTwin, must also modify the store via dispatch with the deleteAsset function.

)}
</Grid>
);

const AssetBoard: React.FC<AssetBoardProps> = ({ tab, error }) => {
const assets = useSelector((state: RootState) => state.assets.items);
const dispatch = useDispatch();

const handleDelete = (deletedAssetPath: string) => {
dispatch(deleteAsset(deletedAssetPath));
};

if (error) {
return <em style={{ textAlign: 'center' }}>{error}</em>;
}

return (
<Grid {...outerGridContainerProps}>
{assets.map((asset: Asset) => (
<AssetGridItem key={asset.path} asset={asset} tab={tab} />
{assets.map((asset) => (
<AssetGridItem
key={asset.path}
asset={asset}
tab={tab}
onDelete={handleDelete}
/>
))}
</Grid>
);
Expand Down
78 changes: 77 additions & 1 deletion client/src/preview/components/asset/AssetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,34 @@ import { useSelector } from 'react-redux';
import { selectDigitalTwinByName } from 'preview/store/digitalTwin.slice';
import { RootState } from 'store/store';
import LogDialog from 'preview/route/digitaltwins/execute/LogDialog';
import DetailsDialog from 'preview/route/digitaltwins/manage/DetailsDialog';
import ReconfigureDialog from 'preview/route/digitaltwins/manage/ReconfigureDialog';
import DeleteDialog from 'preview/route/digitaltwins/manage/DeleteDialog';
import StartStopButton from './StartStopButton';
import LogButton from './LogButton';
import { Asset } from './Asset';
import DetailsButton from './DetailsButton';
import ReconfigureButton from './ReconfigureButton';
import DeleteButton from './DeleteButton';

interface AssetCardProps {
asset: Asset;
buttons?: React.ReactNode;
}

interface AssetCardManageProps {
asset: Asset;
buttons?: React.ReactNode;
onDelete: () => void;
}

interface CardButtonsContainerManageProps {
assetName: string;
setShowDetails: Dispatch<SetStateAction<boolean>>;
setShowReconfigure: Dispatch<SetStateAction<boolean>>;
setShowDelete: Dispatch<SetStateAction<boolean>>;
}

interface CardButtonsContainerExecuteProps {
assetName: string;
setShowLog: Dispatch<SetStateAction<boolean>>;
Expand Down Expand Up @@ -67,6 +86,21 @@ function CardActionAreaContainer(asset: Asset) {
);
}

function CardButtonsContainerManage({
assetName,
setShowDetails,
setShowReconfigure,
setShowDelete,
}: CardButtonsContainerManageProps) {
return (
<CardActions style={{ justifyContent: 'flex-end' }}>
<DetailsButton assetName={assetName} setShowLog={setShowDetails} />
<ReconfigureButton setShowReconfigure={setShowReconfigure} />
<DeleteButton setShowLog={setShowDelete} />
</CardActions>
);
}

function CardButtonsContainerExecute({
assetName,
setShowLog,
Expand Down Expand Up @@ -105,6 +139,48 @@ function AssetCard({ asset, buttons }: AssetCardProps) {
);
}

function AssetCardManage({ asset, onDelete }: AssetCardManageProps) {
const [showDetailsLog, setShowDetailsLog] = useState(false);
const [showDeleteLog, setShowDeleteLog] = useState(false);
const [showReconfigure, setShowReconfigure] = useState(false);
const digitalTwin = useSelector(selectDigitalTwinByName(asset.name));

return (
digitalTwin && (
<>
<AssetCard
asset={asset}
buttons={
<CardButtonsContainerManage
assetName={asset.name}
setShowDelete={setShowDeleteLog}
setShowDetails={setShowDetailsLog}
setShowReconfigure={setShowReconfigure}
/>
}
/>
<CustomSnackbar />
<DetailsDialog
showLog={showDetailsLog}
setShowLog={setShowDetailsLog}
name={asset.name}
/>
<ReconfigureDialog
showLog={showReconfigure}
setShowLog={setShowReconfigure}
name={asset.name}
/>
<DeleteDialog
showLog={showDeleteLog}
setShowLog={setShowDeleteLog}
name={asset.name}
onDelete={onDelete}
/>
</>
)
);
}

function AssetCardExecute({ asset }: AssetCardProps) {
useState<AlertColor>('success');
const [showLog, setShowLog] = useState(false);
Expand Down Expand Up @@ -133,4 +209,4 @@ function AssetCardExecute({ asset }: AssetCardProps) {
);
}

export default AssetCardExecute;
export { AssetCardManage, AssetCardExecute };
26 changes: 26 additions & 0 deletions client/src/preview/components/asset/DeleteButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react';
import { Dispatch, SetStateAction } from 'react';
import { Button } from '@mui/material';

interface DeleteButtonProps {
setShowLog: Dispatch<React.SetStateAction<boolean>>;
}

const handleToggleLog = (setShowLog: Dispatch<SetStateAction<boolean>>) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of the function is unclear. The delete button is on Manage tab where there is no need for log dialogue.

Copy link
Contributor Author

@VanessaScherma VanessaScherma Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function has been renamed handleToggleDeleteDialog. Its purpose is to open the DeleteDialog component when the button is clicked.

setShowLog(true);
};

function DeleteButton({ setShowLog }: DeleteButtonProps) {
return (
<Button
variant="contained"
size="small"
color="primary"
onClick={() => handleToggleLog(setShowLog)}
>
Delete
</Button>
);
}

export default DeleteButton;
35 changes: 35 additions & 0 deletions client/src/preview/components/asset/DetailsButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react';
import { Dispatch, SetStateAction } from 'react';
import { Button } from '@mui/material';
import { useSelector } from 'react-redux';
import { selectDigitalTwinByName } from '../../store/digitalTwin.slice';
import DigitalTwin from '../../util/gitlabDigitalTwin';

interface DialogButtonProps {
assetName: string;
setShowLog: Dispatch<React.SetStateAction<boolean>>;
}

export const handleToggleLog = async (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it handleDetailsWindow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function has been renamed handleToggleDetailsDialog.

digitalTwin: DigitalTwin,
setShowLog: Dispatch<SetStateAction<boolean>>,
) => {
await digitalTwin.getFullDescription();
setShowLog(true);
};

function DetailsButton({ assetName, setShowLog }: DialogButtonProps) {
const digitalTwin = useSelector(selectDigitalTwinByName(assetName));
return (
<Button
variant="contained"
size="small"
color="primary"
onClick={() => handleToggleLog(digitalTwin, setShowLog)}
>
Details
</Button>
);
}

export default DetailsButton;
28 changes: 28 additions & 0 deletions client/src/preview/components/asset/ReconfigureButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react';
import { Button } from '@mui/material';
import { Dispatch, SetStateAction } from 'react';

interface ReconfigureButtonProps {
setShowReconfigure: Dispatch<SetStateAction<boolean>>;
}

const handleToggleReconfigure = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Reconfigure button is never inactive. The original html page and all the related React components are active in the background. Is there a need to deactivate the Details button. Perhaps you intend to use this click action to show README in which case the code structure and names have to reflect that intention?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function has been changed into handleToggleReconfigureDialog and it is used to open the ReconfigureDialog by clicking on the ReconfigureButton. Both the ReconfigureButton and the DetailsButton are never deactivated. If there are no files within the DT folder on GitLab, the ReconfigureDialog shows the empty SimpleTreeView (while maintaining the ‘Description’, ‘Lifecycle’, ‘Configuration’ sections). If there is no README.md, the DetailsDialog informs of the absence of that file within the GitLab folder. Is that what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An updated message: "There is no README.md file for the hello-world digital twin"

setShowReconfigure: Dispatch<SetStateAction<boolean>>,
) => {
setShowReconfigure((prev) => !prev);
};

function ReconfigureButton({ setShowReconfigure }: ReconfigureButtonProps) {
return (
<Button
variant="contained"
size="small"
color="primary"
onClick={() => handleToggleReconfigure(setShowReconfigure)}
>
Reconfigure
</Button>
);
}

export default ReconfigureButton;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import tabs from './DigitalTwinTabDataPreview';

export const createDTTab = (error: string | null): TabData[] =>
tabs
.filter((tab) => tab.label === 'Execute')
.filter((tab) => tab.label === 'Manage' || tab.label === 'Execute')
.map((tab) => ({
label: tab.label,
body: (
Expand Down
66 changes: 66 additions & 0 deletions client/src/preview/route/digitaltwins/editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as React from 'react';
import { useState } from 'react';
import { Box, Grid, Tabs, Tab } from '@mui/material';
// import { Resizable } from 'react-resizable';
import EditorTab from './EditorTab';
import PreviewTab from './PreviewTab';
import Sidebar from './Sidebar';

interface EditorProps {
DTName: string;
}

function Editor({ DTName }: EditorProps) {
const [activeTab, setActiveTab] = useState(0);
const [fileName, setFileName] = useState('');
const [fileContent, setFileContent] = useState('');
const [fileType, setFileType] = useState('');

const handleTabChange = (event: React.SyntheticEvent, newValue: number) => {
setActiveTab(newValue);
};

return (
<Box sx={{ display: 'flex', height: '100%', width: '100%' }}>
<Sidebar
name={DTName}
setFileName={setFileName}
setFileContent={setFileContent}
setFileType={setFileType}
/>

<Grid container direction="column" sx={{ flexGrow: 1, padding: 2 }}>
<Tabs
value={activeTab}
onChange={handleTabChange}
aria-label="editor preview tabs"
>
<Tab label="Editor" />
<Tab label="Preview" />
</Tabs>

<Box
sx={{
flexGrow: 1,
padding: 2,
border: '1px solid lightgray',
marginTop: 2,
}}
>
{activeTab === 0 && (
<EditorTab
fileName={fileName}
fileContent={fileContent}
setFileContent={setFileContent}
/>
)}
{activeTab === 1 && (
<PreviewTab fileContent={fileContent} fileType={fileType} />
)}
</Box>
</Grid>
</Box>
);
}

export default Editor;
Loading
Loading