-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: DHIS2-4881, DHIS2-4882, DHIS2-4883, DHIS2-3455 This PR implements dashboard filters for ou, pe and dynamic dimensions. It uses shared analytics components. Details: * Rename action/reducer to itemFilters Dashboards app can have multiple filters/overrides * Fetch list of dimensions at app start and store it The list does not really change, so we can store it once at app startup and use it in the different components, also shared ones * Add reducer/actions for editItemFilters This is used to differentiate between applied filters (itemFilters in the store) and selected items in the filters, which is needed by the dimension dialogs when the user interacts with the "Add filter" feature in the app. The Confirm button is what copies the selected filters in itemFilters and that is what is used by the app for applying the filters to the items. * Import reducer/actions from the renamed itemFilters * Add new components for dashboard item filtering * Use new FilterSelector component * Fix tests for itemFilters reducer * Ensure proper URL encoding Pass the query string object as argument to Api.get() instead of including it directly in the URL * Add edit and remove reducer/action for dashboard filters * Add component for showing active filter badges * Enable FilterBar under TitleBar * Fix filters handling. Remove debug logs * Apply dashboard filters to AO before passing it to plugins * Add reselect dependency * Add new strings for translations * Move FilterBadge in its own file. Add click handler. When clicking on the badge, it should open the corresponding filter dialog for editing the filter. * Apply only the filter currently edited The Confirm button in FilterDialog only applies the currently edited filter instead of copying all the edited filters. The Cancel button only closes the dialog, but keeps the filter selection in the store (in editItemFilters). * Pass dashboard filters in AO to plugins * Style buttons in view mode and filter dialogs * Pass around displayNameProperty used in the org unit tree * Open the filter dialog when clicking on the filter badge This allows to edit the filter * Fix tests * Remove unused code and dependency * Remove d2-ui dependency * Enable rich text editor/parser on Text dashboard items * Make sure the full AO is preserved when switching between edit/view * Add @dhis2/d2-ui-analytics dependency for shared components * Update translations pot file * Update yarn.lock after updates in data-visualizer-plugin * Fix failing tests * test fixes * upgrade d2-ui-analytics * test fix
- Loading branch information
1 parent
a288aba
commit bc22817
Showing
42 changed files
with
1,350 additions
and
551 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { | ||
SET_ACTIVE_MODAL_DIMENSION, | ||
CLEAR_ACTIVE_MODAL_DIMENSION, | ||
} from '../reducers/activeModalDimension'; | ||
|
||
export const acSetActiveModalDimension = value => ({ | ||
type: SET_ACTIVE_MODAL_DIMENSION, | ||
value, | ||
}); | ||
|
||
export const acClearActiveModalDimension = () => ({ | ||
type: CLEAR_ACTIVE_MODAL_DIMENSION, | ||
}); |
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,29 @@ | ||
import keyBy from 'lodash/keyBy'; | ||
import sortBy from 'lodash/sortBy'; | ||
import { SET_DIMENSIONS } from '../reducers/dimensions'; | ||
import { apiFetchDimensions } from '@dhis2/d2-ui-analytics'; | ||
import { sGetSettingsDisplayNameProperty } from '../reducers/settings'; | ||
|
||
export const acSetDimensions = dimensions => ({ | ||
type: SET_DIMENSIONS, | ||
value: keyBy(sortBy(dimensions, [d => d.name.toLowerCase()]), 'id'), | ||
}); | ||
|
||
export const tSetDimensions = d2 => async (dispatch, getState) => { | ||
const onSuccess = dimensions => { | ||
dispatch(acSetDimensions(dimensions)); | ||
}; | ||
|
||
const onError = error => { | ||
console.log('Error (apiFetchDimensions): ', error); | ||
return error; | ||
}; | ||
|
||
try { | ||
const displayNameProp = sGetSettingsDisplayNameProperty(getState()); | ||
const dimensions = await apiFetchDimensions(d2, displayNameProp); | ||
return onSuccess(dimensions); | ||
} catch (err) { | ||
return onError(err); | ||
} | ||
}; |
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 { | ||
REMOVE_EDIT_ITEM_FILTER, | ||
SET_EDIT_ITEM_FILTERS, | ||
} from '../reducers/editItemFilters'; | ||
|
||
// actions | ||
|
||
export const acRemoveEditItemFilter = id => ({ | ||
type: REMOVE_EDIT_ITEM_FILTER, | ||
id, | ||
}); | ||
|
||
export const acSetEditItemFilters = filters => ({ | ||
type: SET_EDIT_ITEM_FILTERS, | ||
filters, | ||
}); |
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,24 @@ | ||
import { | ||
ADD_ITEM_FILTER, | ||
REMOVE_ITEM_FILTER, | ||
SET_ITEM_FILTERS, | ||
} from '../reducers/itemFilters'; | ||
|
||
export const FILTER_ORG_UNIT = 'ou'; | ||
|
||
// actions | ||
|
||
export const acAddItemFilter = filter => ({ | ||
type: ADD_ITEM_FILTER, | ||
filter, | ||
}); | ||
|
||
export const acRemoveItemFilter = id => ({ | ||
type: REMOVE_ITEM_FILTER, | ||
id, | ||
}); | ||
|
||
export const acSetItemFilters = filters => ({ | ||
type: SET_ITEM_FILTERS, | ||
filters, | ||
}); |
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 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import i18n from '@dhis2/d2-i18n'; | ||
|
||
import { colors } from '../../modules/colors'; | ||
|
||
const styles = { | ||
badgeContainer: { | ||
margin: '0 4px', | ||
padding: '0 16px', | ||
borderRadius: '4px', | ||
color: colors.white, | ||
backgroundColor: '#212934', | ||
height: 36, | ||
display: 'flex', | ||
alignItems: 'center', | ||
}, | ||
badge: { | ||
fontSize: '13px', | ||
cursor: 'pointer', | ||
}, | ||
badgeRemove: { | ||
fontSize: '12px', | ||
textDecoration: 'underline', | ||
marginLeft: '24px', | ||
cursor: 'pointer', | ||
}, | ||
}; | ||
|
||
class FilterBadge extends Component { | ||
onClick = id => () => this.props.onClick(id); | ||
onRemove = id => () => this.props.onRemove(id); | ||
|
||
render() { | ||
const { data } = this.props; | ||
|
||
return ( | ||
<div style={styles.badgeContainer}> | ||
<span style={styles.badge} onClick={this.onClick(data.id)}> | ||
{`${data.name}: ${ | ||
data.values.length > 1 | ||
? i18n.t('{{count}} selected', { | ||
count: data.values.length, | ||
}) | ||
: data.values[0].name | ||
}`} | ||
</span> | ||
<span | ||
style={styles.badgeRemove} | ||
onClick={this.onRemove(data.id)} | ||
> | ||
{i18n.t('Remove')} | ||
</span> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
FilterBadge.propTypes = { | ||
data: PropTypes.object.isRequired, | ||
onClick: PropTypes.func.isRequired, | ||
onRemove: PropTypes.func.isRequired, | ||
}; | ||
|
||
FilterBadge.defaultProps = { | ||
onClick: Function.prototype, | ||
onRemove: Function.prototype, | ||
}; | ||
|
||
export default FilterBadge; |
Oops, something went wrong.