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

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

Merged
merged 3 commits into from Dec 14, 2023

Conversation

tjuanitas
Copy link
Contributor

@tjuanitas tjuanitas commented Dec 14, 2023

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.

@@ -41,13 +24,13 @@ type Props = {
method?: 'get' | 'post',
/** Name of the text input */
name?: string,
/** On change handler for the search input, debounced by 250ms */
Copy link
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
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
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
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
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?

Copy link
Contributor Author

@tjuanitas tjuanitas Dec 14, 2023

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
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
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 review from a team as code owners December 14, 2023 18:26
Copy link
Contributor

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

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
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
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
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
7 checks passed
@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.

None yet

4 participants