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

refactor: Improve GL item config types #2138

Merged
merged 15 commits into from
Jul 12, 2024

Conversation

bmingles
Copy link
Contributor

@bmingles bmingles commented Jul 9, 2024

  • Broke out explicit ItemConfig sub types and converted ItemConfig type into a union them all
  • Updated createContentItem to be more explicit in its mapping of config types to returned content items
  • Updated references to ItemConfigType with ItemConfig
  • Updated Component, RowOrColumn, and Stack classes to allow null parent

resolves #2130

@bmingles bmingles requested a review from mofojed July 9, 2024 22:12
@bmingles bmingles marked this pull request as draft July 9, 2024 22:51
@@ -66,7 +66,7 @@ export default class Component extends AbstractContentItem {
}

close() {
this.parent.removeChild(this);
this.parent?.removeChild(this);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to wrap my head around how this didn't cause problems before, but e2e tests would suggest that Component item types can be instantiated without a parent.

Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 46.66667% with 8 lines in your changes missing coverage. Please review.

Project coverage is 46.62%. Comparing base (8e47216) to head (08466f9).
Report is 4 commits behind head on main.

Files Patch % Lines
packages/dashboard/src/layout/LayoutUtils.ts 53.84% 6 Missing ⚠️
packages/code-studio/src/main/AppMainContainer.tsx 0.00% 1 Missing ⚠️
packages/dashboard/src/PanelManager.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2138      +/-   ##
==========================================
+ Coverage   46.59%   46.62%   +0.03%     
==========================================
  Files         682      685       +3     
  Lines       38441    38492      +51     
  Branches     9578     9800     +222     
==========================================
+ Hits        17912    17948      +36     
+ Misses      20519    20492      -27     
- Partials       10       52      +42     
Flag Coverage Δ
unit 46.62% <46.66%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bmingles bmingles marked this pull request as ready for review July 10, 2024 15:27
@@ -276,8 +266,9 @@ export default class Stack extends AbstractContentItem {
const insertBefore =
this._dropSegment === 'top' || this._dropSegment === 'left';
const hasCorrectParent =
(isVertical && this.parent.isColumn) ||
(isHorizontal && this.parent.isRow);
this.parent instanceof RowOrColumn &&
Copy link
Contributor Author

@bmingles bmingles Jul 10, 2024

Choose a reason for hiding this comment

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

I am making a slight assumption adding the instanceof RowOrColumn check here, since AbstractContentItem has an optional isColumn and isRow prop. Technically it wouldn't have to be said instance to have passed this check in the past. The other piece is the call to addChild on line 200 which does assume the 3rd argument in addChild which is only present in RowOrColumn, so it seems reasonable to think this should always be an instance of RowOrcolumn

packages/dashboard/src/layout/LayoutUtils.ts Outdated Show resolved Hide resolved
packages/dashboard/src/layout/LayoutUtils.ts Show resolved Hide resolved
Comment on lines 53 to 59
type ItemConfigSupported =
| ColumnItemConfig
| RowItemConfig
| StackItemConfig
| ComponentConfig;

const SUPPORTED_ITEM_TYPES = ['column', 'row', 'stack', 'component'] as const;
Copy link
Member

Choose a reason for hiding this comment

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

Docstrings for why these are the only supported types? Why isn't ReactComponentConfig supported for example? What is this "supported" by? We use ReactComponentConfig in a lot of places elsewhere... Maybe a better name would be something like LayoutItemConfig ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bender I don't actually know the answer as to why we only support these. This was just based on the constructors that were in the previous code. Any ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the ReactComponentConfig isn't listed due to it being converted out where this is used. I can improve that in the names / docs here to be more explicit, but not sure of any other reasons why other types aren't supported.

Copy link
Contributor Author

@bmingles bmingles Jul 11, 2024

Choose a reason for hiding this comment

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

Updated based on what I know. Not sure why DefaultItemConfig and RootItemConfig aren't included, but should at least clarify why ReactComponentConfig is excluded

packages/golden-layout/src/items/Stack.ts Show resolved Hide resolved
@bmingles bmingles requested a review from mofojed July 11, 2024 21:47
@bmingles bmingles merged commit 0da547d into deephaven:main Jul 12, 2024
11 checks passed
@bmingles bmingles deleted the 2130-gl-create-content-item-types branch July 12, 2024 17:33
@github-actions github-actions bot locked and limited conversation to collaborators Jul 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve types for Golden Layout createContentItem
2 participants