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: faq page filter #218

Merged
merged 7 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 21 additions & 5 deletions components/search-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function SearchForm({
sortSettings,
autoSearch,
initialValue,
checkDocSize,
}: {
itemName: string;
onSubmitKeywords: (keywords: string, filters?: any, sort_by?: string) => void;
Expand All @@ -46,6 +47,7 @@ export function SearchForm({
filters?: {};
sort?: string;
};
checkDocSize: boolean;
}) {
const defaultSort = sortSettings?.length ? sortSettings[0].value : "";
const [keywords, setKeywords] = useState<string>("");
Expand Down Expand Up @@ -139,6 +141,7 @@ export function SearchForm({
</SecondaryButton>
</div>
</div>

{filterItems && Object.keys(filterItems).length ? (
<>
<span className="block mb-2 font-medium text-gray-700">Filter</span>
Expand All @@ -161,17 +164,29 @@ export function SearchForm({
>
<option value="">Semua</option>
{buckets.map((bucket: any, bIdx: number) => {
return (
bucket.doc_count > 0 &&
bucket.key && (
if (bucket.key) {
if (checkDocSize && bucket.doc_count > 0) {
return (
<option
key={`option-${key}-${bIdx + 1}`}
value={bucket.key}
>
{bucket.key}
</option>
);
}

// FAQ page doesn't check the doc_count
return (
<option
key={`option-${key}-${bIdx + 1}`}
value={bucket.key}
>
{bucket.key}
</option>
)
);
);
}
Comment on lines +167 to +188
Copy link
Collaborator

@ekamuktia ekamuktia Jul 20, 2021

Choose a reason for hiding this comment

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

For this part, buckets that have doc_count 0 is still printed even though the checkDocSize is true because it goes to the 2nd return. So now, all the filters are always shown.
image

If the intention for FAQ page is to always show all the categories, another way to do it is to generate filterItems value from groupped faq instead of using value generated from useSearch.
This way, the filter category order can be in the same order as how the FAQ items are shown which probably is more natural for FAQ page.
image

Copy link
Member

Choose a reason for hiding this comment

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

Could you please report another issue for this Mbak @ekamuktia? So we can do a rework later. Thanks! 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay~!

Copy link
Member Author

@mazipan mazipan Jul 20, 2021

Choose a reason for hiding this comment

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

Check this PR #229

Copy link
Member Author

@mazipan mazipan Jul 20, 2021

Choose a reason for hiding this comment

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

For option no 2, I think it will need more time to be done, since it need to refactor the way we select the selected filter. It can be done on #197 if we want to pick the ticket

return null;
})}
</Select>
</div>
Expand All @@ -180,6 +195,7 @@ export function SearchForm({
</div>
</>
) : null}

{sortSettings?.length ? (
<div className="grid grid-cols-2 gap-4">
<div className="space-y-1">
Expand Down
1 change: 1 addition & 0 deletions lib/hooks/use-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function useSearch<T = unknown[]>(
...sortSettings,
},
};

if (aggregationSettings?.length) {
configuration.aggregations = aggregationSettings.reduce(
(aggregations: any, cur) => {
Expand Down
1 change: 1 addition & 0 deletions pages/faq.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function Faqs(props: FaqsProps) {
/>
<PageContent>
<SearchForm
checkDocSize={false}
filterItems={filterItems}
initialValue={urlParams}
itemName="pertanyaan"
Expand Down
1 change: 1 addition & 0 deletions pages/provinces/[provinceSlug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function ProvincePage(props: ProvinceProps) {
/>
<PageContent>
<SearchForm
checkDocSize={true}
filterItems={filterItems}
initialValue={urlParams}
itemName="kontak"
Expand Down
1 change: 1 addition & 0 deletions pages/provinces/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function ProvincesPage(props: ProvincesPageProps) {
<PageContent>
<SearchForm
autoSearch={true}
checkDocSize={true}
initialValue={urlParams}
itemName="provinsi"
onSubmitKeywords={handleSubmitKeywords}
Expand Down