-
Notifications
You must be signed in to change notification settings - Fork 532
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
Conversation
$$type: 'ais.answers'; | ||
renderState: AnswersRenderState; | ||
indexRenderState: { | ||
answers: WidgetRenderState<AnswersRenderState, AnswersConnectorParams>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
)
There was a problem hiding this 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. We could improve this part later if we find a solution.
52671f2
to
3f3da50
Compare
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:
|
relevantSort: { relevancyStrictness: undefined }, | ||
relevantSort: 25, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah it sounds right.
relevantSort: { | ||
...uiState.relevantSort, | ||
relevancyStrictness: searchParameters.relevancyStrictness, | ||
}, | ||
relevantSort: | ||
searchParameters.relevancyStrictness || uiState.relevantSort, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
toggleRefinement: this.getWidgetRenderState(renderOptions), | ||
toggleRefinement: { | ||
...renderState.toggleRefinement, | ||
[attribute]: this.getWidgetRenderState(renderOptions), | ||
}, |
There was a problem hiding this comment.
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
@@ -385,25 +384,13 @@ const connectRefinementList: RefinementListConnector = function connectRefinemen | |||
} | |||
|
|||
if (results) { | |||
if (!isFromSearch) { |
There was a problem hiding this comment.
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
: Partial<RequiredWidgetType<TWidgetDescription>>; | ||
: { | ||
/** | ||
* Identifier for widgets. | ||
*/ | ||
$$widgetType?: string; | ||
}; |
There was a problem hiding this comment.
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
There was a problem hiding this 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, |
There was a problem hiding this comment.
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>; |
There was a problem hiding this 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. We could improve this part later if we find a solution.
There was a problem hiding this 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah it sounds right.
relevantSort: { | ||
...uiState.relevantSort, | ||
relevancyStrictness: searchParameters.relevancyStrictness, | ||
}, | ||
relevantSort: | ||
searchParameters.relevancyStrictness || uiState.relevantSort, |
There was a problem hiding this comment.
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?
01ece8c
to
53d4812
Compare
cd4e053
to
049d4b8
Compare
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)
getRenderState
per attributestate
state from getWidgetRenderStateThese are technically breaking changes, but small enough to just be listed in the changeling IMO