Skip to content

Commit

Permalink
Merge pull request #56 from DANS-KNAW/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
ddzyne authored Dec 11, 2023
2 parents e9f2494 + e322eb6 commit a2860f5
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 207 deletions.
2 changes: 2 additions & 0 deletions apps/rda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"@dans-framework/theme": "workspace:*",
"@dans-framework/rdt-search-ui": "workspace:*",
"@fontsource/roboto": "^5.0.7",
"@mui/icons-material": "^5.14.3",
"@mui/material": "^5.14.3",
"html-react-parser": "^4.2.2",
"i18next": "^23.4.1",
"i18next-browser-languagedetector": "^7.1.0",
"i18next-resources-to-backend": "^1.1.4",
Expand Down
115 changes: 77 additions & 38 deletions apps/rda/src/pages/record/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Chip, Container } from "@mui/material";
import type { Result } from "@dans-framework/rdt-search-ui";
import React from "react";
import { useParams } from "react-router-dom";

import styles from "../search/index.module.css";
import Button from "@mui/material/Button";
import Typography from "@mui/material/Typography";
import Grid from "@mui/material/Unstable_Grid2";

interface RdaRecord {
card_url: string;
Expand Down Expand Up @@ -47,36 +48,51 @@ export function RdaRecord() {

return (
<Container>
<div style={{ margin: "3rem 0" }}>
<h2>{record.title || <i>empty</i>}</h2>
<p>{record.dc_description || ""}</p>
<MetadataList record={record} />
<div style={{ margin: "2rem 0" }}>
{record.page_url && (
<a href={record.page_url} style={{ marginRight: "1rem" }}>
<Chip label="RDA" />
</a>
)}
{record.uri && (
<a href={record.uri} style={{ marginRight: "1rem" }}>
<Chip label="Zenodo" />
</a>
)}
{record.pid_lod && (
<a href={record.pid_lod}>
<Chip label="DOI" />
</a>
)}
</div>
<ShowJSON record={record} />
</div>
<Grid container>
<Grid
sm={10}
md={8}
lg={7}
smOffset={1}
mdOffset={2}
lgOffset={2.5}
pt={4}
>
<Typography variant="h3">
{record.title || <i>Untitled</i>}
</Typography>
<Typography gutterBottom>{record.dc_description || ""}</Typography>

<MetadataList record={record} />

<div style={{ margin: "2rem 0" }}>
{record.page_url && (
<a href={record.page_url} style={{ marginRight: "1rem" }}>
<Chip label="RDA" />
</a>
)}
{record.uri && (
<a href={record.uri} style={{ marginRight: "1rem" }}>
<Chip label="Zenodo" />
</a>
)}
{record.pid_lod && (
<a href={record.pid_lod}>
<Chip label="DOI" />
</a>
)}
</div>
<ShowJSON record={record} />
</Grid>
</Grid>
</Container>
);
}

const style = {
display: "grid",
gridTemplateColumns: "200px 1fr",
gridTemplateColumns: "1fr 4fr",
marginBottom: "0.25rem",
};

function Metadata({ name, value }: { name: string; value: string | string[] }) {
Expand All @@ -85,35 +101,58 @@ function Metadata({ name, value }: { name: string; value: string | string[] }) {
const _value = Array.isArray(value) ? value.join(" / ") : value;

return (
<li style={style}>
<div style={{ color: "gray" }}>{name}</div>
<div>{_value}</div>
</li>
<div style={style}>
<Typography variant="body2" color="neutral.dark" pr={1}>
{name}
</Typography>
<Typography
variant="body2"
sx={{
overflow: "hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis",
}}
>
{_value}
</Typography>
</div>
);
}

export function MetadataList({ record }: { record: RdaRecord | Result }) {
return (
<ul style={{ listStyle: "none", margin: 0, padding: 0 }}>
<Metadata name="Language" value={record.dc_language} />
<div>
{record.dc_language && (
<Metadata name="Language" value={record.dc_language} />
)}
<Metadata name="Individuals" value={record.individuals} />
<Metadata name="Rights" value={record.resource_rights_types} />
<Metadata name="Relations" value={record.relation_types} />
<Metadata name="Workflows" value={record.workflows} />
<Metadata name="Pathways" value={record.pathways} />
</ul>
</div>
);
}

function ShowJSON({ record }: { record: RdaRecord }) {
const [active, setActive] = React.useState(false);

return (
<div className={styles.showjson}>
<button onClick={() => setActive(!active)}>
<>
<Button onClick={() => setActive(!active)} variant="contained">
{active ? "Hide" : "Show"} JSON
</button>
{active && <pre>{JSON.stringify(record, undefined, 3)}</pre>}
</div>
</Button>
{active && (
<pre
style={{
background: "rgba(0,0,0,0.1)",
padding: "1rem",
overflow: "auto",
}}
>
{JSON.stringify(record, undefined, 3)}
</pre>
)}
</>
);
}
52 changes: 1 addition & 51 deletions apps/rda/src/pages/search/index.module.css
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
.wrapper {
margin: auto;
max-width: 1400px;
padding-top: 4rem;
padding-top: 2rem;
}

.result {
background: white;
box-shadow: 0 0px 20px #DDD;
margin: 0 0 2rem 0;
padding: 1rem;
}

.result em {
background: yellow;
}

.header {
display: grid;
grid-template-columns: 1fr fit-content(0);
grid-gap: 1rem;
}

.header h3 {
margin-top: 0;
}

.header div {
color: gray;
white-space: nowrap;
}

.description {
margin-bottom: 1rem;
}

.showjson pre {
background: rgba(0, 0, 255, .05);
border: 1px solid darkblue;
border-radius: .25rem;
overflow: hidden;
padding: 1rem;
}

.showjson button,
.description button {
background: none;
border: none;
color: #007bff;
cursor: pointer;
font-size: 0.8rem;
padding: 0;
}
5 changes: 0 additions & 5 deletions apps/rda/src/pages/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import { useNavigate } from "react-router-dom";
import styles from "./index.module.css";

const config: Partial<RDTSearchUIProps> = {
style: {
background: "#F6F6F6",
buttonBackground: "#ececec",
},
fullTextFields: ["title^2", "dc_description"],
fullTextHighlight: {
fields: {
Expand All @@ -42,7 +38,6 @@ export function RdaSearch({
url={`${
import.meta.env.VITE_ELASTICSEARCH_API_ENDPOINT
}/dans-rda2/_search`}
style={config.style}
>
<DateChartFacet
config={{
Expand Down
82 changes: 41 additions & 41 deletions apps/rda/src/pages/search/result.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import type { ResultBodyProps } from "@dans-framework/rdt-search-ui";

import React from "react";

import styles from "./index.module.css";
import { useState } from "react";
import { MetadataList } from "../record";
import parse from "html-react-parser";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";

export function Rda2Result(props: ResultBodyProps) {
const { result: item } = props;

const title = item.highlight?.title?.[0] || item.title || "<i>empty</i>";

return (
<div className={styles.result}>
<header className={styles.header}>
<h3 dangerouslySetInnerHTML={{ __html: title }} />
{item.dc_date && <div>{new Date(item.dc_date).toDateString()}</div>}
</header>
{/* <div className="descriptions" dangerouslySetInnerHTML={{ __html: description }} /> */}
<>
<Typography variant="h5">{parse(title)}</Typography>
{item.dc_date && (
<Typography variant="body2" gutterBottom>
{new Date(item.dc_date).toDateString()}
</Typography>
)}
<ReadMore item={item} />
<MetadataList record={item} />
</div>
</>
);
}

function ReadMore({ item }: { item: ResultBodyProps["result"] }) {
const [active, setActive] = React.useState(false);

const hasHighlight = item.highlight?.dc_description?.[0] != null;
const [active, setActive] = useState(false);

// No description, return nothing
if (item.dc_description == null) return null;

// Highlighted description, return it
if (hasHighlight) {
return (
<div
className={styles.description}
dangerouslySetInnerHTML={{
__html: item.highlight?.dc_description?.[0] as string,
}}
/>
);
}
if (item.dc_description === null) return null;

const [visibleText, hiddenText] = item.dc_description.split(/\. (.*)/);
const [visibleText, hiddenText] = [
item.dc_description.substring(0, 180),
item.dc_description.substring(180),
];

// There is only one sentence, return it
if (hiddenText == null || hiddenText.trim().length === 0) {
return <div className={styles.description}>{visibleText}</div>;
return <Typography variant="body1">{visibleText}</Typography>;
}

return (
<div className={styles.description}>
{visibleText}.{active && ` ${hiddenText}`}
&nbsp;
<button
onClick={(ev) => {
ev.stopPropagation();
setActive(!active);
}}
>
{active ? "Read less" : "Read more"}
</button>
</div>
<>
<Typography mb={2}>
{`${visibleText}${
visibleText.length < item.dc_description.length && !active
? "..."
: hiddenText
}`}
<Button
size="small"
onClick={(ev) => {
ev.stopPropagation();
setActive(!active);
}}
sx={{ fontSize: 10, pt: 0.1, pb: 0.1 }}
endIcon={active ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />}
>
{active ? "Read less" : "Read more"}
</Button>
</Typography>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ const AutocompleteAPIField = ({
// only for freesolo, add input directly as option
if (
field.allowFreeText &&
!isLoading &&
!isLoading &&
!isFetching &&
debouncedInputValue === inputValue
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rdt-search-ui
Submodule rdt-search-ui updated 37 files
+3 −0 package.json
+123 −88 src/app.tsx
+4 −1 src/context/props/index.ts
+20 −65 src/dashboard.tsx
+8 −0 src/facets/chart/view/chart.tsx
+1 −14 src/facets/chart/view/index.module.css
+84 −26 src/facets/index.tsx
+20 −26 src/facets/list/view/list-view.tsx
+60 −90 src/facets/list/view/options.tsx
+20 −57 src/facets/list/view/value.tsx
+0 −1 src/facets/wrapper.module.css
+11 −32 src/facets/wrapper.tsx
+0 −12 src/index.tsx
+0 −53 src/views/active-filters/index.module.css
+52 −49 src/views/active-filters/index.tsx
+0 −33 src/views/active-filters/save-search/load-search.module.css
+31 −26 src/views/active-filters/save-search/load-search.tsx
+0 −10 src/views/active-filters/save-search/save-search.module.css
+21 −19 src/views/active-filters/save-search/save-search.tsx
+11 −46 src/views/active-filters/value.tsx
+14 −56 src/views/full-text-search/index.tsx
+0 −35 src/views/full-text-search/input.module.css
+31 −35 src/views/full-text-search/input.tsx
+0 −29 src/views/header/index.module.css
+24 −16 src/views/header/index.tsx
+2 −3 src/views/header/result-count/index.tsx
+4 −23 src/views/header/result-count/order-by/index.tsx
+15 −54 src/views/header/result-count/order-by/option.tsx
+12 −106 src/views/pagination/index.tsx
+0 −19 src/views/search-result/components.tsx
+89 −25 src/views/search-result/index.tsx
+0 −18 src/views/ui/button.module.css
+2 −3 src/views/ui/drop-down/help.tsx
+0 −66 src/views/ui/drop-down/index.module.css
+30 −58 src/views/ui/drop-down/index.tsx
+0 −16 src/views/ui/input.module.css
+0 −12 src/views/ui/label.tsx
8 changes: 6 additions & 2 deletions packages/user-auth/src/languages/locales/en/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"submittedTo": "Submitted to",
"submissionStatus": "Status",
"processing": "Processing your submission",
"error": "Error with your submission",
"success": "Succesfully submitted"
"error": "Error with your submission, click to see details",
"success": "Succesfully submitted",
"moreInfo": "Error",
"errorExplanation": "This is the error we got back from the server",
"retryItem": "Correct the error and try again",
"copyItem": "Copy this dataset for a new submission"
}
8 changes: 6 additions & 2 deletions packages/user-auth/src/languages/locales/nl/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"submittedTo": "Gesubmit naar",
"submissionStatus": "Status",
"processing": "Bezig met verwerken",
"error": "Fout bij het verwerken van je data",
"success": "Succesvol gesubmit"
"error": "Fout bij het verwerken van je data, click om details te zien",
"success": "Succesvol gesubmit",
"moreInfo": "Fout",
"errorExplanation": "Dit is de foutmelding die we van de server terugkregen",
"retryItem": "Verbeter de foutmelding en probeer opnieuw",
"copyItem": "Kopiëer deze dataset voor een nieuwe submissie"
}
Loading

0 comments on commit a2860f5

Please sign in to comment.