Skip to content

Commit

Permalink
DATAP-1611 Made Chart Error Notification Full-Width (#563)
Browse files Browse the repository at this point in the history
* Moved chart error notification to outside of the main chart wrapper, so that it can have full-width

* Updated margin for error notifications in general, and specialized ones in Trends Panel

* update dist

---------

Co-authored-by: Chanel Henley <[email protected]>
Co-authored-by: Richard Dinh <[email protected]>
  • Loading branch information
3 people authored Dec 4, 2024
1 parent 7fd8619 commit ec1235d
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 65 deletions.
4 changes: 2 additions & 2 deletions dist/ccdb5.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ccdb5.css.map

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions dist/ccdb5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ccdb5.js.map

Large diffs are not rendered by default.

18 changes: 6 additions & 12 deletions src/components/Charts/ChartWrapper/ChartWrapper.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import './ChartWrapper.scss';
import { ErrorBlock } from '../../Warnings/Error';
import PropTypes from 'prop-types';

export const ChartWrapper = ({ domId, hasKey, isEmpty }) => (
export const ChartWrapper = ({ domId, hasKey }) => (
<section className={`${hasKey ? 'ext-tooltip' : ''}`}>
{isEmpty ? (
<ErrorBlock text="Cannot display chart. Adjust your date range or date interval." />
) : (
<div className="chart-wrapper">
<p className="y-axis-label">Complaints</p>
<div id={domId} />
<p className="x-axis-label">Date received by the CFPB</p>
</div>
)}
<div className="chart-wrapper">
<p className="y-axis-label">Complaints</p>
<div id={domId} />
<p className="x-axis-label">Date received by the CFPB</p>
</div>
</section>
);

ChartWrapper.propTypes = {
domId: PropTypes.string.isRequired,
hasKey: PropTypes.bool.isRequired,
isEmpty: PropTypes.bool.isRequired,
};
7 changes: 0 additions & 7 deletions src/components/Charts/ChartWrapper/ChartWrapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ describe('ChartWrapper', () => {
render(<ChartWrapper hasKey={hasKey} isEmpty={isEmpty} domId={domId} />);
};

test('It renders warning when empty', () => {
renderComponent({ hasKey: false, isEmpty: true, domId: 'some-id' });
expect(screen.getByRole('alert')).toHaveTextContent(
'Cannot display chart. Adjust your date range or date interval',
);
});

test('It renders wrapper with data', () => {
renderComponent({ hasKey: false, isEmpty: false, domId: 'some-id' });
const text = screen.getByText('Date received by the CFPB');
Expand Down
18 changes: 13 additions & 5 deletions src/components/Charts/LineChart/LineChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
selectQueryDateInterval,
} from '../../../reducers/query/selectors';
import { ChartWrapper } from '../ChartWrapper/ChartWrapper';
import { ErrorBlock } from '../../Warnings/Error';

export const LineChart = () => {
const dispatch = useDispatch();
Expand All @@ -41,11 +42,14 @@ export const LineChart = () => {
const width = useSelector(selectViewWidth);

const hasTooltip = lens !== 'Overview';

const processData = useMemo(() => {
const dateRange = { from: dateFrom, to: dateTo };
return pruneIncompleteLineInterval(areaData, dateRange, interval);
}, [areaData, dateFrom, dateTo, interval]);

const isDataEmpty = isLineDataEmpty(processData);

useEffect(() => {
const dateRange = { from: dateFrom, to: dateTo };
const chartID = '#line-chart';
Expand Down Expand Up @@ -148,11 +152,15 @@ export const LineChart = () => {
width,
]);

if (isDataEmpty) {
return (
<ErrorBlock text="Cannot display chart. Adjust your date range or date interval." />
);
}

return (
<ChartWrapper
hasKey={hasTooltip}
domId="line-chart"
isEmpty={isLineDataEmpty(processData)}
/>
<section className="chart">
<ChartWrapper hasKey={hasTooltip} domId="line-chart" />
</section>
);
};
15 changes: 10 additions & 5 deletions src/components/Charts/StackedAreaChart/StackedAreaChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
selectViewWidth,
} from '../../../reducers/view/selectors';
import { ChartWrapper } from '../ChartWrapper/ChartWrapper';
import { ErrorBlock } from '../../Warnings/Error';

export const StackedAreaChart = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -152,11 +153,15 @@ export const StackedAreaChart = () => {
width,
]);

if (isDataEmpty) {
return (
<ErrorBlock text="Cannot display chart. Adjust your date range or date interval." />
);
}

return (
<ChartWrapper
hasKey={showTooltip}
domId="stacked-area-chart"
isEmpty={isDataEmpty}
/>
<section className="chart">
<ChartWrapper hasKey={showTooltip} domId="stacked-area-chart" />
</section>
);
};
4 changes: 2 additions & 2 deletions src/components/Trends/TrendsPanel/TrendsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ export const TrendsPanel = () => {
</strong>
</div>
<div className="layout-row">
<section className="chart">
<>
{chartType === 'line' && <LineChart />}
{chartType === 'area' && <StackedAreaChart />}
</section>
</>
{!hasOverview && <ExternalTooltip />}
</div>
</>
Expand Down
7 changes: 7 additions & 0 deletions src/components/Trends/TrendsPanel/TrendsPanel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@
margin-bottom: $gutter-normal;
}

.m-notification {
width: 100%;
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
}

@media screen and (min-width: $layout-breakpoint-tablet-min) and (max-width: $layout-breakpoint-tablet-max) {
padding-left: 20px;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Warnings/Error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getIcon from '../iconMap';
import PropTypes from 'prop-types';
import './Error.scss';

export const ErrorBlock = ({ text }) => (
<div
Expand Down
5 changes: 5 additions & 0 deletions src/components/Warnings/Error.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.error {
&.m-notification {
margin: 10px;
}
}

0 comments on commit ec1235d

Please sign in to comment.