This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(breadcrumb): use a single component for Breadcrumbs
fix #1770
- Loading branch information
Showing
23 changed files
with
156 additions
and
321 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,6 @@ | |
"lint-staged": { | ||
"**/*.{js,jsx,ts,tsx}": [ | ||
"npm run lint:fix", | ||
"npm run test:ci", | ||
"git add ." | ||
] | ||
} | ||
|
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
31 changes: 0 additions & 31 deletions
31
src/__tests__/components/breadcrumb/Appointmentbreadcrumb.test.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
src/__tests__/components/breadcrumb/DefaultBreadcrumb.test.tsx
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/__tests__/components/breadcrumb/PatientBreadcrumb.test.tsx
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
import React from 'react' | ||
import { useHistory } from 'react-router' | ||
import { useSelector } from 'react-redux' | ||
import { useTranslation } from 'react-i18next' | ||
import { | ||
Breadcrumb as HrBreadcrumb, | ||
BreadcrumbItem as HrBreadcrumbItem, | ||
} from '@hospitalrun/components' | ||
import { RootState } from '../store' | ||
|
||
const Breadcrumbs = () => { | ||
const history = useHistory() | ||
const { t } = useTranslation() | ||
const { breadcrumbs } = useSelector((state: RootState) => state.breadcrumbs) | ||
|
||
return ( | ||
<HrBreadcrumb> | ||
{breadcrumbs.map(({ i18nKey, text, location }, index) => { | ||
const isLast = index === breadcrumbs.length - 1 | ||
const onClick = !isLast ? () => history.push(location) : undefined | ||
|
||
return ( | ||
<HrBreadcrumbItem key={location} active={isLast} onClick={onClick}> | ||
{i18nKey ? t(i18nKey) : text} | ||
</HrBreadcrumbItem> | ||
) | ||
})} | ||
</HrBreadcrumb> | ||
) | ||
} | ||
|
||
export default Breadcrumbs |
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,30 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | ||
import Breadcrumb from 'model/Breadcrumb' | ||
|
||
interface BreadcrumbsState { | ||
breadcrumbs: Breadcrumb[] | ||
} | ||
|
||
const initialState: BreadcrumbsState = { | ||
breadcrumbs: [], | ||
} | ||
|
||
const breadcrumbsSlice = createSlice({ | ||
name: 'breadcrumbs', | ||
initialState, | ||
reducers: { | ||
setBreadcrumbs(state, { payload }: PayloadAction<Breadcrumb[]>) { | ||
state.breadcrumbs = payload | ||
}, | ||
addBreadcrumb(state, { payload }: PayloadAction<Breadcrumb>) { | ||
state.breadcrumbs = [...state.breadcrumbs, payload] | ||
}, | ||
removeBreadcrumb(state) { | ||
state.breadcrumbs = state.breadcrumbs.slice(0, -1) | ||
}, | ||
}, | ||
}) | ||
|
||
export const { setBreadcrumbs, addBreadcrumb, removeBreadcrumb } = breadcrumbsSlice.actions | ||
|
||
export default breadcrumbsSlice.reducer |
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,16 @@ | ||
import { useEffect } from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import Breadcrumb from 'model/Breadcrumb' | ||
import { addBreadcrumb, removeBreadcrumb } from './breadcrumbs-slice' | ||
|
||
export default function useAddBreadcrumb(breadcrumb: Breadcrumb): void { | ||
const dispatch = useDispatch() | ||
|
||
useEffect(() => { | ||
dispatch(addBreadcrumb(breadcrumb)) | ||
|
||
return () => { | ||
dispatch(removeBreadcrumb()) | ||
} | ||
}, [dispatch, breadcrumb]) | ||
} |
Oops, something went wrong.