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 Create tab into Digital Twins page preview #1005

Open
wants to merge 14 commits into
base: feature/distributed-demo
Choose a base branch
from

Conversation

VanessaScherma
Copy link
Contributor

Title

Add Create tab into Digital Twins page preview

Type of Change

  • New feature
  • Bug fix
  • Documentation update
  • Refactoring
  • Security patch
  • UI/UX improvement

Description

PR with the aim of solving issue #1002.

When opening, the Create page shows the Editor and three files already placed in the sidebar:

  • description.md
  • README.md
  • .gitlab-ci.yml

The user can:

  • insert a new file via the ‘Add new file’ button (it is not possible to insert files with the same name, but the extension can be different)
  • delete a file (either inserted by him or one of the predefined ones, but it is not possible to delete .gitlab-ci.yml as it is necessary for the execution of the DT)
  • rename a file inserted by him

By clicking on the ‘Create’ button, the user can enter the name of the DT, which will correspond to the name of the sub-folder within his GitLab digitaltwins folder, and confirm the operation.
At the end of the operation, the Snackbar informs of success or failure.

By switching to one of the other tabs, the DT is already visible.

Testing

Unit and integration tests are currently in progress.

Impact

These changes add a new functionality, allowing the user to insert new digital twins.

Additional Information

None.

Checklist

  • My code adheres to the coding and style guidelines of the project.
  • I have added tests for all the new code and any changes made to
    existing code.
  • I have made corresponding changes to the documentation.

@prasadtalasila
Copy link
Contributor

@VanessaScherma Thanks for the PR. A very top-level review.

What works:

  1. Saving of skeletal DT in the gitlab repository

What does not work:

  1. The newly created DT does not show up in Manage and Execute pages
  2. The new DT is not shown even after restarting the client and also not after relogin

What are the suggested improvements:

  1. Have a field for name of DT
  2. Permit users to save DTs even if the files are empty

@VanessaScherma
Copy link
Contributor Author

@prasadtalasila

The DT created should be immediately visible within the page, as shown in these screenshots:
CreateDT
Snackbar
Manage
In the example shown, I created a digital twin called ‘testDT’, correctly created as informed by the Snackbar at the bottom of the page after confirming the save. As soon as I changed tabs to Manage, it was immediately visible.

Regarding suggestions, I can move the field for the DT name from the Dialog to above the Editor, so that it is always visible. For empty files, on the other hand, I had initially left this option but a problem had arisen with Editor Monaco. In fact, if the file is empty, the text shown on EditorTab cannot be updated, showing the contents of the previously selected file. This is probably due to the ‘read-only’ option I added to avoid writing without having selected a file first. I can look for some alternative solution if you think the possibility of creating empty files is more suitable.

@prasadtalasila
Copy link
Contributor

@VanessaScherma

In the example shown, I created a digital twin called ‘testDT’, correctly created as informed by the Snackbar at the bottom of the page after confirming the save. As soon as I changed tabs to Manage, it was immediately visible.

Strange. I've created two new DTs, namely "new-dt" and "new-digital-twin". But they don't show up in Manage and Execute tabs.

Regarding suggestions, I can move the field for the DT name from the Dialog to above the Editor, so that it is always visible.

Ok thanks

For empty files, on the other hand, I had initially left this option but a problem had arisen with Editor Monaco. In fact, if the file is empty, the text shown on EditorTab cannot be updated, showing the contents of the previously selected file. This is probably due to the ‘read-only’ option I added to avoid writing without having selected a file first. I can look for some alternative solution if you think the possibility of creating empty files is more suitable.

It is alright for now. Please focus on completing the PR.

Copy link

codeclimate bot commented Oct 28, 2024

Code Climate has analyzed commit 28c38a7 and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

View more on Code Climate.

Copy link
Contributor

@prasadtalasila prasadtalasila left a comment

Choose a reason for hiding this comment

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

@VanessaScherma Thanks for the updates. Broader suggestions are:

  1. The Execute and Manage pages refer to default branch while the create page refers to the main branch. Please make the create page refer to the default branch as well.
  2. When the tab is changed, the execution status of the DTs is lost. If it is easily doable, please retain the execution status including the waiting loop icon. Otherwise, skip it for now.
  3. The execution fails for a newly created DT
  4. Suggested text for different tabs in DigitalTwinTabDataPreview.ts is:
Create: Create and save new digital twins. The new digital twins are saved in the linked gitlab repository. Remember to add valid `.gitlab-ci.yml` configuration as it is used for execution of digital twin.

Manage: Explore, edit and delete existing digital twins. The changes get saved in the linked gitlab repository.

Execute: Execute existing digital twins using CI/CD pipelines of the linked gitlab repository. Availability of gitlab runners is required for execution of digital twins.

In addition, please see the comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

This file requires significant reorganization. Perhaps it is better to split it into two independent files/modules.

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 file was split in this way:

  • Sidebar.tsx: contains the Sidebar layout and the logic to manage the rendering of files
  • SidebarDialog.tsx: contains the dialog for adding a new file

dispatch(setDigitalTwin({ assetName: asset.name, digitalTwin }));
});
};

export const DTContent = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only creating new DT. Can this intent be made more clear with a restructuring of code?

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 purpose of this file has remained unchanged, I have only added the necessary logic for the Create page (the useState newDigitalTwinName) while I have moved the pre-existing logic in the function fetchAssetsAndCreateTwins to the AssetBoard, as it no longer has to be called up only when the main component (DigitalTwinsPreview) is opened, but each time an AssetBoard is rendered, i.e. when switching to the Manage or Execute tabs. This is necessary in order to allow the new DT to be displayed immediately after creation by switching to one of the aforementioned tabs.

Copy link
Contributor

Choose a reason for hiding this comment

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

The AssetBoard is a react component. It is better to move the actual logic out of it.

const dispatch = useDispatch();

const gitlabInstance = new GitlabInstance(
Copy link
Contributor

Choose a reason for hiding this comment

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

This code has been moved from DigitalTwinsPreview.tsx to here. The non-react part of code belongs to some file in preview/util module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has been moved to init.ts in preview/util.

Copy link
Contributor

Choose a reason for hiding this comment

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

File handling relates to operations on gitlab repo from frontend. Perhaps separating all the file handling operations into one module, say util/File.ts helps with modularity of the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Functions with file-related operations have been moved to file.ts in preview/util.

client/src/preview/util/gitlabDigitalTwin.ts Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

The broader problem I see is this.
We need the user to forget the existence of gitlab but understand DT abstraction. In addition, user knows (rightly) that a DT consists of multiple files including configuration file(s). Thus we need to have a dedicated code for modifying files which can be accessed by DT class and if needed gitlab class. The code dependency graph I see is:

DigitalTwin (create, reconfigure, execute) ---> GitlabInstance (files, commits, jobs etc)
         |                                                         |
         |----> Files (create, update, delete) <-------------------|

The Files code can be in preview/utils/

@@ -12,28 +14,132 @@ const filesSlice = createSlice({
name: 'files',
initialState,
reducers: {
addOrUpdateFile: (state, action: PayloadAction<FileState>) => {
addNewFile: (
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove duplication and restructure these three reducers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Now there is only the addOrUpdateFile reducer, capable to handle these three cases.

@prasadtalasila
Copy link
Contributor

The correct dependency graph is:

DigitalTwin (create, reconfigure, execute) ---> GitlabInstance (files, commits, jobs etc)
         |                                                        ^
         |                                                        |
         |----> Files (create, update, delete) -------------------|

You can create an interface IFiles and then have both GitlabInstance and Files implement this interface.

@prasadtalasila
Copy link
Contributor

The current code structure requires addition of child pipeline in parent pipeline. Thus each new DT created must have an entry in top-level .gitlab-ci.yml. Otherwise, the execution of new DTs fails.

The solution is to have the create step has update the .gitlab-ci.yml at the root-level. Otherwise, the new DTs do not get executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants