Skip to content

Move ResultTablesHeader to its own component#2666

Merged
robertbrignull merged 5 commits intomainfrom
robertbrignull/ResultTables-Header
Aug 11, 2023
Merged

Move ResultTablesHeader to its own component#2666
robertbrignull merged 5 commits intomainfrom
robertbrignull/ResultTables-Header

Conversation

@robertbrignull
Copy link
Copy Markdown
Contributor

I think we can reduce the size of the ResultTables component by pulling out to the bits for the header to a separate component. This header contains the pagination controls as well as the query name and file link.

Screenshot 2023-08-03 at 12 27 10

I've been testing it and as far as I can tell it's still working just as it was before.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@robertbrignull robertbrignull requested a review from a team August 3, 2023 11:43
@robertbrignull robertbrignull requested a review from a team as a code owner August 3, 2023 11:43
getResultSets(props.rawResultSets, props.interpretation),
);

return {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the only bit where it isn't perfectly replicated on the new component and I'm unsure if it's needed or not.

This is checking if the result set exists and if not setting the selected table and page to default values. I'm not sure how to trigger this state. I also think it should be covered by the useEffect hook in the header component which always sets the selected page to the value from the parsed result set.

const [selectedPage, setSelectedPage] = React.useState(
`${parsedResultSets.pageNumber + 1}`,
);
useEffect(() => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Interestingly this effect hook might not strictly be needed. My brain says it should be needed to update selectedPage, but when I try removing it everything still works. 🤔

The case I'd expect to be different is when moving between query results. If I change from viewing the results of one query to a different query, then parsedResultSets is updated and we want selectedPage to also be reset.

Possibly it's because ResultTables is constructing a new copy of this component on every render, so we're always getting the initial calculated value. This could change as we continue to tweak ResultTables.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's worth keeping it - it does seem like the right thing to do.


const onKeyDownHandler = useCallback(
(e: React.KeyboardEvent<HTMLInputElement>) => {
changePage(e.currentTarget.value);
Copy link
Copy Markdown
Contributor Author

@robertbrignull robertbrignull Aug 4, 2023

Choose a reason for hiding this comment

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

Oops, I forgot the logic about checking if it's keycode 13. I'll add that back in.

The callback used to look like:

onKeyDown={(e) => {
  if (e.keyCode === 13) {
    choosePage((e.target as HTMLInputElement).value);
  }
}}

but I accidentally removed the if condition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've actually done e.key === "Enter" because e.keyCode is deprecated now. See https://www.w3.org/TR/uievents-key/#named-key-attribute-values for a list of possible values.

@robertbrignull
Copy link
Copy Markdown
Contributor Author

A note to any reviewers: I'm not hugely confident that this code is any good 😄 . I'm also not all that attached to it, so if it turns out to be too hard to review or you're also unsure if this PR is an improvement on the current state then I'm happy to just close it. This work is not essential and we can always try it again another time.

Copy link
Copy Markdown
Contributor

@charisk charisk left a comment

Choose a reason for hiding this comment

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

Sorry it took a while to review - the diff was a bit scary 😬

I'm not super confident in my review, but I think each code change I've seen makes sense and it's a positive step. I can't see anything wrong. 🚢

@robertbrignull
Copy link
Copy Markdown
Contributor Author

Sorry it took a while to review - the diff was a bit scary 😬

I'm sorry it was a difficult diff! Next time I do one of these I'll try harder to do each change separately. In particular I should have moved the code to the new file in a separate commit to transforming it. Thank you for persevering. ❤️

@robertbrignull robertbrignull merged commit dd0534b into main Aug 11, 2023
@robertbrignull robertbrignull deleted the robertbrignull/ResultTables-Header branch August 11, 2023 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants