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

Tree component refactoring #1863

Merged
merged 10 commits into from
Oct 21, 2024
Merged

Tree component refactoring #1863

merged 10 commits into from
Oct 21, 2024

Conversation

victorlin
Copy link
Member

@victorlin victorlin commented Oct 8, 2024

Description of proposed changes

Changes made while prepping for #1373. These can be considered independently from that PR. See individual commit messages.

Checklist

@victorlin victorlin self-assigned this Oct 8, 2024
@nextstrain-bot nextstrain-bot temporarily deployed to auspice-victorlin-prep--fjlw4s October 8, 2024 00:14 Inactive
@victorlin victorlin temporarily deployed to auspice-victorlin-prep--fjlw4s October 8, 2024 00:49 Inactive
@victorlin victorlin marked this pull request as ready for review October 8, 2024 00:52
Using ReturnType on all sub-states except for controls (which already
has a type to be used directly) and narrative (the compiler was not able
to resolve types between return values and default state). The next
commit will fix the narrative type.
@victorlin victorlin force-pushed the victorlin/prep-dynamic-yvalues branch from 9ecca22 to 8280aaa Compare October 8, 2024 18:00
@victorlin victorlin temporarily deployed to auspice-victorlin-prep--fjlw4s October 8, 2024 18:00 Inactive
@victorlin victorlin force-pushed the victorlin/prep-dynamic-yvalues branch from 8280aaa to 33277b5 Compare October 8, 2024 23:28
@victorlin victorlin temporarily deployed to auspice-victorlin-prep--fjlw4s October 8, 2024 23:28 Inactive
}

clearSelectedNode = () => {
callbacks.clearSelectedNode.bind(this);
Copy link
Member

@jameshadfield jameshadfield Oct 9, 2024

Choose a reason for hiding this comment

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

[reminder to me] - check this change, I remember binding callbacks in the constructor was "the right way" way back when I was writing this code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see:

// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md#es6-classes
this.fitMapBoundsToData = this.fitMapBoundsToData.bind(this);

I've replaced 1eedee4 with a1aec38.

@jameshadfield
Copy link
Member

@genehack could you take a look at the types added / used here if you have a chance? 🙏

@victorlin victorlin temporarily deployed to auspice-victorlin-prep--fjlw4s October 9, 2024 17:22 Inactive
This was necessary to properly type the root state.

Note: AnyAction is used for `action` which is only slightly better than
any. Ideally, each action type would come with its own TypeScript
interface but there is no good way to tightly couple those. I think the
right improvement here is to use Redux's createSlice but that is beyond
the scope of adding types.
This allows type checking on the new entries.
This does not provide much benefit as-is, but should facilitate future
usage of TypeScript within the component.
The commented out usage was removed in "Excise react-svg-pan-zoom"
(56fbb8a).
Keep consistent with other parts of the file.
Only the clearSelectedNode binding needs to be kept in the constructor.
@victorlin victorlin force-pushed the victorlin/prep-dynamic-yvalues branch from 6d65167 to ceec881 Compare October 9, 2024 21:40
@victorlin victorlin temporarily deployed to auspice-victorlin-prep--fjlw4s October 9, 2024 21:41 Inactive
src/components/tree/tree.js Outdated Show resolved Hide resolved
src/reducers/controls.ts Outdated Show resolved Hide resolved
src/reducers/controls.ts Outdated Show resolved Hide resolved
src/reducers/narrative.ts Show resolved Hide resolved
- `treeIsZoomed` is ambiguous since the condition considers two trees.
  Rename to `anyTreeZoomed`.
- `activeResetTreeButton` has the same condition as `anyTreeZoomed`.
  Reuse the existing variable.
Partial<ControlsState> previously worked but has the side effect of
marking all keys as optional, which is not accurate and prone to cause
future type errors.
@victorlin victorlin force-pushed the victorlin/prep-dynamic-yvalues branch from ceec881 to 4658803 Compare October 11, 2024 17:37
@victorlin victorlin temporarily deployed to auspice-victorlin-prep--fjlw4s October 11, 2024 17:38 Inactive
@victorlin victorlin merged commit 887624a into master Oct 21, 2024
29 checks passed
@victorlin victorlin deleted the victorlin/prep-dynamic-yvalues branch October 21, 2024 22:19
@victorlin victorlin mentioned this pull request Oct 21, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants