-
Notifications
You must be signed in to change notification settings - Fork 1
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
Bibdk2021 2032 adv facets #1391
base: main
Are you sure you want to change the base?
Changes from 14 commits
b8b2af5
e01cf7a
acc0833
8d66542
691e40b
368c8d7
a4ed203
2112c48
da4c234
55e7781
75fd4bc
deae2ad
52d3a71
a95b04e
1667679
e8df043
1acefcb
66c33ba
738881a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
describe("Facets", () => { | ||
it(`Get facets from url`, () => { | ||
cy.visit("/iframe.html?id=advancedsearch-facets--facets-in-url"); | ||
|
||
// there should be 3 accordions in this story | ||
cy.get("[data-cy=accordion-item]").should("have.length", 3); | ||
|
||
cy.get("[data-cy=router-query]").then((el) => { | ||
const fisk = JSON.parse(el.text()); | ||
const facets = JSON.parse(fisk.facets); | ||
|
||
// there should be two in query | ||
expect(facets.length).to.equal(2); | ||
}); | ||
|
||
// get the first accordion | ||
cy.get("[data-cy=accordion-item]").first().click(); | ||
|
||
// there should be 10 | ||
cy.get("[data-cy=accordion-item]") | ||
.first() | ||
.find("li") | ||
.should("have.length", 10); | ||
|
||
// two of them should be selected from url params | ||
cy.get("[data-cy=accordion-item]") | ||
.first() | ||
.find("li") | ||
.find("[checked]") | ||
.should("have.length", 2); | ||
|
||
// uncheck one | ||
cy.get("[data-cy=accordion-item]") | ||
.first() | ||
.find("li") | ||
.find("[checked]") | ||
.first() | ||
.focus() | ||
.click({ force: true }); | ||
|
||
// click an item and verify url is updated | ||
cy.get("[data-cy=li-specificmaterialtype-artikel]") | ||
.find("input") | ||
.click({ force: true }); | ||
|
||
cy.get("[data-cy=router-query]").then((el) => { | ||
const fisk = JSON.parse(el.text()); | ||
const facets = fisk.facets; | ||
console.log(facets, "FACETS"); | ||
|
||
assert(facets.includes("artikel")); | ||
}); | ||
|
||
// and again | ||
cy.get("[data-cy=li-specificmaterialtype-aarbog]") | ||
.find("input") | ||
.click({ force: true }); | ||
|
||
cy.get("[data-cy=router-query]").then((el) => { | ||
const fisk = JSON.parse(el.text()); | ||
const facets = fisk.facets; | ||
|
||
assert(facets.includes("aarbog")); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ import Title from "@/components/base/title"; | |
import { NoHitSearch } from "@/components/search/advancedSearch/advancedSearchResult/noHitSearch/NoHitSearch"; | ||
import ResultPage from "./ResultPage/ResultPage"; | ||
import useBreakpoint from "@/components/hooks/useBreakpoint"; | ||
import { AdvancedFacets } from "@/components/search/advancedSearch/facets/advancedFacets"; | ||
import { useFacets } from "@/components/search/advancedSearch/useFacets"; | ||
|
||
export function AdvancedSearchResult({ | ||
pageNo, | ||
|
@@ -23,6 +25,7 @@ export function AdvancedSearchResult({ | |
results, | ||
error = null, | ||
isLoading, | ||
facets, | ||
}) { | ||
const hitcount = results?.hitcount; | ||
const numPages = Math.ceil(hitcount / 10); | ||
|
@@ -34,21 +37,37 @@ export function AdvancedSearchResult({ | |
return null; | ||
} | ||
|
||
const TitleComponent = () => { | ||
return ( | ||
<div className={styles.flex}> | ||
{/*<div className={styles.countstyle}> {hitcount} </div>*/} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skal kommenteret kode fjernes? |
||
<Title type="title5" className={styles.countstyle}> | ||
{hitcount} | ||
</Title> | ||
<Title type="title6">Resultater</Title> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Det skal måske i Translate.json |
||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<TopBar isLoading={isLoading} /> | ||
|
||
<Section | ||
divider={false} | ||
colSize={{ lg: { offset: 1, span: true } }} | ||
colSize={{ | ||
lg: { offset: 0, span: true }, | ||
titel: { lg: { offset: 3, span: true } }, | ||
}} | ||
id="search-result-section" | ||
title="Resultater" | ||
title={<TitleComponent />} | ||
subtitle={ | ||
hitcount > 0 && | ||
!isLoading && ( | ||
<Title type="title5" className={styles.titleStyle}> | ||
{hitcount} | ||
</Title> | ||
<> | ||
<Title type="title6">Afgræns din søgning</Title> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skal det ikke i translate.json? 😬 |
||
<AdvancedFacets facets={facets} /> | ||
</> | ||
) | ||
} | ||
sectionContentClass={isMobile ? styles.sectionContentStyle : ""} | ||
|
@@ -57,6 +76,7 @@ export function AdvancedSearchResult({ | |
{/* Reuse result page from simplesearch - we skip the wrap .. @TODO should we set | ||
some mark .. that we are doing advanced search .. ?? */} | ||
{!isLoading && hitcount === 0 && <NoHitSearch />} | ||
{/*<AdvancedFacets facets={facets} />*/} | ||
<> | ||
<AdvancedSearchSort className={cx(styles.sort_container)} /> | ||
<div> | ||
|
@@ -91,6 +111,7 @@ function parseResponse(bigResponse) { | |
hitcount: bigResponse?.data?.complexSearch?.hitcount || 0, | ||
errorMessage: bigResponse?.data?.complexSearch?.errorMessage || null, | ||
isLoading: bigResponse?.isLoading, | ||
facets: bigResponse?.data?.complexSearch?.facets, | ||
}; | ||
} | ||
|
||
|
@@ -105,20 +126,27 @@ export default function Wrap({ onWorkClick, onPageChange }) { | |
fieldSearchFromUrl: fieldSearch, | ||
pageNoFromUrl: pageNo, | ||
setShowPopover, | ||
facets, | ||
} = useAdvancedSearchContext(); | ||
|
||
const { facetsFromEnum } = useFacets(); | ||
|
||
// @TODO what to do with dataCollect ??? | ||
onWorkClick = null; | ||
// get setter for advanced search history | ||
const { setValue } = useAdvancedSearchHistory(); | ||
const cqlQuery = cql || convertStateToCql(fieldSearch); | ||
const cqlQuery = cql || convertStateToCql({ ...fieldSearch, facets: facets }); | ||
|
||
const showResult = !isEmpty(fieldSearch) || !isEmpty(cql); | ||
|
||
// use the useData hook to fetch data | ||
const fastResponse = useData( | ||
hitcount({ | ||
cql: cqlQuery, | ||
facets: { | ||
facetLimit: 5, | ||
facets: facetsFromEnum, | ||
}, | ||
}) | ||
); | ||
const parsedResponse = parseResponse(fastResponse); | ||
|
@@ -147,6 +175,7 @@ export default function Wrap({ onWorkClick, onPageChange }) { | |
error={parsedResponse.errorMessage} | ||
setShowPopover={setShowPopover} | ||
isLoading={parsedResponse.isLoading} | ||
facets={parsedResponse.facets} | ||
/> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,15 @@ import { useAdvancedSearchContext } from "@/components/search/advancedSearch/adv | |
|
||
import { convertStateToCql } from "@/components/search/advancedSearch/utils"; | ||
import isEmpty from "lodash/isEmpty"; | ||
import { useFacets } from "@/components/search/advancedSearch/useFacets"; | ||
|
||
/** | ||
* Row representation of a search result entry | ||
* | ||
* @param {Object} props | ||
* See propTypes for specific props and types | ||
*/ | ||
export function ResultPage({ rows, onWorkClick, isLoading }) { | ||
export function ResultPage({ rows, onWorkClick, isLoading, facets }) { | ||
const resultRows = rows?.map((row, index) => ( | ||
<Fragment key={row.workId + ":" + index}> | ||
<ResultRow | ||
|
@@ -45,6 +46,7 @@ ResultPage.propTypes = { | |
function parseResponse(bigResponse) { | ||
return { | ||
works: bigResponse?.data?.complexSearch?.works || null, | ||
facets: bigResponse?.data?.complexSearch?.facets || [], | ||
isLoading: bigResponse?.isLoading, | ||
}; | ||
} | ||
|
@@ -62,25 +64,37 @@ export default function Wrap({ onWorkClick, page }) { | |
cqlFromUrl: cql, | ||
fieldSearchFromUrl: fieldSearch, | ||
sort, | ||
facets, | ||
} = useAdvancedSearchContext(); | ||
|
||
const { facetsFromEnum } = useFacets(); | ||
|
||
onWorkClick = null; | ||
|
||
const limit = 10; | ||
let offset = limit * (page - 1); | ||
const cqlQuery = cql || convertStateToCql(fieldSearch); | ||
const cqlQuery = cql || convertStateToCql({ ...fieldSearch, facets: facets }); | ||
|
||
const showResult = !isEmpty(fieldSearch) || !isEmpty(cql); | ||
|
||
// const facets = { | ||
// facetLimit: 5, | ||
// facets: ["specificmaterialtype", "subject"], | ||
// }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fjernes 🧹 |
||
// fetch data for the specific page | ||
const bigResponse = useData( | ||
doComplexSearchAll({ | ||
cql: cqlQuery, | ||
offset: offset, | ||
limit: limit, | ||
facets: { | ||
facetLimit: 5, | ||
facets: facetsFromEnum, | ||
}, | ||
...(!isEmpty(sort) && { sort: sort }), | ||
}) | ||
); | ||
|
||
const parsedResponse = parseResponse(bigResponse); | ||
|
||
if (parsedResponse.isLoading) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import Text from "@/components/base/text"; | |
import Translate from "@/components/base/translate"; | ||
import isEmpty from "lodash/isEmpty"; | ||
import { formattersAndComparitors } from "@/components/search/advancedSearch/useDefaultItemsForDropdownUnits"; | ||
// import { getFacetsQuery } from "@/components/search/advancedSearch/utils"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹🧹 |
||
import { useFacets } from "@/components/search/advancedSearch/useFacets"; | ||
|
||
/** | ||
* | ||
|
@@ -40,6 +42,8 @@ export function FormatFieldSearchIndexes({ fieldsearch }) { | |
(field) => !isEmpty(field.value) | ||
); | ||
|
||
const { selectedFacets } = useFacets(); | ||
|
||
return ( | ||
<div className={styles.formatedQueryContainer}> | ||
<FormatFieldInput | ||
|
@@ -50,6 +54,7 @@ export function FormatFieldSearchIndexes({ fieldsearch }) { | |
dropdowns={filteredDropdownSearchIndices} | ||
showAndOperator={filteredInputFields?.length > 0} | ||
/> | ||
{/*<Text type="text1">{getFacetsQuery(selectedFacets)}</Text>*/} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 |
||
</div> | ||
); | ||
} | ||
|
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.
Bliver bgColor og src ikke brugt ? bgColor kunne evt. have default farve på "var(--blue)". Så der mindre chance for at det påvirker de steder hvor expand bliver brugt