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

feat(smartSort): add widget #4648

Merged
merged 30 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5d47c55
feat(smartSort): add widget
eunjae-lee Feb 3, 2021
c332c62
chore: update types
eunjae-lee Feb 10, 2021
d8ebe67
rename the template key from default to text
eunjae-lee Feb 10, 2021
7db1055
add tests for component and widget
eunjae-lee Feb 10, 2021
a5cf915
provide defaultTemplates for smart-sort widget
eunjae-lee Feb 10, 2021
4dfbf70
Merge branch 'master' into feat/smart-sort
Feb 11, 2021
707d059
clean up storybook
eunjae-lee Feb 11, 2021
ec8dfdf
remove test code that is no longer needed
eunjae-lee Feb 11, 2021
a24b4c1
fix type error
eunjae-lee Feb 11, 2021
09af204
move refine to connectorState
eunjae-lee Feb 11, 2021
858f44b
use setQueryParameter instead of mergeSearchParameters
eunjae-lee Feb 11, 2021
3bd77d6
rename template from text to button
eunjae-lee Feb 11, 2021
901fa5d
update templates to include root and text
eunjae-lee Feb 11, 2021
e91cc3e
Merge branch 'master' into feat/smart-sort
eunjae-lee Feb 11, 2021
9869c12
update client-search and algoliasearch to 4.8.5
eunjae-lee Feb 11, 2021
996c09a
clean up the condition for isSmartSorted
eunjae-lee Feb 11, 2021
d5a1f6c
Revert "clean up the condition for isSmartSorted"
eunjae-lee Feb 11, 2021
3f1fd5c
update bundlesize
eunjae-lee Feb 11, 2021
577bb67
update the storybook
eunjae-lee Feb 11, 2021
da638dc
Merge branch 'master' into feat/smart-sort
Feb 11, 2021
88ff0e7
fix type for client v3
eunjae-lee Feb 15, 2021
a88a21b
Merge branch 'master' into feat/smart-sort
eunjae-lee Feb 15, 2021
2f3409f
remove relevancyStrictness from widgetParams and add isVirtualReplica…
eunjae-lee Feb 16, 2021
8e226cf
Merge branch 'master' into feat/smart-sort
Feb 16, 2021
6003c75
Update src/connectors/smart-sort/connectSmartSort.ts
Feb 16, 2021
f681b87
clean up the story
eunjae-lee Feb 16, 2021
3e385d3
Merge branch 'master' into feat/smart-sort
Feb 18, 2021
5139e90
Update src/connectors/smart-sort/connectSmartSort.ts
Feb 18, 2021
d54831c
use Template type
eunjae-lee Feb 19, 2021
777e47d
Merge branch 'master' into feat/smart-sort
eunjae-lee Feb 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions src/components/SmartSort/SmartSort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,46 @@ type SmartSortProps = {
cssClasses: SmartSortCSSClasses;
templates: SmartSortTemplates;
isSmartSorted: boolean;
relevancyStrictness?: number;
isVirtualReplica: boolean;
refine(relevancyStrictness: number | undefined): void;
};

const SmartSort = ({
cssClasses,
templates,
isSmartSorted,
relevancyStrictness,
isVirtualReplica,
refine,
}: SmartSortProps) => (
<div className={cssClasses.root}>
<Template
templateKey="text"
templates={templates}
rootProps={{
className: cssClasses.text,
}}
data={{ isSmartSorted }}
/>
<button
type="button"
className={cssClasses.button}
onClick={() => {
if (isSmartSorted) {
refine(0);
} else {
refine(relevancyStrictness);
}
}}
>
}: SmartSortProps) =>
isVirtualReplica ? (
<div className={cssClasses.root}>
<Template
rootTagName="span"
templateKey="button"
templateKey="text"
templates={templates}
rootProps={{
className: cssClasses.text,
}}
data={{ isSmartSorted }}
/>
</button>
</div>
);
<button
type="button"
className={cssClasses.button}
onClick={() => {
if (isSmartSorted) {
refine(0);
} else {
refine(undefined);
}
}}
>
<Template
rootTagName="span"
templateKey="button"
templates={templates}
data={{ isSmartSorted }}
/>
</button>
</div>
) : null;

export default SmartSort;
51 changes: 34 additions & 17 deletions src/components/SmartSort/__tests__/SmartSort-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,26 @@ const templates = {
};

describe('SmartSort', () => {
it('render nothing if not virtual replica', () => {
const { container } = render(
<SmartSort
cssClasses={cssClasses}
templates={templates}
isSmartSorted={false}
isVirtualReplica={false}
refine={() => {}}
/>
);
expect(container).toMatchInlineSnapshot(`<div />`);
});

it('render the default status', () => {
const { container } = render(
<SmartSort
cssClasses={cssClasses}
templates={templates}
isSmartSorted={false}
isVirtualReplica={true}
refine={() => {}}
/>
);
Expand Down Expand Up @@ -56,35 +70,21 @@ describe('SmartSort', () => {
cssClasses={cssClasses}
templates={templates}
isSmartSorted={false}
isVirtualReplica={true}
refine={refine}
/>
);
fireEvent.click(getByText('See relevant results'));
expect(refine).toHaveBeenCalledTimes(1);
});

it('refine with given value', () => {
const refine = jest.fn();
const { getByText } = render(
<SmartSort
cssClasses={cssClasses}
templates={templates}
isSmartSorted={false}
relevancyStrictness={30}
refine={refine}
/>
);
fireEvent.click(getByText('See relevant results'));
expect(refine).toHaveBeenCalledTimes(1);
expect(refine).toHaveBeenCalledWith(30);
});

it('render sorted status', () => {
const { container } = render(
<SmartSort
cssClasses={cssClasses}
templates={templates}
isSmartSorted={true}
isVirtualReplica={true}
refine={() => {}}
/>
);
Expand All @@ -109,13 +109,30 @@ describe('SmartSort', () => {
`);
});

it('refine with zero when seeing all results', () => {
it('refine with `undefined` on "See relevant results"', () => {
const refine = jest.fn();
const { getByText } = render(
<SmartSort
cssClasses={cssClasses}
templates={templates}
isSmartSorted={false}
isVirtualReplica={true}
refine={refine}
/>
);
fireEvent.click(getByText('See relevant results'));
expect(refine).toHaveBeenCalledTimes(1);
expect(refine).toHaveBeenCalledWith(undefined);
});

it('refine with `0` on "Seeing all results"', () => {
const refine = jest.fn();
const { getByText } = render(
<SmartSort
cssClasses={cssClasses}
templates={templates}
isSmartSorted={true}
isVirtualReplica={true}
refine={refine}
/>
);
Expand Down
Loading