diff --git a/src/pages/view/FilterBar/FilterBadge.js b/src/pages/view/FilterBar/FilterBadge.js
index c8cfe003d..015c89553 100644
--- a/src/pages/view/FilterBar/FilterBadge.js
+++ b/src/pages/view/FilterBar/FilterBadge.js
@@ -15,13 +15,25 @@ const getFilterValuesText = (values) =>
? values[0].name
: i18n.t('{{count}} selected', { count: values.length })
-const FilterBadge = ({ filter, openFilterModal, onRemove }) => {
- const { isConnected } = useDhis2ConnectionStatus()
- const { width } = useWindowDimensions()
- const notAllowed = !isConnected || width <= 480
- const tooltipContent = !isConnected
- ? i18n.t('Cannot edit filters while offline')
- : i18n.t('Cannot edit filters on a small screen')
+const EditFilterButton = ({ tooltipContent, filter, openFilterModal }) => {
+ const buttonText = `${filter.name}: ${getFilterValuesText(filter.values)}`
+
+ if (!tooltipContent) {
+ return (
+
+ )
+ }
return (
{
closeDelay={100}
className={classes.tooltip}
>
- {({ onFocus, onBlur, onMouseOver, onMouseOut, ref }) => (
- notAllowed && onFocus()}
- onBlur={() => notAllowed && onBlur()}
- onMouseOver={() => notAllowed && onMouseOver()}
- onMouseOut={() => notAllowed && onMouseOut()}
- ref={ref}
+ {(props) => (
+
+ {buttonText}
+
)}
)
}
+EditFilterButton.propTypes = {
+ filter: PropTypes.object,
+ openFilterModal: PropTypes.func,
+ tooltipContent: PropTypes.string,
+}
+
+const FilterBadge = ({ filter, openFilterModal, onRemove }) => {
+ const { isConnected } = useDhis2ConnectionStatus()
+ const { width } = useWindowDimensions()
+ const isEditDisabled = !isConnected || width <= 480
+ const tooltipContent = !isConnected
+ ? i18n.t('Cannot edit filters while offline')
+ : i18n.t('Cannot edit filters on a small screen')
+
+ return (
+
+
+ {isConnected && (
+ onRemove(filter.id)}
+ >
+
+
+ )}
+
+ )
+}
FilterBadge.propTypes = {
filter: PropTypes.object.isRequired,
diff --git a/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js b/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js
index fd0d32110..b183c4643 100644
--- a/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js
+++ b/src/pages/view/FilterBar/__tests__/FilterBadge.spec.js
@@ -79,14 +79,16 @@ test('Has enabled buttons when online', () => {
expect(getByTestId('filter-badge-clear-button')).toBeEnabled()
})
-test('Has disabled buttons when offline', () => {
- useDhis2ConnectionStatus.mockImplementation(() => ({ isConnected: false }))
+test('Shows only a disabled edit-filter button when offline', () => {
+ useDhis2ConnectionStatus.mockImplementationOnce(() => ({
+ isConnected: false,
+ }))
const filter = {
id: 'ponies',
name: 'Ponies',
values: [{ name: 'Twilight Sparkle' }],
}
- const { getByTestId } = render(
+ const { getByTestId, queryByTestId } = render(
{
)
expect(getByTestId('filter-badge-button')).toBeDisabled()
- expect(getByTestId('filter-badge-clear-button')).toBeDisabled()
+ expect(queryByTestId('filter-badge-clear-button')).not.toBeInTheDocument()
})
-test('Has disabled buttons when on small screen', () => {
- useWindowDimensions.mockImplementation(() => ({ width: 440, height: 780 }))
+test('Shows a disabled edit-filter button and enabled clear-filter when on small screen', () => {
+ useWindowDimensions.mockImplementationOnce(() => ({
+ width: 440,
+ height: 780,
+ }))
const filter = {
id: 'ponies',
name: 'Ponies',
@@ -118,5 +123,5 @@ test('Has disabled buttons when on small screen', () => {
)
expect(getByTestId('filter-badge-button')).toBeDisabled()
- expect(getByTestId('filter-badge-clear-button')).toBeDisabled()
+ expect(getByTestId('filter-badge-clear-button')).toBeEnabled()
})
diff --git a/src/pages/view/FilterBar/styles/FilterBadge.module.css b/src/pages/view/FilterBar/styles/FilterBadge.module.css
index 3da675679..3b853fc7b 100644
--- a/src/pages/view/FilterBar/styles/FilterBadge.module.css
+++ b/src/pages/view/FilterBar/styles/FilterBadge.module.css
@@ -28,6 +28,12 @@
border-end-start-radius: 4px;
}
+.filterButton:only-child {
+ padding-inline-end: 6px;
+ border-start-end-radius: 4px;
+ border-end-end-radius: 4px;
+}
+
.removeButton {
padding-inline: 4px 6px;
border-start-end-radius: 4px;