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

feat(gsoc'24): Implemented LayoutElements Panel vue component #317

Merged
merged 16 commits into from
Sep 1, 2024

Conversation

niladrix719
Copy link
Member

@niladrix719 niladrix719 commented Jun 15, 2024

Fixes #108

Describe the changes you have made in this PR -

Created a Vue component out of LayoutElement Panel which was previously in the extra.vue file

  • moved all DOM manipulation to vue's reactives
  • moved all styles to scoped view

Screenshots of the changes (If any) -

Screen.Recording.2024-06-15.at.4.58.51.PM.mov

Summary by CodeRabbit

  • New Features

    • Introduced a new LayoutElementsPanel component for improved management and display of layout elements.
    • Enhanced user interaction with a draggable panel and expandable groups for subcircuit elements.
  • Localization

    • Added new translations for layout-related elements in Bengali, English, and Hindi, improving accessibility for users.
  • Bug Fixes

    • Improved state management for subcircuit elements, ensuring accurate display and interaction within the user interface.
  • Style

    • Removed outdated CSS class for the layout element panel, streamlining the styling process.

@niladrix719 niladrix719 marked this pull request as ready for review June 15, 2024 11:30
Copy link

netlify bot commented Jun 15, 2024

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit aa95b42
🔍 Latest deploy log https://app.netlify.com/sites/circuitverse/deploys/66d48da047f6fd0008f26361
😎 Deploy Preview https://deploy-preview-317--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@niladrix719 niladrix719 added the GSOC'24 PR's for GSoC'24 label Jul 25, 2024
@vedant-jain03
Copy link
Member

@niladrix719 can you check the failed tests?

Copy link
Member

@Arnabdaz Arnabdaz left a comment

Choose a reason for hiding this comment

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

fix the dropdown and icons not showing up
you can take reference from the circuit element panel

@vedant-jain03
Copy link
Member

@niladrix719 are you sure you take care of :

fix the dropdown and icons not showing up
you can take reference from the circuit element panel

Copy link
Member

@Arnabdaz Arnabdaz left a comment

Choose a reason for hiding this comment

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

  • dropdown is not working
    image

  • labels are getting removed when we drag the element in canvas in layout mode
    should be like below image:
    image

Copy link
Contributor

coderabbitai bot commented Sep 1, 2024

Walkthrough

The changes involve a significant restructuring of the Vue components and localization files. A new component, LayoutElementsPanel, has been introduced to enhance the management of layout elements. Additionally, localization files for Bengali, English, and Hindi have been updated with new keys related to layout elements. The state management system has been refined, and several properties related to circuit dialogs have been removed from the state interface.

Changes

Files Change Summary
src/components/Extra.vue Replaced layout element panel markup with <LayoutElementsPanel /> component; added import statement.
src/components/Panels/LayoutElementsPanel/LayoutElementsPanel.vue Introduced new component for managing layout elements; implemented draggable panels and expandable groups.
src/locales/*.json Added new keys related to layout elements and translations for Bengali, English, and Hindi.
src/simulator/src/ux.js Modified fillSubcircuitElements function to integrate new state management approach.
src/store/SimulatorStore/state.ts Updated State interface by removing dialog properties and adding subCircuitElementList properties.
src/styles/css/main.stylesheet.css Removed .layoutElementPanel class definition from the stylesheet.

Assessment against linked issues

Objective Addressed Explanation
New eslint parser to support TypeScript (#108)
Replace eslint-plugin-vue with vue-eslint-parser
Convert arrayHelpers.js to arrayHelpers.ts

🐇
In the meadow, changes bloom,
Panels now dance, dispelling gloom.
With elements laid out, neat and bright,
Localization brings new words to light.
Hooray for code, oh what a delight! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Member

@Arnabdaz Arnabdaz left a comment

Choose a reason for hiding this comment

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

Nice work 👍

@Arnabdaz Arnabdaz merged commit 051c32a into CircuitVerse:main Sep 1, 2024
9 checks passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (3)
src/store/SimulatorStore/state.ts (2)

33-34: Consider removing isEmptySubCircuitElementList and using subCircuitElementList.length === 0 instead.

The addition of subCircuitElementList to manage sub-circuits is approved. However, the isEmptySubCircuitElementList property can be derived from subCircuitElementList and may not be necessary.

Apply this diff to remove isEmptySubCircuitElementList:

 export interface State {
   ...
   subCircuitElementList: Array<LayoutElementGroup>
-  isEmptySubCircuitElementList: boolean
 }

Then, replace all occurrences of isEmptySubCircuitElementList with subCircuitElementList.length === 0 in the codebase.


37-39: Use a more specific type for elements if possible.

The addition of the LayoutElementGroup interface is approved. However, consider using a more specific type for the elements property instead of any[] to enable type checking and improve code quality.

If a more specific type is not available, consider adding a TODO comment to revisit this later:

 interface LayoutElementGroup {
   type: string
-  elements: any[]
+  elements: any[] // TODO: Use a more specific type
 }
src/simulator/src/ux.js (1)

17-18: LGTM! Consider adding a comment to explain the purpose of the SimulatorStore import.

The code changes are approved. The new import statements suggest that a state management system using the Vue composition API is being introduced. To improve code readability and maintainability, consider adding a comment to explain the purpose of the SimulatorStore import.

+// Import the SimulatorStore to manage the state of the simulator using the Vue composition API
 import { SimulatorStore } from '#/store/SimulatorStore/SimulatorStore'
 import { toRefs } from 'vue'
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 129048f and aa95b42.

Files selected for processing (8)
  • src/components/Extra.vue (2 hunks)
  • src/components/Panels/LayoutElementsPanel/LayoutElementsPanel.vue (1 hunks)
  • src/locales/bn.json (1 hunks)
  • src/locales/en.json (1 hunks)
  • src/locales/hi.json (1 hunks)
  • src/simulator/src/ux.js (2 hunks)
  • src/store/SimulatorStore/state.ts (4 hunks)
  • src/styles/css/main.stylesheet.css (1 hunks)
Additional comments not posted (11)
src/store/SimulatorStore/state.ts (1)

72-73: LGTM! But remove isEmptySubCircuitElementList initialization if the property is removed.

The initializations are approved. However, if the isEmptySubCircuitElementList property is removed as suggested earlier, the initialization should also be removed:

 export const useState = defineStore({
   id: 'simulatorStore.state',
 
   state: (): State => {
     return {
       ...
       subCircuitElementList: [],
-      isEmptySubCircuitElementList: true,
     }
   },
 })
src/components/Panels/LayoutElementsPanel/LayoutElementsPanel.vue (1)

1-34: Review of the Template Section

The template section of the Vue component is well-structured and makes good use of Vue's reactivity and internationalization features. Here are some specific observations:

  1. Internationalization Usage: The use of $t for translating text is appropriate and follows best practices for supporting multiple languages.
  2. Dynamic Classes and Refs: The use of dynamic classes and refs like layoutElementPanelRef is correctly implemented.
  3. Event Handling: The @mousedown event on line 20 is correctly attached to initiate the drag operation.

However, there are a couple of areas that could be improved:

  • Accessibility: Consider adding aria-labels to interactive elements like buttons for better accessibility.
  • Event Naming: The event handler dragElement could be renamed to something more descriptive like handleDragStart to clarify its purpose.

Overall, the template section is functionally sound and adheres to Vue's best practices.

src/locales/bn.json (2)

12-15: Translations for layout elements are correct.

The translations for "layout_elements" and "no_elements_available" are correctly added and seem appropriate for the intended usage.


16-16: Translation for 'unlabeled' is correct.

The translation for "unlabeled" is correctly added and is a direct transliteration of the English word into Bengali script, which may be appropriate depending on the context.

src/locales/en.json (2)

12-15: New Localization Keys for Layout Elements

The addition of "layout", "layout_elements", and "no_elements_available" keys under the "layout" object is appropriate and aligns with the PR's objectives to enhance layout management features. These keys are well-placed within the JSON structure, ensuring they are logically grouped under the relevant section.


16-16: Review Placement of the 'Unlabeled' Key

The "unlabeled" key is added outside the "layout" object. If this key is intended to be used globally across different components, its placement is correct. However, if it's specifically related to layout elements, consider nesting it within the "layout" object for better logical grouping.

Please confirm the intended use of the "unlabeled" key to ensure its placement aligns with its usage.

src/locales/hi.json (1)

12-16: Approved: New localization entries added.

The changes introduce new keys for layout-related elements in the Hindi localization file. The JSON structure is correct, and the keys are appropriately nested. Ensure the translations are accurate and contextually appropriate.

src/components/Extra.vue (2)

163-163: Verify the import path for LayoutElementsPanel.

The import statement for LayoutElementsPanel is crucial for the functionality of the newly modularized component. Ensure that the path './Panels/LayoutElementsPanel/LayoutElementsPanel.vue' correctly points to the component file. This is important for maintaining the integrity of the component imports and avoiding runtime errors due to missing files.

Verification successful

Import path for LayoutElementsPanel is correct.

The file LayoutElementsPanel.vue exists at the specified path, confirming that the import statement in src/components/Extra.vue is accurate. No issues were found with the import path.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the LayoutElementsPanel component file.

# Test: Check if the file exists. Expect: File should exist.
fd 'LayoutElementsPanel.vue' 'src/components/Panels/LayoutElementsPanel'

Length of output: 136


19-19: Review integration of <LayoutElementsPanel /> component.

The integration of the <LayoutElementsPanel /> component into the template is a significant change aimed at enhancing modularity. It is important to ensure that this component is correctly integrated without any missing props or event bindings that might have been part of the original layout element panel. Additionally, verify that the scoped styles in the new component do not conflict with global styles, ensuring a seamless UI integration.

src/simulator/src/ux.js (1)

442-476: LGTM!

The code changes are approved. The refactoring of the fillSubcircuitElements function to use the Vue composition API and the SimulatorStore for state management is a significant improvement in terms of code clarity, maintainability, and readability. The changes reflect a transition from imperative DOM manipulation to a declarative state management model, which is a best practice in modern web development.

Some of the key improvements include:

  • Initializing the state variables subCircuitElementList and isEmptySubCircuitElementList from the simulatorStore ensures a consistent initial state.
  • Populating the subcircuitElements array with elementGroup objects provides a more structured and readable approach compared to the previous implementation.
  • Updating the final state of subCircuitElementList and isEmptySubCircuitElementList based on the subcircuitElements array and whether any elements were found is a clear and concise way to manage the state.

Overall, the changes align with the best practices for state management in Vue applications and enhance the maintainability and scalability of the codebase.

src/styles/css/main.stylesheet.css (1)

Line range hint 1-1000: Review of CSS Changes: Removal of .layoutElementPanel

The removal of the .layoutElementPanel class from the stylesheet is a significant change. This class previously managed layout and visibility aspects of certain UI elements. Given the PR's context, this removal is likely intentional to shift styling responsibilities to Vue's scoped styles for better encapsulation and maintainability.

Action Required:

  1. Verify the Integration with Vue Scoped Styles: Ensure that the Vue component responsible for the layout elements now includes scoped styles that adequately replace the removed CSS rules. This is crucial for maintaining the UI's appearance and functionality.
  2. Check for Unused Styles: Since the .layoutElementPanel class has been removed, verify that there are no lingering CSS selectors in the stylesheet that attempt to modify elements using this class, as they would no longer have any effect.

Additional Observations:

  • The stylesheet includes a variety of global styles and specific component styles. It's important to ensure that these styles do not conflict with the new Vue component styles.
  • The use of @import statements at the beginning of the file suggests dependencies on other stylesheets. Confirm that these dependencies are still relevant and that the imported styles do not conflict with the new component styles.

Recommendation:

  • Conduct a Thorough Testing: Given the significant changes in styling strategy, it's recommended to perform thorough testing of the UI, especially the components affected by the removal of the .layoutElementPanel class. This includes checking the responsive behavior and cross-browser compatibility to ensure that the UI remains consistent across different environments.

Comment on lines +36 to +83
<script lang="ts" setup>
import { useState } from '#/store/SimulatorStore/state'
import { simulationArea } from '#/simulator/src/simulationArea'
import { useLayoutStore } from '#/store/layoutStore';
import { ref, onMounted } from 'vue';

const layoutStore = useLayoutStore()

const layoutElementPanelRef = ref<HTMLElement | null>(null);

onMounted(() => {
layoutStore.layoutElementPanelRef = layoutElementPanelRef.value
})

const SimulatorState = useState();

const dragElement = (groupType: string, element: any, index: number) => {
element.subcircuitMetadata.showInSubcircuit = true
element.newElement = true
simulationArea.lastSelected = element

// Remove the element from subCircuitElementList
SimulatorState.subCircuitElementList.forEach((typeGroup) => {
typeGroup.elements = typeGroup.elements.filter(
(_, elementIndex) => {
if(typeGroup.type === groupType && index === elementIndex)
return false

return true;
}
)
})

// Remove the type group if its elements array is empty
SimulatorState.subCircuitElementList =
SimulatorState.subCircuitElementList.filter(
(typeGroup) => typeGroup.elements.length > 0
)
}

function getImgUrl(elementName: string) {
const elementImg = new URL(
`../../../simulator/src/img/${elementName}.svg`,
import.meta.url
).href;
return elementImg;
}
</script>
Copy link
Contributor

Choose a reason for hiding this comment

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

Review of the Script Section

The script section is well-organized and makes effective use of Vue's composition API and TypeScript. Here are some detailed observations:

  1. TypeScript Usage: The use of TypeScript for type safety is evident and beneficial, especially in a complex component like this.
  2. Reactive References: The setup of reactive references such as layoutElementPanelRef and their usage in lifecycle hooks (e.g., onMounted) is correctly implemented.
  3. Function Implementation:
    • The dragElement function on lines 52-74 handles the logic for dragging elements and updating the state accordingly. However, the logic inside this function is quite complex and could benefit from further decomposition or comments for clarity.
    • The getImgUrl function on lines 76-82 is a utility function that constructs URLs for images. The use of URL and import.meta.url is appropriate for this purpose.

Suggestions:

  • Refactor dragElement for Clarity: Consider breaking down the dragElement function into smaller, more manageable functions. This can improve readability and maintainability.
  • Add Comments: Adding comments to complex logic within dragElement would help other developers understand the code more quickly.

Overall, the script section is robust, but minor improvements could enhance its clarity and maintainability.

Comment on lines +85 to +94
<style scoped>

.layoutElementPanel {
width: 220px;
font: inherit;
display: none;
top: 90px;
left: 10px;
}
</style>
Copy link
Contributor

Choose a reason for hiding this comment

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

Review of the Style Section

The scoped style section is concise and targets the .layoutElementPanel class specifically. Here are some observations:

  1. Scoped Styles: The use of scoped styles is a best practice in Vue components to prevent CSS rules from affecting other parts of the application.
  2. CSS Properties: The properties set for .layoutElementPanel are appropriate for a draggable panel, including its positioning and display settings.

Suggestions:

  • Responsiveness: Consider adding media queries to ensure that the panel is responsive and displays correctly on different screen sizes.

Overall, the style section is well-implemented, but adding responsiveness could improve the component's usability across different devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GSOC'24 PR's for GSoC'24
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Identify and fix all existing bugs & Complete the implementation of any remaining simulator components.
3 participants