Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion frontend/src/js/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ export interface HistorySources {

export type GetEntityHistoryDefaultParamsResponse = HistorySources & {
searchConcept: string | null; // concept id
searchFilters?: string[]; // allowlisted filter ids within the searchConcept
searchConnector: string | null; // connector id within the searchConcept, the table that holds the searchFilters
searchFilters?: string[]; // allowlisted filter ids within the searchConnector
};

export interface EntityInfo {
Expand Down
24 changes: 11 additions & 13 deletions frontend/src/js/entity-history/SearchEntities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
usePostResolveEntities,
} from "../api/api";
import { transformFilterValueToApi } from "../api/apiHelper";
import type { ConceptT, TableT } from "../api/types";
import type { TableT } from "../api/types";
import type { StateT } from "../app/reducers";
import PrimaryButton from "../button/PrimaryButton";
import { getConceptById } from "../concept-trees/globalTreeStoreHelper";
Expand All @@ -32,21 +32,19 @@ export const SearchEntites = ({
}: {
onLoad: (payload: LoadingPayload) => void;
}) => {
const searchConcept = useSelector<StateT, ConceptT | undefined>((state) => {
const searchConceptId = state.entityHistory.defaultParams.searchConcept;
const searchConceptTable = useSelector<StateT, TableT | undefined>(
(state) => {
const { searchConcept, searchConnector } =
state.entityHistory.defaultParams;
const concept = searchConcept ? getConceptById(searchConcept) : undefined;

return searchConceptId ? getConceptById(searchConceptId) : undefined;
});
if (!concept || !nodeIsElement(concept)) return undefined;

if (
!searchConcept ||
!nodeIsElement(searchConcept) ||
searchConcept.tables?.length !== 1
) {
return null;
}
return concept.tables?.find((t) => t.connectorId === searchConnector);
},
);

const searchConceptTable = searchConcept.tables[0];
if (!searchConceptTable) return null;

return <SearchEntitiesComponent table={searchConceptTable} onLoad={onLoad} />;
};
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/js/entity-history/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type EntityHistoryStateT = {
defaultParams: {
sources: HistorySources;
searchConcept: string | null;
searchConnector: string | null;
searchFilters: string[];
};
isLoading: boolean;
Expand All @@ -60,6 +61,7 @@ const initialState: EntityHistoryStateT = {
defaultParams: {
sources: { all: [], default: [] },
searchConcept: null,
searchConnector: null,
searchFilters: [],
},
label: "",
Expand Down Expand Up @@ -88,6 +90,7 @@ export default function reducer(
defaultParams: {
sources: { all: action.payload.all, default: action.payload.default },
searchConcept: action.payload.searchConcept,
searchConnector: action.payload.searchConnector,
searchFilters: action.payload.searchFilters || [],
},
};
Expand Down
Loading