Skip to content

fix(search-form): extract search actions component - #3475

Merged
mergify[bot] merged 3 commits into
box:masterfrom
tjuanitas:fix-extract-search-actions
Dec 14, 2023
Merged

mergify[bot] merged 3 commits into
box:masterfrom
tjuanitas:fix-extract-search-actions

Conversation

@tjuanitas

@tjuanitas tjuanitas commented Dec 14, 2023 •

Copy link
Copy Markdown
Contributor

This should address an issue in the features version of ContentExplorer where passing a searchInputProps prop prevented the search input to not submit. I honestly couldn't figure out the exact root cause but extracting the makeLoadable HOC out of the render method seemed to fix it.

method?: 'get' | 'post',
/** Name of the text input */
name?: string,
/** On change handler for the search input, debounced by 250ms */

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.

outdated comment - the debounce was removed in box-react-ui

</div>
);

const LoadableSearchActions = makeLoadable(SearchActions);

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.

legacy docs state to not use HOCs in the render method: https://legacy.reactjs.org/docs/higher-order-components.html#dont-use-hocs-inside-the-render-method

I don't know if this is the direct cause of the original issue but it ended up fixing it without changing the other logic

Comment on lines +127 to +132
// Sift through the nested HOCs to find the correct element
const searchActions = wrapper
.find('LoadableSearchActions')
.shallow()
.shallow()
.shallow();

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.

admittedly not my best work...I briefly looked into using mount and alternatives but I selfishly didn't want to spend too much time on this component and changes

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.

shouldn't we being use two dive()s here instead of two shallow()?

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.

Also should this test be here? shouldn't it be in a new test file for SearchActions this way you dont have to go through the HOC?

@tjuanitas tjuanitas Dec 14, 2023 •

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.

shouldn't we being use two dive()s here instead of two shallow()?

I mainly copied from the existing test since I wasn't sure the exact differences. but it looks like dive() is preferred so I'll update these:
enzymejs/enzyme#1798

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.

Also should this test be here? shouldn't it be in a new test file for SearchActions this way you dont have to go through the HOC?

yeah this was one of the alternatives I was looking into but then moving it to a new SearchActions file I think sort of defeats the intention of the original test since it's testing the onClearHandler in SearchForm (the parent component)

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 think the ideal way to test it would be to convert this to RTL I guess and test the button click functionality? but then I was like: ahhh we'll save that for another day...

@tjuanitas
tjuanitas marked this pull request as ready for review December 14, 2023 18:26
@tjuanitas
tjuanitas requested a review from a team as a code owner December 14, 2023 18:26
@tjuanitas
tjuanitas requested a review from a team December 14, 2023 18:26

@greg-in-a-box greg-in-a-box left a comment

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.

left some comments

Comment on lines +127 to +132
// Sift through the nested HOCs to find the correct element
const searchActions = wrapper
.find('LoadableSearchActions')
.shallow()
.shallow()
.shallow();

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.

shouldn't we being use two dive()s here instead of two shallow()?

Comment on lines +127 to +132
// Sift through the nested HOCs to find the correct element
const searchActions = wrapper
.find('LoadableSearchActions')
.shallow()
.shallow()
.shallow();

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.

Also should this test be here? shouldn't it be in a new test file for SearchActions this way you dont have to go through the HOC?

onClear: (event: React.SyntheticEvent<HTMLButtonElement>) => void;
}

const SearchActions = ({ hasSubmitAction, intl, onClear }: SearchActionsProps) => {

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.

fyi this component is just copied from SearchForm. leaving class names and whatnot as the same so it doesn't break existing functionality for apps

@mergify
mergify Bot merged commit 8d77320 into box:master Dec 14, 2023
@tjuanitas
tjuanitas deleted the fix-extract-search-actions branch December 14, 2023 23:20
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