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

Bibdk2021 2032 adv facets #1391

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 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
66 changes: 66 additions & 0 deletions e2e/cypress/e2e/advFacets.cy.js
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"));
});
});
});
2 changes: 1 addition & 1 deletion src/components/base/accordion/Accordion.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}

.header_content {
padding: var(--pt2) 0 var(--pt2) 0;
padding: var(--pt1) 0 var(--pt1) 0;
}

.wrapper {
Expand Down
5 changes: 3 additions & 2 deletions src/components/base/animation/expand/Expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import Icon from "@/components/base/icon/Icon";

import styles from "./Expand.module.css";

export default function Expand({ open, size = 3 }) {
export default function Expand({ open, size = 3, src, bgColor }) {
return (
<Icon
size={size}
bgColor="var(--blue)"
// bgColor="var(--blue)"
dataCy="expand-icon"
className={`${styles.expandicon} ${open ? styles.opened : styles.closed}`}
alt="expand"
src="expand.svg"
Copy link
Contributor

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

>
{/* Lines to be animated */}
<div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/base/animation/expand/Expand.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
height: 40%;
position: relative;

top: 20%;
left: 20%;
top: 50%;
left: 50%;

transform: translate(-50%, -50%);
}
Expand All @@ -20,7 +20,7 @@

width: 100%;

background: white;
background: blue;
height: 2px;
transition: all 0.35s;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/base/forms/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Checkbox.propTypes = {
required: PropTypes.bool,
readOnly: PropTypes.bool,
onChange: PropTypes.func,
onClick: PropTypes.func,
skeleton: PropTypes.bool,
dataCy: PropTypes.string,
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/base/section/Section.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default function Section({
{title && !rightSideTitle && (
<Col
xs={12}
lg={2}
lg={colSize?.titel?.lg?.offset || 2}
data-cy={cyKey({ name: "title", prefix: "section" })}
className={`section-title ${styles.title} ${titleDividerClass} ${sectionTitleClass}`}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default function AdvancedSearch({ ariaExpanded, className }) {
}, [cqlFromUrl, router?.query?.mode]);

//add raw cql query in url if showCqlEditor. Add state to url if fieldInputs
// @TODO add facets here - they can be taken from context :)
const doAdvancedSearch = () => {
if (showCqlEditor) {
const cqlParsedFromUrl = fieldSearchFromUrl
Expand Down
3 changes: 3 additions & 0 deletions src/components/search/advancedSearch/advancedSearchContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ export default function AdvancedSearchProvider({ children, router }) {
cql: cqlFromUrl = null,
fieldSearch = "",
sort: sortFromUrl = "",
facets: facetsFromUrl = "[]",
} = router.query;
const fieldSearchFromUrl = fieldSearch && JSON.parse(fieldSearch);
const sort = sortFromUrl && JSON.parse(sortFromUrl);
const facets = facetsFromUrl && JSON.parse(facetsFromUrl);

//// ---- Popup Trigger ----
const popoverRef = useRef(null);
Expand Down Expand Up @@ -168,6 +170,7 @@ export default function AdvancedSearchProvider({ children, router }) {
resetObjectState,
parsedCQL,
setParsedCQL,
facets,
fieldSearchFromUrl,
cqlFromUrl,
pageNoFromUrl: page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,6 +25,7 @@ export function AdvancedSearchResult({
results,
error = null,
isLoading,
facets,
}) {
const hitcount = results?.hitcount;
const numPages = Math.ceil(hitcount / 10);
Expand All @@ -34,21 +37,37 @@ export function AdvancedSearchResult({
return null;
}

const TitleComponent = () => {
return (
<div className={styles.flex}>
{/*<div className={styles.countstyle}> {hitcount} </div>*/}
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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 : ""}
Expand All @@ -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>
Expand Down Expand Up @@ -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,
};
}

Expand All @@ -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);
Expand Down Expand Up @@ -147,6 +175,7 @@ export default function Wrap({ onWorkClick, onPageChange }) {
error={parsedResponse.errorMessage}
setShowPopover={setShowPopover}
isLoading={parsedResponse.isLoading}
facets={parsedResponse.facets}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,6 +46,7 @@ ResultPage.propTypes = {
function parseResponse(bigResponse) {
return {
works: bigResponse?.data?.complexSearch?.works || null,
facets: bigResponse?.data?.complexSearch?.facets || [],
isLoading: bigResponse?.isLoading,
};
}
Expand All @@ -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"],
// };
Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹🧹

import { useFacets } from "@/components/search/advancedSearch/useFacets";

/**
*
Expand Down Expand Up @@ -40,6 +42,8 @@ export function FormatFieldSearchIndexes({ fieldsearch }) {
(field) => !isEmpty(field.value)
);

const { selectedFacets } = useFacets();

return (
<div className={styles.formatedQueryContainer}>
<FormatFieldInput
Expand All @@ -50,6 +54,7 @@ export function FormatFieldSearchIndexes({ fieldsearch }) {
dropdowns={filteredDropdownSearchIndices}
showAndOperator={filteredInputFields?.length > 0}
/>
{/*<Text type="text1">{getFacetsQuery(selectedFacets)}</Text>*/}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹

</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,17 @@ export function CqlErrorMessage(errormessage) {
}

export default function Wrap({ cql = "" }) {
const bigResponse = useData(doComplexSearchAll({ cql, offset: 0, limit: 1 }));
const bigResponse = useData(
doComplexSearchAll({
cql,
offset: 0,
limit: 1,
facets: {
facetLimit: 5,
facets: ["specificmaterialtype", "subject"],
},
})
);

return CqlErrorMessage(bigResponse?.data?.complexSearch?.errorMessage);
}
Loading