Skip to content

Commit

Permalink
Merge pull request #3417 from BIZFactoryGmbH/feat/preview-adjustments
Browse files Browse the repository at this point in the history
Feat/preview adjustments
  • Loading branch information
awildturtok authored May 2, 2024
2 parents 0e37263 + 5a1172b commit 9dc1dc7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
10 changes: 8 additions & 2 deletions frontend/src/js/preview/Diagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { parseDate, parseStdDate } from "../common/helpers/dateHelper";
import { hexToRgbA } from "../entity-history/TimeStratifiedChart";

import { Theme, useTheme } from "@emotion/react";
import { Chart } from "chart.js";
import { useTranslation } from "react-i18next";
import {
formatNumber,
Expand Down Expand Up @@ -121,7 +120,10 @@ export default function Diagram({
plugins: {
title: {
display: true,
font: Chart.defaults.font,
font: {
weight: "normal",
size: 14,
},
position: "bottom",
text: stat.label,
},
Expand All @@ -146,6 +148,10 @@ export default function Diagram({
const yScaleTitle = {
display: true,
text: t("preview.chartYLabel"),
font: {
weight: "normal",
size: 14,
},
};

if (previewStatsIsBarStats(stat)) {
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/js/preview/HeadlineStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ const SxTooltipEntries = styled(TooltipEntries)`

export type HeadlineStatsProps = {
statistics: PreviewStatisticsResponse | null;
idLabel: string;
};

export default function HeadlineStats({ statistics }: HeadlineStatsProps) {
export default function HeadlineStats({
statistics,
idLabel,
}: HeadlineStatsProps) {
return (
<Root>
<SxTooltipEntries
matchingEntities={statistics?.entities}
matchingEntries={statistics?.total}
dateRange={statistics?.dateRange}
idLabel={idLabel}
/>
</Root>
);
Expand Down
20 changes: 17 additions & 3 deletions frontend/src/js/preview/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import styled from "@emotion/styled";
import { useState } from "react";
import { useMemo, useState } from "react";
import { useHotkeys } from "react-hotkeys-hook";
import { useTranslation } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";

import { StateT } from "../app/reducers";

import { PreviewStatistics } from "../api/types";
import { PreviewStatistics, SecondaryId } from "../api/types";
import { TransparentButton } from "../button/TransparentButton";
import FaIcon from "../icon/FaIcon";

Expand Down Expand Up @@ -79,13 +79,27 @@ const SxSelectBox = styled(SelectBox)`

export default function Preview() {
const preview = useSelector<StateT, PreviewStateT>((state) => state.preview);
const loadedSecondaryIds = useSelector<StateT, SecondaryId[]>(
(state) => state.conceptTrees.secondaryIds,
);
const dispatch = useDispatch();
const { t } = useTranslation();
const [selectBoxOpen, setSelectBoxOpen] = useState<boolean>(false);
const [page, setPage] = useState<number>(0);
const [popOver, setPopOver] = useState<PreviewStatistics | null>(null);
const onClose = () => dispatch(closePreview());
const statistics = preview.statisticsData;
const idLabel = useMemo(() => {
const primaryIdLabel = t("tooltip.entitiesFound", { count: 2 });
if (preview.queryData?.secondaryId) {
const secondaryIdLabel = loadedSecondaryIds.find(
(x) => x.id === preview.queryData?.secondaryId,
)?.label;
return t("preview.idLabel", { primaryIdLabel, secondaryIdLabel });
} else {
return `${t("queryEditor.secondaryIdStandard")} (${primaryIdLabel})`;
}
}, [preview.queryData, loadedSecondaryIds, t]);

useHotkeys("esc", () => {
if (!selectBoxOpen && !popOver) onClose();
Expand All @@ -110,7 +124,7 @@ export default function Preview() {
isOpen={selectBoxOpen}
setIsOpen={setSelectBoxOpen}
/>
<HeadlineStats statistics={statistics} />
<HeadlineStats statistics={statistics} idLabel={idLabel} />
</Headline>
{statistics ? (
<SxCharts
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/js/tooltip/TooltipEntries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import styled from "@emotion/styled";
import {
faArrowsLeftRightToLine,
faHashtag,
faMicroscope,
faUser,
} from "@fortawesome/free-solid-svg-icons";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -75,11 +76,12 @@ interface Props extends HTMLAttributes<HTMLDivElement> {
matchingEntries?: number | null;
matchingEntities?: number | null;
dateRange?: DateRangeT;
idLabel?: string;
}

const TooltipEntries = (props: Props) => {
const { t } = useTranslation();
const { matchingEntries, matchingEntities, dateRange } = props;
const { matchingEntries, matchingEntities, dateRange, idLabel } = props;

const isZero = props.matchingEntries === 0;
const isZeroEntities = props.matchingEntities === 0;
Expand All @@ -101,6 +103,15 @@ const TooltipEntries = (props: Props) => {

return (
<Root {...props}>
{idLabel && (
<>
<StyledFaIcon icon={faMicroscope} />
<Info>
<Date>{idLabel}</Date>
<Text zero={isZero}>{t("queryEditor.secondaryId")}</Text>
</Info>
</>
)}
<StyledFaIcon icon={faHashtag} />
<Info>
<Number zero={isZero}>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/localization/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@
"name": "Name",
"value": "Wert",
"densityPlot": "Dichtediagramm",
"chartYLabel": "Anzahl"
"chartYLabel": "Anzahl",
"idLabel": "{{primaryIdLabel}} und {{secondaryIdLabel}}"
},
"login": {
"headline": "Anfragen und Analyse",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@
"name": "Name",
"value": "Value",
"densityPlot": "Density Plot",
"chartYLabel": "Count"
"chartYLabel": "Count",
"idLabel": "{{primaryIdLabel}} and {{secondaryIdLabel}}"
},
"login": {
"headline": "Queries and Analyses",
Expand Down

0 comments on commit 9dc1dc7

Please sign in to comment.