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

GFF-232: change cohort export to all index filters #302

Merged
merged 2 commits into from
Jan 15, 2025
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
"dev:watch": " lerna watch -- lerna run dev --scope=\\$LERNA_PACKAGE_NAME",
"start": "lerna run start",
"build:start": "npm run build && npm run start",
"setProxy" : "(cd ./packages/tools/localDev/nginx/; ./configureNginx.sh -d $npm_config_domain)",
"test": "npm run test --workspaces",
"test:int": "npm run test:int --workspaces",
"test:all": "npm run test:all --workspaces"
32 changes: 26 additions & 6 deletions packages/core/src/features/cohort/cohortSlice.ts
Original file line number Diff line number Diff line change
@@ -14,13 +14,15 @@ export interface CohortState {
cohort: Cohort;
}

export const EmptyCohort: Cohort = {
id: 'default',
name: 'Filters',
filters: {},
modified_datetime: new Date().toISOString(),
};

const initialCohortState: CohortState = {
cohort: {
id: 'default',
name: 'Filters',
filters: {},
modified_datetime: new Date().toISOString(),
},
cohort: { ...EmptyCohort },
};

interface UpdateFilterParams {
@@ -34,6 +36,10 @@ interface SetFilterParams {
filters: FilterSet;
}

interface SetAllIndexFiltersParams {
filters: IndexedFilterSet;
}

interface RemoveFilterParams {
index: string;
field: string;
@@ -98,6 +104,18 @@ export const cohortSlice = createSlice({
},
};
},
setCohortIndexFilters: (
state: Draft<CohortState>,
action: PayloadAction<SetAllIndexFiltersParams>,
) => {
return {
cohort: {
...state.cohort,
filters: { ...action.payload.filters },
},
};
},

// removes a filter to the cohort filter set at the given index
removeCohortFilter: (
state: Draft<CohortState>,
@@ -149,6 +167,7 @@ export const cohortSlice = createSlice({
export const {
updateCohortFilter,
setCohortFilter,
setCohortIndexFilters,
removeCohortFilter,
clearCohortFilters,
} = cohortSlice.actions;
@@ -181,6 +200,7 @@ export const selectIndexedFilterByName = (
};

const EmptyFilterSet: FilterSet = { mode: 'and', root: {} };

/**
* Select a filter from the index.
* returns undefined.
2 changes: 2 additions & 0 deletions packages/core/src/features/cohort/index.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import {
selectCurrentCohort,
updateCohortFilter,
setCohortFilter,
setCohortIndexFilters,
removeCohortFilter,
clearCohortFilters,
} from './cohortSlice';
@@ -23,6 +24,7 @@ export {
cohortReducer,
updateCohortFilter,
setCohortFilter,
setCohortIndexFilters,
removeCohortFilter,
clearCohortFilters,
};
5 changes: 3 additions & 2 deletions packages/frontend/src/components/Buttons/UploadJSONButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Button, FileButton, Loader, Tooltip } from '@mantine/core';
import { Button, FileButton, Tooltip } from '@mantine/core';
import { Icon } from '@iconify/react';

interface UploadJSONButtonProps {
@@ -29,9 +29,10 @@ const UploadJSONButton: React.FC<UploadJSONButtonProps> = ({
}}
accept="application/json"
>
{() => (
{(props) => (
<Tooltip label={tooltip} disabled={!tooltip}>
<Button
{...props}
loading={processingFile}
variant="outline"
classNames={{ root: 'bg-base-max' }}
29 changes: 16 additions & 13 deletions packages/frontend/src/features/CohortBuilder/CohortSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import React from 'react';
import { Group } from '@mantine/core';
import JSONObjectDownloadButton from '../../components/Buttons/DownloadButtons/JSONObjectDownloadButton';
import { FilterSet, useCoreDispatch, setCohortFilter } from '@gen3/core';
import {
IndexedFilterSet,
useCoreDispatch,
setCohortIndexFilters,
selectCohortFilters,
useCoreSelector,
} from '@gen3/core';
import { useDeepCompareCallback } from 'use-deep-compare';
import UploadJSONButton from '../../components/Buttons/UploadJSONButton';

interface CohortSelectorProps {
showSelectedCohorts?: boolean;
readonly index: string;
readonly filters: FilterSet;
}

const CohortSelector: React.FC<CohortSelectorProps> = ({ index, filters }) => {
const CohortSelector = () => {
const dispatch = useCoreDispatch();
const getData = useDeepCompareCallback(() => {
return filters;
}, [filters]);

const cohortFilters = useCoreSelector(selectCohortFilters);

const getData = () => cohortFilters;

const setCohort = useDeepCompareCallback(
(data: string) => {
const jsonForm = JSON.parse(data);
dispatch(setCohortFilter({ index, filters: jsonForm as FilterSet }));
dispatch(
setCohortIndexFilters({ filters: jsonForm as IndexedFilterSet }),
);
},
[index, dispatch],
[dispatch],
);

return (
Original file line number Diff line number Diff line change
@@ -199,7 +199,7 @@ const QueryExpressionSection: React.FC<QueryExpressionSectionProps> = ({
</button>
)}
<div className="display flex gap-2 ml-auto mr-3">
<CohortSelector index={index} filters={filters} />
<CohortSelector />
<Tooltip
label={
noFilters