Open KobyFowler opened 1 month ago
I endorse this issue!
// In Selection.js
// Before Refactor
addSelectionAttributes(selectable) {
if (selectable[0] && selectable[0].element) {
selectable[0].element.setAttribute('s-selected', '');
}
if (selectable[1] && selectable[1].element) {
selectable[1].element.setAttribute('s-selected-parent', '');
}
}
// After Refactor
class DomManipulator {
addSelectionAttributes(selectable) {
if (selectable[0] && selectable[0].element) {
selectable[0].element.classList.add('selected');
}
if (selectable[1] && selectable[1].element) {
selectable[1].element.classList.add('selected-parent');
}
}
removeSelectionAttributes(selectable) {
if (selectable[0] && selectable[0].element) {
selectable[0].element.classList.remove('selected');
}
if (selectable[1] && selectable[1].element) {
selectable[1].element.classList.remove('selected-parent');
}
}
}
// Step 2: Modify Selection.js to Use DomManipulator:
class Selection {
constructor(openmct, domManipulator) {
this.openmct = openmct;
this.domManipulator = domManipulator;
}
// Instead of handling DOM directly
select(selectable) {
this.domManipulator.addSelectionAttributes(selectable);
// Other selection logic
}
deselect(selectable) {
this.domManipulator.removeSelectionAttributes(selectable);
// Other deselection logic
}
}
@KobyFowler @WavesJ99,
Thank you both for the suggestion! I have a few follow-up questions and comments:
Looking forward to your thoughts!
Hey Jesse! @ozyx I hope to answer your questions:
Thanks for the info @WavesJ99 !
Sounds like a cool class. Is there a requirement to get your changes merged into the codebase? If so, what is your timeline on when you need to get this done? I ask because to contribute to this repository you'll need to submit a CLA. The CLA approval process can take a variable amount of time, sometimes quite a long time.
If that's not an issue, I can help you find something in our backlog that you could contribute which meets the criteria. That way you'll not only be completing your project requirements, but you'll be directly helping a NASA project!
Let me know what you think and if it's feasible given the CLA timeline and requirements.
Thanks for the response @ozyx
We aren't required to have the changes merged just to create our first PR. I also ensured my whole team submitted the CLA, but we understand that may take some time. It would be amazing if you could point us in the direction of something in the backlog that needs to be worked on. The focus of the class is Software architecture so I believe we have to try and find an improvement we can make within the architecture.
We are working our way through a new version of updating this class to continue the first PR for the assignments sake but would love if you could point us in the direction of other work that might be better for us to work on.
Again thank you for the responses we are more than excited get in contact with you and start contributing to the repo.
@WavesJ99
We aren't required to have the changes merged just to create our first PR.
In that case, why don't you and your team continue on the same path and I can help guide you? Making an architectural change to such a long-standing app won't be easy, but at the very least you can gain some experience contributing to the open source and interacting with open source maintainers.
Whenever you're ready, feel free to open your PR (as a draft). Make sure that you are working off of a branch on your fork. Our dialogue can continue there.
I also ensured my whole team submitted the CLA, but we understand that may take some time.
Awesome!
Is your feature request related to a problem? Please describe.
Violation of SRP and tight coupling that could be solved.
Describe the solution you'd like
Introduces a separation of concerns by extracting DOM manipulation logic into a dedicated DomManipulator class. This approach centralizes the responsibility for managing selection-related DOM attributes, making the code more modular and easier to maintain. The DomManipulator class provides methods for adding and removing selection attributes, using classList for better performance and flexibility. The Selection class is then modified to use an instance of DomManipulator, delegating DOM operations to this specialized class. This refactoring improves the structure by isolating DOM interactions, potentially making the code easier to test and modify in the future. It also provides a clear interface for selection-related DOM operations, which could be extended or modified more easily as requirements change.
Describe alternatives you've considered
We could create a SelectableDecorator that wraps the selectable objects and adds methods for managing their selection state. This decorator would encapsulate the DOM manipulation logic within each selectable object, allowing for more flexibility and potentially easier testing of individual components. This approach would keep the selection logic close to the objects being selected, which could be beneficial if different types of selectables need different selection behaviors in the future.
Additional context
Code change will occur in src/selection/Selection.js
Code solution provided by @WavesJ99