-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eusm commodity create Update (#1330)
* Update group-management dependencies * Extract general re-usable productForm * Define a way to dynamically provide vlaidationRules * Make it possible to configure hiddenfilds and validationRUles * Make the whole Group details section configurable * Move current commodity list implementation to DEfault * Add Eusm centric commodity list * Configurable view details section for group list view * Conditionally render list view wrt to project code * Update utils * Install jest-canvas-mock, mocks canvas for antd upload * Create a mock for window.URL.createObjectURL * Create Eusm edit * Fix lint issues * Update snapshot tests * Show error banner if list id is not configured * Replace fallback image with skeleton image * Link material number to the identifier dataindex * Add material number to view details section * Fix test regressions * Wrap commodity edit in rbaccheck * Refactor lexicalities on variable unitOfMeasure * Cleaning up the code * Wrap commodity edit in rbaccheck * Update mock envs to fix test regression * Update snapshot in commodity list view * Fix missing material number * Wait for binary Query to render form view * Fix binary payload generation and append to list * Disable caching on binary query * Update docstring for helper fun toArrayBuffer * Fix bug where attractive item did not have correct value
- Loading branch information
1 parent
2e7ee0f
commit 2f590a0
Showing
33 changed files
with
3,131 additions
and
2,987 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
packages/fhir-group-management/src/components/CommodityAddEdit/Default/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
return <Spin size="large" className="custom-spinner"></Spin>; | ||
} | ||
|
||
if (groupQuery.error && !groupQuery.data) { | ||
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> | ||
); | ||
}; |
18 changes: 18 additions & 0 deletions
18
...anagement/src/components/CommodityAddEdit/Default/tests/__snapshots__/index.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
/> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.