Skip to content

Commit

Permalink
Merge branch '354-generic-resource-list' into update-app-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscoder committed Dec 6, 2024
2 parents 86dc77c + 73fc700 commit 27d933b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
40 changes: 20 additions & 20 deletions src/components/SearchBar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,48 @@ export enum SearchBarColumnType {
export interface SearchBarProps {
columns: SearchBarColumn[];
}
export type SearchBarStringColumn = {

type SearchBarColumnBase = {
id: string;
searchParam?: string;
};

export type SearchBarStringColumn = SearchBarColumnBase & {
type: SearchBarColumnType.STRING;
placeholder: string;
};
export type SearchBarDateColumn = {
id: string;
export type SearchBarDateColumn = SearchBarColumnBase & {
type: SearchBarColumnType.DATE;
placeholder: [string, string];
};
export type SearchBarSingleDateColumn = {
id: string;
export type SearchBarSingleDateColumn = SearchBarColumnBase & {
type: SearchBarColumnType.SINGLEDATE;
placeholder: string;
defaultValue?: moment.Moment;
};
export type SearchBarReferenceColumn = {
id: string;
export type SearchBarReferenceColumn = SearchBarColumnBase & {
type: SearchBarColumnType.REFERENCE;
expression: Expression['expression'];
path: QuestionnaireItemChoiceColumn['path'];
placeholder: string;
};
export type SearchBarChoiceColumn = {
id: string;
export type SearchBarChoiceColumn = SearchBarColumnBase & {
type: SearchBarColumnType.CHOICE;
repeats?: boolean;
placeholder: string;
defaultValue?: ValueSetOption;
} & (
| {
options: ValueSetOption[];
valueSet?: never;
}
| {
options?: never;
valueSet: ValueSet['id'];
}
);
| {
options: ValueSetOption[];
valueSet?: never;
}
| {
options?: never;
valueSet: ValueSet['id'];
}
);

export type SearchBarSolidChoiceColumn = {
id: string;
export type SearchBarSolidChoiceColumn = SearchBarColumnBase & {
type: SearchBarColumnType.SOLIDCHOICE;
repeats?: boolean;
placeholder: string;
Expand Down
5 changes: 3 additions & 2 deletions src/containers/PatientResourceListExample/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function PatientResourceListExample() {
headerTitle={t`Patients`}
resourceType="Patient"
searchParams={searchParams}
tableColumns={[
getTableColumns={() => [
{
title: <Trans>Name</Trans>,
dataIndex: 'name',
Expand All @@ -59,9 +59,10 @@ export function PatientResourceListExample() {
width: '25%',
},
]}
searchBarColumns={[
getFilters={() => [
{
id: 'name',
searchParam: 'name',
type: SearchBarColumnType.STRING,
placeholder: t`Find patient`,
},
Expand Down
2 changes: 1 addition & 1 deletion src/uberComponents/ResourceListPage/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function useResourceListPage<R extends Resource>(
const searchBarSearchParams = {
...Object.fromEntries(
debouncedFilterValues.map((filterValue) => [
filterValue.column.id,
filterValue.column.searchParam ?? filterValue.column.id,
getSearchBarColumnFilterValue(filterValue),
]),
),
Expand Down
22 changes: 13 additions & 9 deletions src/uberComponents/ResourceListPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { SearchBarColumn } from '../../components/SearchBar/types';

type RecordType<R extends Resource> = { resource: R; bundle: Bundle };

interface ActionManager {
interface TableManager {
reload: () => void;
}

Expand All @@ -57,19 +57,19 @@ interface ResourceListPageProps<R extends Resource> {
/* Default search params */
searchParams?: SearchParams;

/* Search bar columns that displayed before the table */
searchBarColumns?: SearchBarColumn[];
/* Filter that are displayed in the search bar and inside table columns */
getFilters?: () => SearchBarColumn[];

/* Table columns without action column - action column is generated based on `getRecordActions` */
tableColumns: ColumnsType<RecordType<R>>;
getTableColumns: (manager: TableManager) => ColumnsType<RecordType<R>>;

/**
* Record actions list that is displayed in the table per record
* (for example, edit organization)
*/
getRecordActions?: (
record: RecordType<R>,
manager: ActionManager,
manager: TableManager,
) => Array<QuestionnaireActionType | NavigationActionType | CustomActionType>;

/**
Expand Down Expand Up @@ -102,10 +102,14 @@ export function ResourceListPage<R extends Resource>({
getRecordActions,
getHeaderActions,
getBatchActions,
searchBarColumns,
tableColumns,
getFilters,
getTableColumns,
defaultLaunchContext,
}: ResourceListPageProps<R>) {
const allFilters = getFilters?.() ?? [];
// TODO: filter out column filters
const searchBarColumns = allFilters;

const { columnsFilterValues, onChangeColumnFilter, onResetFilters } = useSearchBar({
columns: searchBarColumns ?? [],
});
Expand Down Expand Up @@ -200,7 +204,7 @@ export function ResourceListPage<R extends Resource>({
rowKey={(p) => p.resource.id!}
dataSource={isSuccess(recordResponse) ? recordResponse.data : []}
columns={[
...tableColumns,
...getTableColumns({ reload }),
...(getRecordActions
? [
getRecordActionsColumn({
Expand All @@ -224,7 +228,7 @@ function getRecordActionsColumn<R extends Resource>({
}: {
getRecordActions: (
record: RecordType<R>,
manager: ActionManager,
manager: TableManager,
) => Array<QuestionnaireActionType | NavigationActionType | CustomActionType>;
defaultLaunchContext?: ParametersParameter[];
reload: () => void;
Expand Down

0 comments on commit 27d933b

Please sign in to comment.