-
Notifications
You must be signed in to change notification settings - Fork 0
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
- [FP-2787](https://movai.atlassian.net/browse/FP-2787): IDE - Topics - Can't open multiple Topics tabs #323
Conversation
quirinpa
commented
Jul 12, 2024
•
edited
Loading
edited
- FP-2787: IDE - Topics - Can't open multiple Topics tabs
- Notes:
- See this comment if you have any doubts
- Needs: https://github.com/MOV-AI/frontend-npm-ide/pull/594 (with updated lib-ide)
- Notes:
… - Can't open multiple Topics tabs
5924241
to
1af29ce
Compare
…t-open-multiple-topics-tabs
…t-open-multiple-topics-tabs
12e4776
to
72c9aeb
Compare
72c9aeb
to
da801f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at the Sonar issues pls
src/utils/generalFunctions.js
Outdated
const toolIdData = toolIds[toolName] ?? { last: 0, free: [] }; | ||
const id = toolIdData.free.shift() || toolIdData.last++; | ||
const tabData = { ...getToolTabData({ scope: toolName, id: toolName + "-" + id }, props) }; | ||
if (tabData.multiple) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming suggestion: multiple -> multipleTabs?
It's easy to know what it means when looking at it from the PR, but by the code itself, it's not that clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've talked about this. I think in the context we could agree it refers to tabs
return { | ||
id: id, | ||
rid: rid, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What rid stands for? realID? Might be good to rename it...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
realId, yes, but I think it isn't needed.
@@ -356,6 +356,16 @@ const useTabLayout = (props, dockRef) => { | |||
|
|||
// Remove tab and apply new layout | |||
tabsById.current.delete(tabId); | |||
const nid = new Number(tabId.substring(tabId.lastIndexOf("-") + 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is nId numberId? subID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numberId. Renamed
@@ -356,6 +356,16 @@ const useTabLayout = (props, dockRef) => { | |||
|
|||
// Remove tab and apply new layout | |||
tabsById.current.delete(tabId); | |||
const nid = new Number(tabId.substring(tabId.lastIndexOf("-") + 1)); | |||
if (!isNaN(nid)) { | |||
const toolIds = tabsById.current.get("toolIds"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to the PR, but We might want to rename tabsById -> tabsByIdRef. Without the ref it looks like we are talking about the "current tab"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I don't think this should be a ref, because a global would suffice. But done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls compute the toolId when loading the page
src/utils/generalFunctions.js
Outdated
tabData.name += "-" + id; | ||
tabData.title += "-" + id; | ||
} else | ||
tabData.id = toolName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be moved to getToolTabData?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The else part can but I don't think it should
A comment is missing. David asked to compute the toolIds object instead of loading from localStorage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I did this review BEFORE you went on vacation, and I kinda forgot to click submit review 🤦
I'm ok with this one as is :)
Good work 👍
@@ -627,6 +637,7 @@ const useTabLayout = (props, dockRef) => { | |||
if (!tabFromMemory && !data.content) return; | |||
const { | |||
id, | |||
rid, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're no longer using rid
, we can get rid of it (pun intended!) 😆
src/utils/generalFunctions.js
Outdated
function breakToolId(tabId) { | ||
const index = tabId.search(/\d/); | ||
const alpha = tabId.substring(0, index - 1); | ||
|
||
if (index < 0) | ||
return [alpha]; | ||
|
||
const number = new Number(tabId.substring(index)); | ||
|
||
return [alpha, number]; | ||
} | ||
|
||
function computeIds(tabsMap) { | ||
const res = {}; | ||
|
||
for (const [tabId] of tabsMap) { | ||
const [alpha, number] = breakToolId(tabId); | ||
const index = tabId.search(/\d/); | ||
if (index < 0) | ||
continue; | ||
const specific = res[alpha] ?? { last: 0, busy: {}, free: [] }; | ||
specific.busy[number] = 1; | ||
if (number > specific.last) | ||
specific.last = number; | ||
res[alpha] = specific; | ||
} | ||
|
||
for (const toolName in res) { | ||
const specific = res[toolName]; | ||
for (let j = 0; j < specific.last; j++) | ||
if (!specific.busy[j]) | ||
specific.free.push(j); | ||
delete specific.busy; | ||
specific.last++; | ||
} | ||
|
||
return res; | ||
} | ||
|
||
const workspace = new Workspace(); | ||
const tabsMap = workspace.getTabs(); | ||
const toolIds = computeIds(tabsMap); | ||
|
||
export function freeToolId(tabId) { | ||
const [alpha, number] = breakToolId(tabId); | ||
|
||
if (!number) | ||
return; | ||
|
||
const toolIdData = toolIds[alpha]; | ||
toolIdData.free.unshift(number); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually coming to review this again, I'm trying to understand this code, and looks so much more, less performant and more complex than what I did here in the src/utils/Utils.js
to achieve the same thing. Can you confirm @EdwardAngeles @quirinpa ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That only runs when the page loads.
It is to compute the things instead of using localStorage.
After the initial time it runs, it's pretty fast.
Faster than using local storage, for sure.
The fact that goes until the last number doesn't actually add a lot of overhead since we make sure to keep those numbers low. Even if we had 10000 tabs, We wouldn't see a lot of slowness when loading the page.
8b68ced
to
873e813
Compare
…t-open-multiple-topics-tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a couple of suggestions that may improve the code. Take a look and let me know if you have any questions or would like to do a small pair session.
tl;dr;
Overall, I like the logic of your thinking. I just think you made it harder to understand with generic, non-related naming in most vars and I don't think all this code belongs in this file.
src/utils/generalFunctions.js
Outdated
function computeIds(tabsMap) { | ||
const res = {}; | ||
|
||
/* get a map of this format: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get from where? Maybe you meant create?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are computing. But also creating.
I don't see this as a strong reason to hold the PR
src/utils/generalFunctions.js
Outdated
const index = tabId.search(/\d/); | ||
if (index < 0) | ||
continue; | ||
const specific = res[alpha] ?? { last: 0, busy: {}, free: [] }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is specific
? Maybe since we're doing this only for tool tabs, why not toolTab
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resulting object is not a tool tab. But indeed something specific to that tool.
src/utils/generalFunctions.js
Outdated
function breakToolId(tabId) { | ||
const index = tabId.search(/\d/); | ||
const alpha = tabId.substring(0, index - 1); | ||
|
||
if (index < 0) | ||
return [alpha]; | ||
|
||
const number = new Number(tabId.substring(index)); | ||
|
||
return [alpha, number]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You wouldn't need this entire function if you reused the multiple
property to be the tabIncrement
like per mine and @diasdm's suggestion. Since you're cycling through the tabs that come from localStorage
you'd have access to the entire tabData which includes the multiple
, or whatever name we call that property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems overly complicated when this simple function suffices perfectly.
src/utils/generalFunctions.js
Outdated
* to efficently organize tool ids. | ||
*/ | ||
function computeIds(tabsMap) { | ||
const res = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const res = {}; | |
const toolTabIncrementMap = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
res comes from "result". I don't think "toolTabIncrementMap is a good name.
src/utils/generalFunctions.js
Outdated
* } | ||
*/ | ||
for (const [tabId] of tabsMap) { | ||
const [alpha, number] = breakToolId(tabId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [alpha, number] = breakToolId(tabId); | |
const [toolName, tabIncrement] = breakToolId(tabId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you get rid of the breakToolId
function, you can use something like:
const {scope, tabIncrement} = tabData;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's a strong reason to modify what we're storing there.
A strange idea to be computing part, and using localStorage to store another part.
At least lets be consistent.
src/utils/generalFunctions.js
Outdated
const workspace = new Workspace(); | ||
const tabsMap = workspace.getTabs(); | ||
const toolIds = computeIds(tabsMap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate that we are just floating around in the middle of this generalFunctions
file. I think you might be able to come up with some better way to do this.
Also, maybe all this "tool tab" logic should be in its own file, since none of these are actual "general functions" but very specific ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is only used here. We already have too many files.
Quality Gate passedIssues Measures |
Replaced by #334 |