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

Eusm commodity create Update #1330

Merged
merged 37 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cdb282a
Update group-management dependencies
peterMuriuki Feb 8, 2024
70bee89
Extract general re-usable productForm
peterMuriuki Feb 8, 2024
2d39c98
Define a way to dynamically provide vlaidationRules
peterMuriuki Feb 8, 2024
033c21b
Make it possible to configure hiddenfilds and validationRUles
peterMuriuki Feb 8, 2024
3619bbc
Make the whole Group details section configurable
peterMuriuki Feb 9, 2024
5fb9b48
Move current commodity list implementation to DEfault
peterMuriuki Feb 12, 2024
dc2ab4b
Add Eusm centric commodity list
peterMuriuki Feb 12, 2024
fac1930
Configurable view details section for group list view
peterMuriuki Feb 12, 2024
a51569b
Conditionally render list view wrt to project code
peterMuriuki Feb 12, 2024
2384382
Update utils
peterMuriuki Feb 12, 2024
a9f6254
Merge branch '1328-eusm-commodity-rd' into 1328-eusm-commodity-cu-back
peterMuriuki Feb 12, 2024
4ec75cc
Install jest-canvas-mock, mocks canvas for antd upload
peterMuriuki Feb 15, 2024
e2069de
Create a mock for window.URL.createObjectURL
peterMuriuki Feb 15, 2024
b7b5c1c
Create Eusm edit
peterMuriuki Feb 15, 2024
5a7ed3c
Fix lint issues
peterMuriuki Feb 15, 2024
71f980c
Update snapshot tests
peterMuriuki Feb 15, 2024
d2406c6
Show error banner if list id is not configured
peterMuriuki Feb 16, 2024
ef7874e
Replace fallback image with skeleton image
peterMuriuki Feb 16, 2024
5cd5f79
Link material number to the identifier dataindex
peterMuriuki Feb 16, 2024
37afdff
Add material number to view details section
peterMuriuki Feb 16, 2024
4a736b2
Fix test regressions
peterMuriuki Feb 16, 2024
f16b747
Merge branch '1328-eusm-commodity-rd' into 1328-eusm-commodity-cu
peterMuriuki Feb 16, 2024
23834ca
Wrap commodity edit in rbaccheck
peterMuriuki Feb 16, 2024
9438ab0
Merge branch '1328-eusm-commodity-rd' into 1328-eusm-commodity-cu
peterMuriuki Feb 16, 2024
8478bb4
Refactor lexicalities on variable unitOfMeasure
peterMuriuki Feb 16, 2024
4cc749b
Cleaning up the code
peterMuriuki Feb 18, 2024
e9cdb34
Wrap commodity edit in rbaccheck
peterMuriuki Feb 16, 2024
340c1d0
Update mock envs to fix test regression
peterMuriuki Feb 19, 2024
450cab6
Update snapshot in commodity list view
peterMuriuki Feb 19, 2024
c1f61a9
Merge branch '1328-eusm-commodity-rd' into 1328-eusm-commodity-cu
peterMuriuki Feb 19, 2024
c594633
Fix missing material number
peterMuriuki Feb 19, 2024
0d4829b
Wait for binary Query to render form view
peterMuriuki Feb 19, 2024
f2d91d4
Fix binary payload generation and append to list
peterMuriuki Feb 19, 2024
cac7022
Disable caching on binary query
peterMuriuki Feb 19, 2024
48923fa
Update docstring for helper fun toArrayBuffer
peterMuriuki Feb 23, 2024
1a6bcf5
Fix bug where attractive item did not have correct value
peterMuriuki Feb 28, 2024
51455ae
Merge branch 'main' into 1328-eusm-commodity-cu
peterMuriuki Feb 28, 2024
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
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
transformIgnorePatterns: [
'node_modules/(?!(@helsenorge/toolkit|@helsenorge/core-utils|@helsenorge/designsystem-react)/)',
],
setupFiles: ['./setupTests'],
setupFiles: ['./setupTests', 'jest-canvas-mock'],
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
roots: ['packages/', 'app'],
moduleNameMapper: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"husky": "^8.0.0",
"i18next-parser": "^5.4.0",
"jest": "27.5.1",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom-sixteen": "^2.0.0",
"jest-fetch-mock": "^3.0.3",
"jest-haste-map": "^27.4.6",
Expand Down
4 changes: 3 additions & 1 deletion packages/fhir-group-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"author": "OpenSRP Engineering",
"license": "Apache-2.0",
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@opensrp/notifications": "^0.0.5",
"@opensrp/pkg-config": "^0.0.9",
"@opensrp/rbac": "workspace:^",
Expand All @@ -46,6 +47,7 @@
},
"peerDependencies": {
"@opensrp/i18n": "^0.0.1",
"react": "17.0.0"
"react": "17.0.0",
"react-query": "^3.15.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ import { useTranslation } from '../../../mls';
import { TFunction } from '@opensrp/i18n';
import { RbacCheck } from '@opensrp/rbac';

export type TableData = ReturnType<typeof parseGroup> & Record<string, unknown>;
export type DefaultTableData = ReturnType<typeof parseGroup> & Record<string, unknown>;

export type BaseListViewProps = Partial<Pick<ViewDetailsProps, 'keyValueMapperRenderProp'>> & {
export type ExtendableTableData = Pick<
ReturnType<typeof parseGroup>,
'id' | 'name' | 'active' | 'identifier' | 'lastUpdated'
>;

export type BaseListViewProps<TableData extends ExtendableTableData = DefaultTableData> = Partial<
Pick<ViewDetailsProps, 'keyValueMapperRenderProp'>
> & {
fhirBaseURL: string;
getColumns: (t: TFunction) => Column<TableData>[];
extraQueryFilters?: Record<string, string>;
createButtonLabel: string;
createButtonUrl?: string;
pageTitle: string;
generateTableData?: (groups: IGroup) => TableData;
viewDetailsRender?: (fhirBaseURL: string, resourceId?: string) => ReactNode;
};

Expand All @@ -37,7 +45,9 @@ export type BaseListViewProps = Partial<Pick<ViewDetailsProps, 'keyValueMapperRe
* @param props - GroupList component props
* @returns returns healthcare display
*/
export const BaseListView = (props: BaseListViewProps) => {
export function BaseListView<TableData extends ExtendableTableData = DefaultTableData>(
props: BaseListViewProps<TableData>
) {
const {
fhirBaseURL,
extraQueryFilters,
Expand All @@ -46,6 +56,7 @@ export const BaseListView = (props: BaseListViewProps) => {
createButtonUrl,
keyValueMapperRenderProp,
pageTitle,
generateTableData = parseGroup,
viewDetailsRender,
} = props;

Expand Down Expand Up @@ -73,9 +84,9 @@ export const BaseListView = (props: BaseListViewProps) => {

const tableData = (data?.records ?? []).map((org: IGroup, index: number) => {
return {
...parseGroup(org),
...generateTableData(org),
key: `${index}`,
};
} as TableData;
});

const columns = getColumns(t);
Expand Down Expand Up @@ -118,4 +129,4 @@ export const BaseListView = (props: BaseListViewProps) => {
</Row>
</div>
);
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React from 'react';
import { Helmet } from 'react-helmet';
import { CommodityForm } from '../../ProductForm';
import { useParams } from 'react-router';
import {
accountabilityPeriod,
appropriateUsage,
availability,
condition,
groupResourceType,
isAttractiveItem,
LIST_COMMODITY_URL,
materialNumber,
productImage,
} from '../../../constants';
import { Spin } from 'antd';
import { PageHeader } from '@opensrp/react-utils';
import { useQuery } from 'react-query';
import { FHIRServiceClass, BrokenPage } from '@opensrp/react-utils';
import { IGroup } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IGroup';
import {
generateGroupPayload,
getGroupFormFields,
postPutGroup,
updateListReferencesFactory,
validationRulesFactory,
} from './utils';
import { useTranslation } from '../../../mls';

export interface GroupAddEditProps {
fhirBaseURL: string;
listId: string;
}

export interface RouteParams {
id?: string;
}

export const CommodityAddEdit = (props: GroupAddEditProps) => {
const { fhirBaseURL: fhirBaseUrl, listId } = props;

const { id: resourceId } = useParams<RouteParams>();
const { t } = useTranslation();

const groupQuery = useQuery(
[groupResourceType, resourceId],
async () =>
new FHIRServiceClass<IGroup>(fhirBaseUrl, groupResourceType).read(resourceId as string),
{
enabled: !!resourceId,
}
);

if (!groupQuery.isIdle && groupQuery.isLoading) {
machariamuguku marked this conversation as resolved.
Show resolved Hide resolved
return <Spin size="large" className="custom-spinner"></Spin>;
}

if (groupQuery.error && !groupQuery.data) {
peterMuriuki marked this conversation as resolved.
Show resolved Hide resolved
return <BrokenPage errorMessage={(groupQuery.error as Error).message} />;
}

const initialValues = getGroupFormFields(groupQuery.data);

const pageTitle = groupQuery.data
? t('Edit Commodity | {{name}}', { name: groupQuery.data.name ?? '' })
: t('Create Commodity');

const postSuccess = updateListReferencesFactory(fhirBaseUrl, listId);

return (
<section className="content-section">
<Helmet>
<title>{pageTitle}</title>
</Helmet>
<PageHeader title={pageTitle} />
<div className="bg-white p-5">
<CommodityForm
hidden={[
materialNumber,
isAttractiveItem,
availability,
condition,
appropriateUsage,
accountabilityPeriod,
productImage,
]}
fhirBaseUrl={fhirBaseUrl}
initialValues={initialValues}
cancelUrl={LIST_COMMODITY_URL}
successUrl={LIST_COMMODITY_URL}
postSuccess={postSuccess}
validationRulesFactory={validationRulesFactory}
mutationEffect={async (initialValues, values) => {
const payload = generateGroupPayload(values, initialValues);
return postPutGroup(fhirBaseUrl, payload);
}}
/>
</div>
</section>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly: active radio button 1`] = `
<input
checked=""
class="ant-radio-input"
type="radio"
value="true"
/>
`;

exports[`renders correctly: disabled radio button 1`] = `
<input
class="ant-radio-input"
type="radio"
value="false"
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ export const newList = {
entry: [],
};

export const editedList = {
resourceType: 'List',
id: 'list-resource-id',
identifier: [{ use: 'official', value: 'list-resource-id' }],
status: 'current',
mode: 'working',
title: 'Supply Chain commodities',
code: {
coding: [{ system: 'http://ona.io', code: 'supply-chain', display: 'Supply Chain Commodity' }],
text: 'Supply Chain Commodity',
},
entry: [{ item: { reference: 'Group/123' } }],
};

export const createdCommodity1 = {
code: {
coding: [{ system: 'http://snomed.info/sct', code: '386452003', display: 'Supply management' }],
Expand All @@ -140,3 +154,29 @@ export const createdCommodity1 = {
},
],
};

export const editedCommodity1 = {
resourceType: 'Group',
id: '567ec5f2-db90-4fac-b578-6e07df3f48de',
identifier: [{ value: '43245245336', use: 'official' }],
active: true,
type: 'device',
actual: false,
code: {
coding: [{ system: 'http://snomed.info/sct', code: '386452003', display: 'Supply management' }],
},
name: 'Paracetamol 100mg TabletsDettol',
characteristic: [
{
code: {
coding: [
{ system: 'http://snomed.info/sct', code: '767524001', display: 'Unit of measure' },
],
},
valueCodeableConcept: {
coding: [{ system: 'http://snomed.info/sct', code: '767525000', display: 'Unit' }],
text: 'Bottles',
},
},
],
};
Loading
Loading