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

MF-647: Introduce PatientTable component #20

Merged
merged 5 commits into from
Jul 19, 2021
Merged
Changes from 1 commit
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
Next Next commit
MF-647: Add Patient Table component
  • Loading branch information
samuelmale committed Jul 19, 2021
commit cb4253a5847e8c4b5b896d19dc25da5fa20aafca
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import DataTable, {
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableHeader,
TableRow,
} from 'carbon-components-react/lib/components/DataTable';
import React from 'react';

const PatientTable: React.FC<{ patients: Array<Object>; columns: Array<PatientTableColumn> }> = ({
patients,
columns,
}) => {
const rows = patients.map((patient) => {
const row = {};
columns.forEach((column) => {
row['id'] = patient['id'] || patient['uuid'];
row[column.key] = column.getValue ? column.getValue(patient) : patient[column.key];
});
return row;
});
return (
<TableContainer>
<DataTable rows={rows as any} headers={columns as any} isSortable={true} size="normal" useZebraStyles={true}>
{({ rows, headers, getHeaderProps, getTableProps }) => (
<Table {...getTableProps()}>
<TableHead>
<TableRow>
{headers.map((header) => (
<TableHeader
{...getHeaderProps({
header,
isSortable: header.isSortable,
})}>
{header.header?.content ?? header.header}
</TableHeader>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => (
<TableRow key={row.id}>
{row.cells.map((cell) => (
<TableCell key={cell.id}>{cell.value?.content ?? cell.value}</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
)}
</DataTable>
</TableContainer>
);
};

export interface PatientTableColumn {
key: string;
label: string;
getValue?: (patient) => any;
}

export default PatientTable;
12 changes: 10 additions & 2 deletions packages/esm-patient-list-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getAsyncLifecycle } from '@openmrs/esm-framework';
import { registerBreadcrumbs } from '@openmrs/esm-framework';
import { getAsyncLifecycle, registerBreadcrumbs } from '@openmrs/esm-framework';
import './offline/offlineData';
import './patientListData/api';

@@ -66,6 +65,15 @@ function setupOpenMRS() {
moduleName,
}),
},
{
id: 'patient-table',
load: getAsyncLifecycle(() => import('./PatientTable/patient-table.component'), {
featureName: 'patient-table',
moduleName,
}),
online: true,
offline: true,
},
],
};
}