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(ts): migrate connectors to new Widget type #4735

Merged
merged 4 commits into from
May 3, 2021

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Apr 15, 2021

Summary

migrates all the connectors to the new type from #4734

Result

fixes some smaller things in the tests, plus implementation of refinementList (removed dead code)

  • connectToggleRefinement: nest getRenderState per attribute
  • connectToggleRefinement: remove state state from getWidgetRenderState
  • connectRefinementList: remove dead code in getWidgetRenderState
  • connectRelevantSort: remove "relevantSort" nesting, since there's only one property

These are technically breaking changes, but small enough to just be listed in the changeling IMO

$$type: 'ais.answers';
renderState: AnswersRenderState;
indexRenderState: {
answers: WidgetRenderState<AnswersRenderState, AnswersConnectorParams>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
answers: WidgetRenderState<AnswersRenderState, AnswersConnectorParams>;
answers: AnswersRenderState;

I wish it could just be this, and then augmented with the parameters when you use it (eg. in Widget['getRenderState']), but I can't get it to work, so for now, the index render state only types the connector params, not the connector & widget params. I think this is a reasonable tradeoff for now, considering the use cases for reading the widget params from index render state are likely slim (and can use an as any)

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me. We could improve this part later if we find a solution.

@Haroenv Haroenv force-pushed the chore/types-reorg-5 branch from 52671f2 to 3f3da50 Compare April 15, 2021 14:31
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 15, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 049d4b8:

Sandbox Source
InstantSearch.js Configuration

relevantSort: { relevancyStrictness: undefined },
relevantSort: 25,
Copy link
Contributor Author

@Haroenv Haroenv Apr 19, 2021

Choose a reason for hiding this comment

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

I don't understand why it was 25 and not undefined before, this is a fix

Copy link
Contributor

Choose a reason for hiding this comment

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

When the helper state doesn't include appliedRelevancyStrictness at all, then the widget shouldn't, either. I guess that's what this test is about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but if the helper state doesn't have relevancy strictness, but the ui state (route) does have it, doesn't that apply the strictness in getWidgetSearchParameters?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah it sounds right.

Comment on lines -119 to +134
relevantSort: {
...uiState.relevantSort,
relevancyStrictness: searchParameters.relevancyStrictness,
},
relevantSort:
searchParameters.relevancyStrictness || uiState.relevantSort,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

uiState change is technically a breaking change, but small enough to just mention in changelog

Copy link
Member

Choose a reason for hiding this comment

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

|| uiState.relevantSort

Does this mean we can now set the relevantSort from the frontend?

Comment on lines -221 to +224
toggleRefinement: this.getWidgetRenderState(renderOptions),
toggleRefinement: {
...renderState.toggleRefinement,
[attribute]: this.getWidgetRenderState(renderOptions),
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

uiState change is technically a breaking change, but small enough to just mention in changelog

@Haroenv Haroenv requested review from a team, eunjae-lee and tkrugg and removed request for a team April 19, 2021 15:46
@@ -385,25 +384,13 @@ const connectRefinementList: RefinementListConnector = function connectRefinemen
}

if (results) {
if (!isFromSearch) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this code was unreachable, isFromSearch is never passed to getWidgetRenderState

Comment on lines -158 to +163
: Partial<RequiredWidgetType<TWidgetDescription>>;
: {
/**
* Identifier for widgets.
*/
$$widgetType?: string;
};
Copy link
Contributor Author

@Haroenv Haroenv Apr 20, 2021

Choose a reason for hiding this comment

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

previous implementation sometimes caused infinite loops in the type resolution, so it's written explicitly here

Copy link
Contributor

@eunjae-lee eunjae-lee left a comment

Choose a reason for hiding this comment

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

Thanks for the work!

relevantSort: { relevancyStrictness: undefined },
relevantSort: 25,
Copy link
Contributor

Choose a reason for hiding this comment

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

When the helper state doesn't include appliedRelevancyStrictness at all, then the widget shouldn't, either. I guess that's what this test is about.

$$type: 'ais.answers';
renderState: AnswersRenderState;
indexRenderState: {
answers: WidgetRenderState<AnswersRenderState, AnswersConnectorParams>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me. We could improve this part later if we find a solution.

Copy link
Contributor

@eunjae-lee eunjae-lee left a comment

Choose a reason for hiding this comment

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

Looks good to me!

relevantSort: { relevancyStrictness: undefined },
relevantSort: 25,
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah it sounds right.

@Haroenv Haroenv requested a review from shortcuts May 3, 2021 07:57
Comment on lines -119 to +134
relevantSort: {
...uiState.relevantSort,
relevancyStrictness: searchParameters.relevancyStrictness,
},
relevantSort:
searchParameters.relevancyStrictness || uiState.relevantSort,
Copy link
Member

Choose a reason for hiding this comment

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

|| uiState.relevantSort

Does this mean we can now set the relevantSort from the frontend?

@Haroenv Haroenv force-pushed the chore/types-reorg-4 branch from 01ece8c to 53d4812 Compare May 3, 2021 12:45
Base automatically changed from chore/types-reorg-4 to master May 3, 2021 12:45
Haroenv added 4 commits May 3, 2021 14:46

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@Haroenv Haroenv force-pushed the chore/types-reorg-5 branch from cd4e053 to 049d4b8 Compare May 3, 2021 12:46
@Haroenv Haroenv merged commit f742083 into master May 3, 2021
@Haroenv Haroenv deleted the chore/types-reorg-5 branch May 3, 2021 12:46
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.

None yet

3 participants