Skip to content

Commit

Permalink
Merge pull request #1325 from danskernesdigitalebibliotek/develop
Browse files Browse the repository at this point in the history
Release 2024.28.0
  • Loading branch information
kasperg authored Jul 10, 2024
2 parents 50e06f8 + 161aeca commit e876a29
Show file tree
Hide file tree
Showing 39 changed files with 914 additions and 275 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@babel/preset-typescript": "^7.24.7",
"@csstools/postcss-sass": "^5.1.1",
"@cypress/browserify-preprocessor": "^3.0.2",
"@cypress/code-coverage": "^3.12.39",
"@cypress/code-coverage": "^3.12.41",
"@graphql-codegen/add": "^3.1.1",
"@graphql-codegen/cli": "^2.6.2",
"@graphql-codegen/introspection": "^2.1.1",
Expand All @@ -75,25 +75,25 @@
"@testing-library/react": "^14.2.2",
"@testing-library/react-hooks": "^8.0.1",
"@tsconfig/create-react-app": "^1.0.2",
"@types/node": "^20.14.9",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-flatpickr": "^3.8.11",
"@types/react-redux": "^7.1.24",
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^7.14.1",
"@typescript-eslint/parser": "^7.15.0",
"@vitest/coverage-istanbul": "^1.6.0",
"autoprefixer": "^10.4.19",
"babel-loader": "^9.1.3",
"babel-plugin-istanbul": "^6.1.1",
"babel-plugin-istanbul": "^7.0.0",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"caniuse-lite": "^1.0.30001639",
"caniuse-lite": "^1.0.30001640",
"chokidar-cli": "^3.0.0",
"concurrently": "^8.2.2",
"core-js": "^3.37.1",
"css-loader": "^7.1.2",
"cssnano": "^7.0.3",
"cssnano": "^7.0.4",
"cypress": "^9.6.1",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
Expand Down Expand Up @@ -144,7 +144,7 @@
"prop-types": "Since we use former ddb-react components that depend on prop-types we keep this. Should be removed when usage of prop-types is deprecated."
},
"dependencies": {
"@danskernesdigitalebibliotek/dpl-design-system": "^2024.27.0-50a60f2057fffa8dac33aaaa4ceff523369c6b68",
"@danskernesdigitalebibliotek/dpl-design-system": "^2024.28.0-100e48a2a38f735862212d267438eeb6dc86e31b",
"@fullcalendar/core": "^6.1.14",
"@fullcalendar/daygrid": "^6.1.14",
"@fullcalendar/interaction": "^6.1.14",
Expand Down
5 changes: 5 additions & 0 deletions src/apps/advanced-search/AdvancedSearch.dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ export default {
name: "Advanced search filter - non-fiction",
defaultValue: "Non-fiction",
control: { type: "text" }
},
advancedSearchFilterHoldingStatusText: {
name: "Advanced search filter - holding status",
defaultValue: "Holding Status On Shelf",
control: { type: "text" }
}
}
} as ComponentMeta<typeof AdvancedSearchEntry>;
Expand Down
1 change: 1 addition & 0 deletions src/apps/advanced-search/AdvancedSearch.entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface AdvancedSearchEntryTextProps {
advancedSearchFilterOnlineText: string;
advancedSearchFilterFictionText: string;
advancedSearchFilterNonFictionText: string;
advancedSearchFilterHoldingStatusText: string;
advancedSearchInputLabelText: string;
}

Expand Down
37 changes: 37 additions & 0 deletions src/apps/advanced-search/AdvancedSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
removeQueryParametersFromUrl,
setQueryParametersInUrl
} from "../../core/utils/helpers/url";
import { LocationFilter } from "./LocationFilter";

interface AdvancedSearchProps {
pageSize: number;
Expand All @@ -28,6 +29,32 @@ const AdvancedSearch: React.FC<AdvancedSearchProps> = ({ pageSize }) => {
// This is the CQL query that is actually executed.
const [executedQuery, setExecutedQuery] = useState<string | null>(null);

const [locationFilter, setLocationFilter] = useState<LocationFilter>({});
const handleLocationChange = (location: string) => {
setLocationFilter((prevFilter) => ({
...prevFilter,
location: [location]
}));
};
const handleSublocationChange = (sublocation: string) => {
setLocationFilter((prevFilter) => ({
...prevFilter,
sublocation: [sublocation]
}));
};

const [onShelf, setOnShelf] = useState(false);
const handleOnShelfChange = (checked: boolean) => {
setOnShelf(checked);
if (checked) {
setQueryParametersInUrl({
onshelf: "true"
});
} else {
removeQueryParametersFromUrl("onshelf");
}
};

// Only react on url parameters on the initial render.
useEffectOnce(() => {
// We have to remove brackets if multiple filters were used so that we can
Expand All @@ -52,6 +79,10 @@ const AdvancedSearch: React.FC<AdvancedSearchProps> = ({ pageSize }) => {
if (getUrlQueryParam("linked") === "true") {
setShowResultOnly(true);
}

if (getUrlQueryParam("onshelf") === "true") {
setOnShelf(true);
}
});

useEffect(() => {
Expand Down Expand Up @@ -85,13 +116,19 @@ const AdvancedSearch: React.FC<AdvancedSearchProps> = ({ pageSize }) => {
setSearchObject={setSearchObject}
searchQuery={searchQuery}
setSearchQuery={setSearchQuery}
onShelf={onShelf}
setOnShelf={handleOnShelfChange}
onLocationChange={handleLocationChange}
onSublocationChange={handleSublocationChange}
/>
)}
{executedQuery && (
<AdvancedSearchResult
q={executedQuery}
pageSize={pageSize}
showContentOnly={showResultOnly}
onShelf={onShelf}
locationFilter={locationFilter}
/>
)}
</div>
Expand Down
30 changes: 28 additions & 2 deletions src/apps/advanced-search/AdvancedSearchHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,30 @@ import {
translateSearchObjectToCql
} from "./helpers";
import { Button } from "../../components/Buttons/Button";
import CheckBox from "../../components/checkbox/Checkbox";

export type AdvancedSearchHeaderProps = {
dataCy?: string;
searchQuery: string | null;
setSearchQuery: (searchQuery: string | null) => void;
searchObject: AdvancedSearchQuery | null;
setSearchObject: (searchObject: AdvancedSearchQuery | null) => void;
onShelf: boolean;
setOnShelf: (checked: boolean) => void;
onLocationChange: (location: string) => void;
onSublocationChange: (sublocation: string) => void;
};

const AdvancedSearchHeader: React.FC<AdvancedSearchHeaderProps> = ({
dataCy = "advanced-search-header",
searchQuery,
setSearchQuery,
searchObject,
setSearchObject
setSearchObject,
onShelf,
setOnShelf,
onLocationChange,
onSublocationChange
}) => {
const t = useText();
const [isFormMode, setIsFormMode] = useState<boolean>(true);
Expand All @@ -50,6 +59,10 @@ const AdvancedSearchHeader: React.FC<AdvancedSearchHeaderProps> = ({
const [rawCql, setRawCql] = useState<string>("");
const [focusedRow, setFocusedRow] = useState<number | null>(null);

const handleOnShelfChange = (checked: boolean) => {
setOnShelf(checked);
};

// If a new search object is passed in, override the internal state to reflect
// the updated values in the state.
useEffect(() => {
Expand Down Expand Up @@ -191,6 +204,12 @@ const AdvancedSearchHeader: React.FC<AdvancedSearchHeaderProps> = ({
/>
</div>
</section>
<CheckBox
id="on-shelf"
selected={onShelf}
onChecked={handleOnShelfChange}
label={t("advancedSearchFilterHoldingStatusText")}
/>
<PreviewSection
translatedCql={translatedCql}
reset={reset}
Expand All @@ -200,7 +219,14 @@ const AdvancedSearchHeader: React.FC<AdvancedSearchHeaderProps> = ({
</>
)}
{!isFormMode && (
<CqlSearchHeader initialCql={translatedCql} setCql={setRawCql} />
<CqlSearchHeader
initialCql={translatedCql}
setCql={setRawCql}
onShelf={onShelf}
handleOnShelfChange={handleOnShelfChange}
onLocationChange={onLocationChange}
onSublocationChange={onSublocationChange}
/>
)}

<section className="advanced-search__footer">
Expand Down
17 changes: 14 additions & 3 deletions src/apps/advanced-search/AdvancedSearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ import useGetCleanBranches from "../../core/utils/branches";
import { Work } from "../../core/utils/types/entities";
import {
ComplexSearchWithPaginationQuery,
HoldingsStatus,
useComplexSearchWithPaginationQuery
} from "../../core/dbc-gateway/generated/graphql";
import usePager from "../../components/result-pager/use-pager";
import SearchResultList from "../../components/card-item-list/SearchResultList";
import SearchResultZeroHits from "../search-result/search-result-zero-hits";
import { currentLocationWithParametersUrl } from "../../core/utils/helpers/url";
import { LocationFilter } from "./LocationFilter";

interface AdvancedSearchResultProps {
q: string;
pageSize: number;
showContentOnly: boolean;
onShelf: boolean;
locationFilter: LocationFilter;
}

const AdvancedSearchResult: React.FC<AdvancedSearchResultProps> = ({
q,
pageSize,
showContentOnly
showContentOnly,
onShelf,
locationFilter
}) => {
const t = useText();
const [copiedLinkToSearch, setCopiedLinkToSearch] = useState<boolean>(false);
Expand Down Expand Up @@ -62,7 +68,12 @@ const AdvancedSearchResult: React.FC<AdvancedSearchResultProps> = ({
offset: page * pageSize,
limit: pageSize,
filters: {
branchId: cleanBranches
branchId: cleanBranches,
status: onShelf ? [HoldingsStatus.OnShelf] : [],
...(locationFilter?.location && { location: locationFilter.location }),
...(locationFilter?.sublocation && {
sublocation: locationFilter.sublocation
})
}
});

Expand All @@ -85,7 +96,7 @@ const AdvancedSearchResult: React.FC<AdvancedSearchResultProps> = ({
return;
}
setResultItems(resultWorks);
}, [data, page]);
}, [data, locationFilter, page]);

const shouldShowSearchResults = isLoading || (!isLoading && hitcount > 0);
const shouldShowResultHeadline = !!(hitcount && !isLoading);
Expand Down
30 changes: 29 additions & 1 deletion src/apps/advanced-search/CqlSearchHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import React, { useEffect } from "react";
import { useText } from "../../core/utils/text";
import CheckBox from "../../components/checkbox/Checkbox";
import TextInput from "../../components/atoms/input/TextInput";

export type CqlSearchHeaderProps = {
dataCy?: string;
initialCql: string;
setCql: (newState: string) => void;
onShelf: boolean;
handleOnShelfChange: (newState: boolean) => void;
onLocationChange: (location: string) => void;
onSublocationChange: (sublocation: string) => void;
};

const CqlSearchHeader: React.FC<CqlSearchHeaderProps> = ({
dataCy = "cql-search-header",
initialCql,
setCql
setCql,
onShelf,
handleOnShelfChange,
onLocationChange,
onSublocationChange
}) => {
const t = useText();

Expand All @@ -37,6 +47,24 @@ const CqlSearchHeader: React.FC<CqlSearchHeaderProps> = ({
onChange={(e) => setCql(e.target.value)}
defaultValue={initialCql}
/>
<TextInput
id="location"
label="Location"
type="text"
onChange={(location) => onLocationChange(location)}
/>
<TextInput
id="location"
label="Sublocation"
type="text"
onChange={(sublocation) => onSublocationChange(sublocation)}
/>
<CheckBox
id="on-shelf"
selected={onShelf}
onChecked={handleOnShelfChange}
label={t("advancedSearchFilterHoldingStatusText")}
/>
</>
);
};
Expand Down
4 changes: 4 additions & 0 deletions src/apps/advanced-search/LocationFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface LocationFilter {
location?: [string];
sublocation?: [string];
}
Loading

0 comments on commit e876a29

Please sign in to comment.