Skip to content

Commit

Permalink
Changes default label from Default to Filters in explorer (#226)
Browse files Browse the repository at this point in the history
* change counts and Default label on Cohort builder

* v0.10.40

* revert .env.development
  • Loading branch information
craigrbarnes authored Aug 21, 2024
1 parent 040aa21 commit 8fc185a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 51 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"packages": ["packages/*"],
"useWorkspaces": true,
"version": "0.10.39"
"version": "0.10.40"
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gen3/core",
"version": "0.10.39",
"version": "0.10.40",
"author": "CTDS",
"description": "Core module for gen3 frontend. Provides an interface for interacting with the gen3 API and a redux store for managing state.",
"license": "Apache-2.0",
Expand Down
55 changes: 34 additions & 21 deletions packages/core/src/features/cohort/cohortSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export interface CohortState {
const initialCohortState: CohortState = {
cohort: {
id: 'default',
name: 'Default',
filters: { },
name: 'Filters',
filters: {},
modified_datetime: new Date().toISOString(),
},
};
Expand Down Expand Up @@ -59,23 +59,29 @@ export const cohortSlice = createSlice({
// adds a filter to the cohort filter set at the given index
updateCohortFilter: (
state: Draft<CohortState>,
action: PayloadAction<UpdateFilterParams>
action: PayloadAction<UpdateFilterParams>,
) => {
const { index, field, filter } = action.payload;
return {
cohort: {
...state.cohort,
filters: {
...state.cohort.filters,
[index]: { mode: state.cohort.filters?.[index]?.mode ?? 'and', root: { ...state.cohort.filters?.[index]?.root ?? {}, [field]: filter } },
[index]: {
mode: state.cohort.filters?.[index]?.mode ?? 'and',
root: {
...(state.cohort.filters?.[index]?.root ?? {}),
[field]: filter,
},
},
},
},
};
},
// removes a filter to the cohort filter set at the given index
removeCohortFilter: (
state: Draft<CohortState>,
action: PayloadAction<RemoveFilterParams>
action: PayloadAction<RemoveFilterParams>,
) => {
const { index, field } = action.payload;
const filters = state.cohort?.filters?.[index]?.root;
Expand All @@ -86,32 +92,36 @@ export const cohortSlice = createSlice({
return {
cohort: {
...state.cohort,
filters: { ...state.cohort.filters, [index]: {
mode: state.cohort.filters[index].mode,
root: updated
} },
filters: {
...state.cohort.filters,
[index]: {
mode: state.cohort.filters[index].mode,
root: updated,
},
},
},
};
},
// removes all filters from the cohort filter set at the given index
clearCohortFilters: (
state: Draft<CohortState>,
action: PayloadAction<ClearAllFilterParams>
action: PayloadAction<ClearAllFilterParams>,
) => {
const { index } = action.payload;
return {
cohort: {
...state.cohort,
filters: {
...state.cohort.filters,
[index]: { // empty filter set
[index]: {
// empty filter set
mode: 'and',
root: {},
} as FilterSet
}
}
} as FilterSet,
},
},
};
}
},
},
extraReducers: {},
});
Expand All @@ -120,14 +130,17 @@ export const cohortSlice = createSlice({
export const { updateCohortFilter, removeCohortFilter, clearCohortFilters } =
cohortSlice.actions;

export const selectCohortFilters = (state: CoreState) : IndexedFilterSet =>
export const selectCohortFilters = (state: CoreState): IndexedFilterSet =>
state.cohorts.cohort.filters;

export const selectCurrentCohortId = (state: CoreState) : string => state.cohorts.cohort.id;
export const selectCurrentCohortId = (state: CoreState): string =>
state.cohorts.cohort.id;

export const selectCurrentCohort = (state: CoreState) : Cohort => state.cohorts.cohort;
export const selectCurrentCohort = (state: CoreState): Cohort =>
state.cohorts.cohort;

export const selectCurrentCohortName = (state: CoreState) : string => state.cohorts.cohort.name;
export const selectCurrentCohortName = (state: CoreState): string =>
state.cohorts.cohort.name;

/**
* Select a filter by its name from the current cohort. If the filter is not found
Expand All @@ -139,7 +152,7 @@ export const selectCurrentCohortName = (state: CoreState) : string => state.coho
export const selectIndexedFilterByName = (
state: CoreState,
index: string,
name: string
name: string,
): Operation | undefined => {
return state.cohorts.cohort.filters[index]?.root[name];
};
Expand All @@ -153,7 +166,7 @@ const EmptyFilterSet: FilterSet = { mode: 'and', root: {} };
*/
export const selectIndexFilters = (
state: CoreState,
index: string
index: string,
): FilterSet => {
return state.cohorts.cohort.filters?.[index] ?? EmptyFilterSet; // TODO: check if this is undefined
};
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gen3/frontend",
"version": "0.10.39",
"version": "0.10.40",
"description": "Gen3 frontend components, content management, and pages",
"keywords": [],
"author": "Center for Translational Data Science",
Expand Down
40 changes: 19 additions & 21 deletions packages/frontend/src/components/counts/CountsValue.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import { Button, LoadingOverlay, Text} from '@mantine/core';

import {
FilterSet,
useGetCountsQuery,
} from '@gen3/core';

import { Paper, LoadingOverlay, Text } from '@mantine/core';

interface CountsValueProps {
readonly label: string;
readonly counts?: number;
readonly isSuccess: boolean;
readonly label: string;
readonly counts?: number;
readonly isSuccess: boolean;
}

const CountsValue = ({ label, isSuccess, counts }: CountsValueProps) => {

// TODO handle case of data.length == 1
return (
<div className="mr-4">
<LoadingOverlay visible={!isSuccess} />
<Button color="primary" variant="filled">
{`${counts?.toLocaleString() ?? '...'} ${label}`}
</Button>
</div>
);
const CountsValue = ({ label, isSuccess, counts }: CountsValueProps) => {
// TODO handle case of data.length == 1
return (
<div className="mr-4">
<LoadingOverlay visible={!isSuccess} />
<Paper
shadow="xs"
p="xs"
withBorder
className="bg-primary font-heading text-md font-semibold"
>
{`${counts?.toLocaleString() ?? '...'} ${label}`}
</Paper>
</div>
);
};

export default CountsValue;
2 changes: 1 addition & 1 deletion packages/sampleCommons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gen3/samplecommons",
"version": "0.10.39",
"version": "0.10.40",
"private": true,
"scripts": {
"lint": "next lint",
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gen3/toolsff",
"version": "0.10.39",
"version": "0.10.40",
"description": "tools for processing portal content",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit 8fc185a

Please sign in to comment.