Skip to content

Commit

Permalink
feat: add tags on item header, used for filters in LL
Browse files Browse the repository at this point in the history
For LL items we don't apply filters.
Show a tag in the item header to indicate this to the user.
  • Loading branch information
edoardo committed Mar 2, 2023
1 parent 440f7c4 commit 5683b14
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/components/Item/ItemHeader/ItemHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import EditItemActions from './EditItemActions.js'
import PrintItemInfo from './PrintItemInfo.js'
import classes from './styles/ItemHeader.module.css'
import ViewItemActions from './ViewItemActions.js'
import ViewItemTags from './ViewItemTags.js'

const getItemActionsMap = (isShortened) => {
return {
Expand All @@ -16,12 +17,15 @@ const getItemActionsMap = (isShortened) => {
}

const ItemHeader = React.forwardRef(
({ dashboardMode, title, isShortened, ...rest }, ref) => {
({ dashboardMode, title, isShortened, tags, ...rest }, ref) => {
const Actions = getItemActionsMap(isShortened)[dashboardMode]
return (
<div className={classes.itemHeaderWrap} ref={ref}>
<p className={classes.itemTitle}>{title}</p>
{Actions ? <Actions {...rest} /> : null}
<div className={classes.itemHeaderRightWrap}>
{tags ? <ViewItemTags tags={tags} /> : null}
{Actions ? <Actions {...rest} /> : null}
</div>
</div>
)
}
Expand All @@ -32,6 +36,7 @@ ItemHeader.displayName = 'ItemHeader'
ItemHeader.propTypes = {
dashboardMode: PropTypes.string,
isShortened: PropTypes.bool,
tags: PropTypes.node,
title: PropTypes.string,
}

Expand Down
12 changes: 12 additions & 0 deletions src/components/Item/ItemHeader/ViewItemTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import PropTypes from 'prop-types'
import React from 'react'
import classes from './styles/ItemHeader.module.css'

const ViewItemTags = ({ tags }) =>
tags ? <div className={classes.itemTagsWrap}>{tags}</div> : null

ViewItemTags.propTypes = {
tags: PropTypes.node,
}

export default ViewItemTags
7 changes: 5 additions & 2 deletions src/components/Item/ItemHeader/styles/ItemHeader.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
align-self: center;
}

.itemActionsWrap {
margin-left: auto;
.itemHeaderRightWrap {
display: flex;
flex-shrink: 0;
align-items: center;
margin-left: auto;
}

.itemActionsWrap button {
margin-left: var(--spacers-dp8);
}
18 changes: 18 additions & 0 deletions src/components/Item/VisualizationItem/Item.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import i18n from '@dhis2/d2-i18n'
import { Tag, Tooltip, IconWarningFilled16 } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { connect } from 'react-redux'
Expand All @@ -19,6 +20,7 @@ import {
import {
getDataStatisticsName,
getItemTypeForVis,
EVENT_VISUALIZATION,
} from '../../../modules/itemTypes.js'
import { sGetIsEditing } from '../../../reducers/editDashboard.js'
import { sGetItemActiveType } from '../../../reducers/itemActiveTypes.js'
Expand Down Expand Up @@ -196,6 +198,21 @@ class Item extends Component {
/>
) : null

const tags =
Object.keys(itemFilters).length &&
isViewMode(dashboardMode) &&
activeType === EVENT_VISUALIZATION ? (
<Tooltip
content={i18n.t(
'Filters are not applied to line list dashboard items'
)}
>
<Tag negative icon={<IconWarningFilled16 />}>
{i18n.t('Filters not applied')}
</Tag>
</Tooltip>
) : null

return (
<>
<ItemHeader
Expand All @@ -205,6 +222,7 @@ class Item extends Component {
ref={this.headerRef}
dashboardMode={dashboardMode}
isShortened={item.shortened}
tags={tags}
/>
<FatalErrorBoundary
message={i18n.t(
Expand Down
1 change: 1 addition & 0 deletions src/components/styles/ItemGrid.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
.MAP .dashboard-item-content,
.EVENT_CHART .dashboard-item-content,
.EVENT_VISUALIZATION .dashboard-item-content {
position: relative;
overflow: hidden;
}

Expand Down

0 comments on commit 5683b14

Please sign in to comment.