Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/maven/backend/io.github.classg…
Browse files Browse the repository at this point in the history
…raph-classgraph-4.8.112
  • Loading branch information
thoniTUB authored Jun 25, 2024
2 parents 81d7f72 + 02aaa17 commit 4ad9a6a
Show file tree
Hide file tree
Showing 32 changed files with 740 additions and 680 deletions.
7 changes: 2 additions & 5 deletions frontend/src/js/concept-trees/ConceptTreeSearchBox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from "@emotion/styled";
import { FC, useCallback, useRef } from "react";
import { useCallback, useRef } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";

Expand Down Expand Up @@ -48,11 +48,8 @@ const TopRow = styled("div")`
align-items: center;
gap: 5px;
`;
interface PropsT {
className?: string;
}

const ConceptTreeSearchBox: FC<PropsT> = ({ className }) => {
const ConceptTreeSearchBox = ({ className }: { className?: string }) => {
const showMismatches = useSelector<StateT, boolean>(
(state) => state.conceptTrees.search.showMismatches,
);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/js/entity-history/ContentControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ const ContentControl = ({ value, onChange }: Props) => {

export const useContentControl = () => {
const [contentFilter, setContentFilter] = useState<ContentFilterValue>({
groupId: false,
groupId: true,
secondaryId: true,
concept: true,
money: true,
rest: false,
rest: true,
dates: true,
});

Expand Down
195 changes: 6 additions & 189 deletions frontend/src/js/entity-history/History.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import styled from "@emotion/styled";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useCallback, useMemo, useState } from "react";
import { ErrorBoundary } from "react-error-boundary";
import { useHotkeys } from "react-hotkeys-hook";
import { useTranslation } from "react-i18next";
import { useSelector } from "react-redux";

import type {
EntityInfo,
HistorySources,
ResultUrlWithLabel,
SelectOptionT,
TimeStratifiedInfo,
Expand All @@ -24,13 +23,16 @@ import { EntityHeader } from "./EntityHeader";
import InteractionControl from "./InteractionControl";
import type { LoadingPayload } from "./LoadHistoryDropzone";
import { Navigation } from "./Navigation";
import SearchControl from "./SearchControl";
import SourcesControl from "./SourcesControl";
import { Timeline } from "./Timeline";
import VisibilityControl from "./VisibilityControl";
import { useUpdateHistorySession } from "./actions";
import { EntityId } from "./reducer";
import { TimelineSearchProvider } from "./timelineSearchState";
import SearchControl from "./timeline-search/SearchControl";
import { TimelineSearchProvider } from "./timeline-search/timelineSearchState";
import { useEntityStatus } from "./useEntityStatus";
import { useOpenCloseInteraction } from "./useOpenCloseInteraction";
import { useSourcesControl } from "./useSourcesControl";

const FullScreen = styled("div")`
position: fixed;
Expand Down Expand Up @@ -270,188 +272,3 @@ export const History = () => {
</TimelineSearchProvider>
);
};

export const useDefaultStatusOptions = () => {
const { t } = useTranslation();

return useMemo(
() => [
{
label: t("history.options.check"),
value: t("history.options.check") as string,
},
{
label: t("history.options.noCheck"),
value: t("history.options.noCheck") as string,
},
],
[t],
);
};

const useEntityStatus = ({
currentEntityId,
}: {
currentEntityId: string | null;
}) => {
const defaultStatusOptions = useDefaultStatusOptions();
const [entityStatusOptions, setEntityStatusOptions] =
useState<SelectOptionT[]>(defaultStatusOptions);

const [entityIdsStatus, setEntityIdsStatus] = useState<EntityIdsStatus>({});
const setCurrentEntityStatus = useCallback(
(value: SelectOptionT[]) => {
if (!currentEntityId) return;

setEntityIdsStatus((curr) => ({
...curr,
[currentEntityId]: value,
}));
},
[currentEntityId],
);
const currentEntityStatus = useMemo(
() => (currentEntityId ? entityIdsStatus[currentEntityId] || [] : []),
[currentEntityId, entityIdsStatus],
);

return {
entityStatusOptions,
setEntityStatusOptions,
entityIdsStatus,
setEntityIdsStatus,
currentEntityStatus,
setCurrentEntityStatus,
};
};

const useSourcesControl = () => {
const [sourcesFilter, setSourcesFilter] = useState<SelectOptionT[]>([]);

const sources = useSelector<StateT, HistorySources>(
(state) => state.entityHistory.defaultParams.sources,
);
const allSourcesOptions = useMemo(
() =>
sources.all.map((s) => ({
label: s.label,
value: s.label, // Gotta use label since the value in the entity CSV is the source label as well
})),
[sources.all],
);
const defaultSourcesOptions = useMemo(
() =>
sources.default.map((s) => ({
label: s.label,
value: s.label, // Gotta use label since the value in the entity CSV is the source label as well
})),
[sources.default],
);

// TODO: Figure out whether we still need the current entity unique sources
//
// const currentEntityUniqueSources = useSelector<StateT, string[]>(
// (state) => state.entityHistory.currentEntityUniqueSources,
// );
// const currentEntitySourcesOptions = useMemo(
// () =>
// currentEntityUniqueSources.map((s) => ({
// label: s,
// value: s,
// })),
// [currentEntityUniqueSources],
// );

const sourcesSet = useMemo(
() => new Set(sourcesFilter.map((o) => o.value as string)),
[sourcesFilter],
);

useEffect(
function takeDefaultIfEmpty() {
setSourcesFilter((curr) =>
curr.length === 0 ? defaultSourcesOptions : curr,
);
},
[defaultSourcesOptions],
);

return {
options: allSourcesOptions,
sourcesSet,
sourcesFilter,
setSourcesFilter,
};
};

const useOpenCloseInteraction = () => {
const [isOpen, setIsOpen] = useState<Record<string, boolean>>({});
const isOpenRef = useRef(isOpen);
isOpenRef.current = isOpen;

const toId = useCallback(
(year: number, quarter?: number) => `${year}-${quarter}`,
[],
);

const getIsOpen = useCallback(
(year: number, quarter?: number) => {
if (quarter) {
return isOpen[toId(year, quarter)];
} else {
return [1, 2, 3, 4].every((q) => isOpen[toId(year, q)]);
}
},
[isOpen, toId],
);

const toggleOpenYear = useCallback(
(year: number) => {
const quarters = [1, 2, 3, 4].map((quarter) => toId(year, quarter));
const wasOpen = quarters.some((quarter) => isOpenRef.current[quarter]);

setIsOpen((prev) => ({
...prev,
...Object.fromEntries(quarters.map((quarter) => [quarter, !wasOpen])),
}));
},
[toId],
);

const toggleOpenQuarter = useCallback(
(year: number, quarter: number) => {
const id = toId(year, quarter);

setIsOpen((prev) => ({ ...prev, [id]: !prev[id] }));
},
[toId],
);

const closeAll = useCallback(() => {
setIsOpen({});
}, []);

const openAll = useCallback(() => {
const lastYearsToUse = 20;
const currYear = new Date().getFullYear();
const years = [...Array(lastYearsToUse).keys()].map((i) => currYear - i);

const newIsOpen: Record<string, boolean> = {};

for (const year of years) {
for (const quarter of [1, 2, 3, 4]) {
newIsOpen[toId(year, quarter)] = true;
}
}

setIsOpen(newIsOpen);
}, [toId]);

return {
getIsOpen,
toggleOpenYear,
toggleOpenQuarter,
closeAll,
openAll,
};
};
2 changes: 1 addition & 1 deletion frontend/src/js/entity-history/SearchEntities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
MultiSelectFilterWithValueType,
} from "../standard-query-editor/types";

import { useDefaultStatusOptions } from "./History";
import { LoadingPayload } from "./LoadHistoryDropzone";
import { useDefaultStatusOptions } from "./useDefaultStatusOptions";

export const SearchEntites = ({
onLoad,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SmallTabNavigation from "../small-tab-navigation/SmallTabNavigation";

import { TimeStratifiedChart } from "./TimeStratifiedChart";
import { TimeStratifiedConceptChart } from "./TimeStratifiedConceptChart";
import { isConceptColumn, isMoneyColumn } from "./timeline/util";
import { isConceptColumn, isMoneyColumn } from "./timeline/util/util";

const Container = styled("div")`
align-self: flex-start;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/js/entity-history/TimeStratifiedChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Bar } from "react-chartjs-2";
import { TimeStratifiedInfo } from "../api/types";
import { exists } from "../common/helpers/exists";

import { formatCurrency } from "./timeline/util";
import { formatCurrency } from "./timeline/util/util";

const TRUNCATE_X_AXIS_LABELS_LEN = 18;

Expand Down
Loading

0 comments on commit 4ad9a6a

Please sign in to comment.