-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update core edit link * Add location resource to table data * Abstract edit link * Code cleanup * Cleanup and add tests * Add edit text as render prop * Add back to param on service point links
- Loading branch information
Showing
8 changed files
with
140 additions
and
24 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
37 changes: 37 additions & 0 deletions
37
packages/fhir-location-management/src/components/EditLink/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,37 @@ | ||
import React from 'react'; | ||
import { Link, useLocation } from 'react-router-dom'; | ||
import { | ||
BACK_SEARCH_PARAM, | ||
URL_LOCATION_UNIT_EDIT, | ||
URL_SERVICE_POINT_ADD_EDIT, | ||
} from '../../constants'; | ||
import { ILocation } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/ILocation'; | ||
|
||
interface EditLinkProps { | ||
location: ILocation; | ||
editLinkText: string; | ||
} | ||
|
||
const EditLink: React.FC<EditLinkProps> = (props) => { | ||
const { location, editLinkText } = props; | ||
const { id, physicalType } = location; | ||
const isBuilding = physicalType?.coding?.[0].code === 'bu'; | ||
const currentLocation = useLocation(); | ||
|
||
const backToParam = new URLSearchParams({ [BACK_SEARCH_PARAM]: currentLocation.pathname }); | ||
|
||
return ( | ||
<Link | ||
to={ | ||
isBuilding | ||
? `${URL_SERVICE_POINT_ADD_EDIT}/${id}?${backToParam}` | ||
: `${URL_LOCATION_UNIT_EDIT}/${id}?${backToParam}` | ||
} | ||
className="m-0 p-1" | ||
> | ||
{editLinkText} | ||
</Link> | ||
); | ||
}; | ||
|
||
export { EditLink }; |
36 changes: 36 additions & 0 deletions
36
packages/fhir-location-management/src/components/EditLink/tests/fixtures.ts
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,36 @@ | ||
import { ILocation } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/ILocation'; | ||
|
||
export const Location: ILocation = { | ||
resourceType: 'Location', | ||
id: '303', | ||
meta: { | ||
versionId: '4', | ||
lastUpdated: '2021-10-14T13:12:22.740+00:00', | ||
source: '#13bbc7f09daa1751', | ||
}, | ||
identifier: [{ use: 'official', value: '93bc9c3d-6321-41b0-9b93-1275d7114e22' }], | ||
status: 'active', | ||
name: 'Yosemite', | ||
description: 'The Sub location', | ||
partOf: { reference: 'Location/2252', display: 'Root FHIR Location' }, | ||
type: [ | ||
{ | ||
coding: [ | ||
{ | ||
system: 'http://terminology.hl7.org/CodeSystem/location-physical-type', | ||
code: 'bu', | ||
display: 'Building', | ||
}, | ||
], | ||
}, | ||
], | ||
physicalType: { | ||
coding: [ | ||
{ | ||
system: 'http://terminology.hl7.org/CodeSystem/location-physical-type', | ||
code: 'bu', | ||
display: 'Building', | ||
}, | ||
], | ||
}, | ||
}; |
56 changes: 56 additions & 0 deletions
56
packages/fhir-location-management/src/components/EditLink/tests/index.test.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,56 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { URL_LOCATION_UNIT_EDIT, URL_SERVICE_POINT_ADD_EDIT } from '../../../constants'; | ||
import { EditLink } from '..'; | ||
import { Location } from './fixtures'; | ||
|
||
describe('EditLink', () => { | ||
it('renders the correct link for building locations', () => { | ||
const { getByText } = render( | ||
<Router> | ||
<EditLink location={Location} editLinkText="Edit" /> | ||
</Router> | ||
); | ||
|
||
const link = getByText('Edit'); | ||
expect(link).toBeInTheDocument(); | ||
expect(link).toHaveAttribute('href', `${URL_SERVICE_POINT_ADD_EDIT}/303?back_to=%2F`); | ||
}); | ||
|
||
it('renders the correct link for non-building locations', () => { | ||
const location = { | ||
...Location, | ||
physicalType: { | ||
coding: [ | ||
{ | ||
system: 'http://terminology.hl7.org/CodeSystem/location-physical-type', | ||
code: 'jdn', | ||
display: 'Jurisdiction', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const { getByText } = render( | ||
<Router> | ||
<EditLink location={location} editLinkText="Edit" /> | ||
</Router> | ||
); | ||
|
||
const link = getByText('Edit'); | ||
expect(link).toBeInTheDocument(); | ||
expect(link).toHaveAttribute('href', `${URL_LOCATION_UNIT_EDIT}/303?back_to=%2F`); | ||
}); | ||
it('renders custom link text from props', () => { | ||
const { getByText } = render( | ||
<Router> | ||
<EditLink location={Location} editLinkText="Edit details" /> | ||
</Router> | ||
); | ||
|
||
const link = getByText('Edit details'); | ||
expect(link).toBeInTheDocument(); | ||
}); | ||
}); |
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