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

Filtered resource description fallback #197

Merged
merged 8 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
13 changes: 0 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"react-popper": "^2.3.0",
"react-responsive": "^9.0.2",
"react-router-dom": "^6.8.0",
"react-text-truncate": "^0.19.0",
"swagger-ui-react": "^5.11.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Resource/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Resource = ({ distributions, resource, title } : ResourcePropsType ) => {
</div>
{dist.data.description && (
<div className={'ds-u-measure--wide ds-u-margin-bottom--7'}>
<p className="dc-c-metadata-description ds-u-margin--0" dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(dist.data.description) }}/>
<div className="dc-c-metadata-description ds-u-margin--0" dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(dist.data.description) }}/>
</div>
)}
{fileFormat === "csv" && <ResourceInformation resource={resource} />}
Expand Down
21 changes: 5 additions & 16 deletions src/templates/FilteredResource/FilteredResourceBody.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
import React, { useEffect, useRef } from 'react';
import qs from 'qs';
import DOMPurify from 'dompurify';
import { Link, useNavigate } from 'react-router-dom';
import SwaggerUI from 'swagger-ui-react';
import useDatastore from '../../services/useDatastore';
import {
HelpDrawerToggle,
Button,
Tooltip,
Spinner,
Accordion,
AccordionItem,
} from '@cmsgov/design-system';
import {Spinner } from '@cmsgov/design-system';
import ResourceHeader from '../../components/ResourceHeader';
import ResourcePreview from '../../components/ResourcePreview';
import ResourceFooter from '../../components/ResourceFooter';
import { buildCustomColHeaders } from './functions';
import QueryBuilder from './QueryBuilder';
import TransformedDate from '../../components/TransformedDate';
import FilteredResourceDescription from './FilteredResourceDescription';
import 'swagger-ui-react/swagger-ui.css';

const FilteredResourceBody = ({
id,
dataset,
distIndex,
location,
apiDocPage,
additionalParams,
customColumns,
columnSettings,
Expand Down Expand Up @@ -76,6 +68,8 @@ const FilteredResourceBody = ({
? distribution.data.title
: dataset.title;

let description = "";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this variable used anywhere?


return (
<section className="ds-l-container ds-u-padding-bottom--3 ds-u-margin-bottom--2">
{Object.keys(distribution).length && (
Expand All @@ -90,12 +84,7 @@ const FilteredResourceBody = ({
<p className="ds-u-margin--0">Updated <TransformedDate date={dataset.modified} /></p>
</div>
<div className={'ds-l-md-col--9'}>
<div className={'ds-u-measure--wide ds-u-margin-bottom--7'}>
<p
className="ds-u-margin-top--0 dc-c-metadata-description"
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(distribution.data.description) }}
/>
</div>
<FilteredResourceDescription distribution={distribution} dataset={dataset} />
</div>
{resource.columns && Object.keys(resource.schema).length && (
<QueryBuilder
Expand Down
25 changes: 25 additions & 0 deletions src/templates/FilteredResource/FilteredResourceDescription.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import DOMPurify from 'dompurify';

const FilteredResourceDescription = ({distribution, dataset}) => {
if(!distribution && !dataset) {
return null;
}
let description = "";
if(distribution.data && distribution.data.description) {
description = distribution.data.description;
} else if(dataset.description) {
description = dataset.description
}

return (
<div className={'ds-u-measure--wide ds-u-margin-bottom--7'}>
<div
className="ds-u-margin-top--0 dc-c-metadata-description"
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(description) }}
/>
</div>
);
}

export default FilteredResourceDescription;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import FilteredResourceDescription from './FilteredResourceDescription';
import * as dataset from "../../tests/fixtures/dataset.json";
import * as distributionWithTitle from "../../tests/fixtures/distributionWithTitle.json"

describe('<FilteredResourceDescription />', () => {
test("Renders with distribution description over dataset description", () => {
render(
<FilteredResourceDescription
dataset={dataset}
distribution={distributionWithTitle.distribution[0]}
/>
);
expect(screen.getByText("Test Custom Description")).toBeInTheDocument();
});
test("Renders dataset description", () => {
render(
<FilteredResourceDescription
dataset={dataset}
distribution={dataset.distribution[0]}
/>
);
expect(screen.getByText("The data below contains newly reported, active covered outpatient drugs which were reported by participating drug manufacturers since the last quarterly update of the Drug Products in the Medicaid Drug Rebate Program (MDRP) database.")).toBeInTheDocument();
});
test("Doesn't render when no dataset or distribution is added", () => {
const { container } = render(<FilteredResourceDescription />);
expect(container.innerHTML).toBe("");
});
});
3 changes: 2 additions & 1 deletion src/templates/FilteredResource/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
import useMetastoreDataset from '../../services/useMetastoreDataset';
import PageNotFound from '../PageNotFound';
import FilteredResourceBody from './FilteredResourceBody';
import withQueryProvider from '../../utilities/QueryProvider/QueryProvider';
import "./filtered-resource.scss";

const FilteredResource = ({
Expand Down Expand Up @@ -80,4 +81,4 @@ const FilteredResource = ({
);
};

export default FilteredResource;
export default withQueryProvider(FilteredResource);