Skip to content

Commit

Permalink
feat: allow user to filter by access facet (#4133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fran McDade authored and Fran McDade committed Oct 31, 2024
1 parent 334b6dc commit a97be95
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 19 deletions.
3 changes: 3 additions & 0 deletions explorer/app/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type PickSome<T, K extends keyof T> = {
[P in K]: T[P];
};
10 changes: 9 additions & 1 deletion explorer/site-config/hca-dcp/cc-ma-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { SiteConfig } from "../../common/entities";
import { makeConfig } from "../dev/config";
import { getAuthenticationConfig } from "./authentication/authentication";
import { getMAExportConfig } from "./export/export";
import { getMAEntitiesConfig } from "./index/projectsEntityConfig";
import {
getMACategoryGroupConfig,
getMAEntitiesConfig,
} from "./index/projectsEntityConfig";

// Template constants
const BROWSER_URL =
Expand All @@ -29,6 +32,11 @@ export function makeManagedAccessConfig(config: SiteConfig): SiteConfig {
// Add authentication to the config.
cloneConfig.authentication = getAuthenticationConfig();

// Update categoryGroupConfig.
cloneConfig.categoryGroupConfig = getMACategoryGroupConfig(
cloneConfig.categoryGroupConfig
);

// Adding authentication to the header.
const header = { ...cloneConfig.layout.header };
cloneConfig.layout.header = { ...header, authenticationEnabled: true };
Expand Down
47 changes: 47 additions & 0 deletions explorer/site-config/hca-dcp/cc-ma-dev/index/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
CategoryGroup,
ColumnConfig,
ComponentConfig,
} from "@databiosphere/findable-ui/lib/config/entities";
import { ProjectsResponse } from "../../../../../app/apis/azul/hca-dcp/common/responses";
import { PickSome } from "../../../../../app/common/types";
import * as C from "../../../../../app/components";
import { mapSelectCategoryValue } from "../../../../../app/config/utils";
import * as V from "../../../../../app/viewModelBuilders/azul/hca-dcp/common/viewModelBuilders";
import {
HCA_DCP_CATEGORY_KEY,
HCA_DCP_CATEGORY_LABEL,
} from "../../../category";
import { mapAccessibleValue } from "./utils";

export const CATEGORY_GROUP: PickSome<
Record<keyof typeof HCA_DCP_CATEGORY_KEY, CategoryGroup>,
"ACCESSIBLE"
> = {
ACCESSIBLE: {
categoryConfigs: [
{
key: HCA_DCP_CATEGORY_KEY.ACCESSIBLE,
label: HCA_DCP_CATEGORY_LABEL.ACCESSIBLE,
mapSelectCategoryValue: mapSelectCategoryValue(mapAccessibleValue),
},
],
label: "Access",
},
};

export const COLUMN: PickSome<
Record<keyof typeof HCA_DCP_CATEGORY_KEY, ColumnConfig>,
"ACCESSIBLE"
> = {
ACCESSIBLE: {
componentConfig: {
component: C.StatusBadge,
viewBuilder: V.buildProjectAccess,
} as ComponentConfig<typeof C.StatusBadge, ProjectsResponse>,
disableSorting: true,
header: HCA_DCP_CATEGORY_LABEL.ACCESSIBLE,
id: HCA_DCP_CATEGORY_KEY.ACCESSIBLE,
width: "auto",
},
};
11 changes: 11 additions & 0 deletions explorer/site-config/hca-dcp/cc-ma-dev/index/common/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Returns "accessible" select category label for the given select category value.
* @param value - Value.
* @returns select category label.
*/
export function mapAccessibleValue(value: string): string {
if (value === "false") {
return "Required";
}
return "Granted";
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import {
ColumnConfig,
ComponentConfig,
EntityConfig,
SiteConfig,
} from "@databiosphere/findable-ui/lib/config/entities";
import { ProjectsResponse } from "../../../../app/apis/azul/hca-dcp/common/responses";
import * as C from "../../../../app/components";
import * as V from "../../../../app/viewModelBuilders/azul/hca-dcp/common/viewModelBuilders";
import { HCA_DCP_CATEGORY_KEY, HCA_DCP_CATEGORY_LABEL } from "../../category";
import { getMAProjectDetailTabs } from "../detail/project/mainColumn";
import { getMAProjectDetailTop } from "../detail/project/top";
import { listHero } from "../listView/projectsListHero";
import { CATEGORY_GROUP, COLUMN } from "./common/constants";

// Accessible column.
const COLUMN_ACCESS: ColumnConfig = {
componentConfig: {
component: C.StatusBadge,
viewBuilder: V.buildProjectAccess,
} as ComponentConfig<typeof C.StatusBadge, ProjectsResponse>,
disableSorting: true,
header: HCA_DCP_CATEGORY_LABEL.ACCESSIBLE,
id: HCA_DCP_CATEGORY_KEY.ACCESSIBLE,
width: "auto",
};
/**
* Returns managed access category group config.
* @param categoryGroupConfig - Category group config.
* @returns managed access category group config.
*/
export function getMACategoryGroupConfig(
categoryGroupConfig: SiteConfig["categoryGroupConfig"]
): SiteConfig["categoryGroupConfig"] {
if (categoryGroupConfig) {
return {
...categoryGroupConfig,
categoryGroups: [
CATEGORY_GROUP.ACCESSIBLE,
...categoryGroupConfig.categoryGroups,
],
};
}
}

/**
* Returns managed access entity config.
Expand Down Expand Up @@ -55,7 +57,7 @@ export function getMAProjectsEntityConfig(
// Clone columns.
const cloneColumns = [...cloneList.columns];
// Add accessible column.
cloneColumns.splice(1, 0, COLUMN_ACCESS); // Accessible column.
cloneColumns.splice(1, 0, COLUMN.ACCESSIBLE); // Accessible column.
cloneList.columns = cloneColumns;
cloneEntity.list = cloneList;
// Update list view.
Expand Down

0 comments on commit a97be95

Please sign in to comment.