Skip to content

Commit

Permalink
feat: print dashboard [DHIS2-7045] (#1015)
Browse files Browse the repository at this point in the history
To implement dashboard printing, two routes have been added: printlayout and printoipp (oipp = one item per page). Note that these routes are used when navigating to Print from View mode. But in Edit mode, the print preview does not change the route.

Some components have been broken out into separate ones (e.g. ItemGrid), to avoid adding even more conditional statements into an already complex component, and risk breaking stuff that works (normal View and Edit mode).

Some refactors were done to prevent code from getting even more complex due to the introduction of Print Mode.

* Dashboard component now handles all the potential error or not-ready states (test scenarios: no dashboards, invalid id, dashboards not yet loaded). This functionality was previously in ViewDashboard/EditDashboard
* Removed the editItemFilters redux prop, and replaced with useState in the FilterSelector component
* src/actions/index.js removed bc it was never used
* ItemHeader is moved to a directory and code split up
* Show/hide description is now an user setting that persists across dashboards
  • Loading branch information
jenniferarnesen authored Aug 25, 2020
1 parent 4f236c3 commit 20cb64f
Show file tree
Hide file tree
Showing 76 changed files with 2,545 additions and 840 deletions.
73 changes: 66 additions & 7 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2020-06-10T01:32:16.274Z\n"
"PO-Revision-Date: 2020-06-10T01:32:16.274Z\n"
"POT-Creation-Date: 2020-08-25T05:26:00.043Z\n"
"PO-Revision-Date: 2020-08-25T05:26:00.043Z\n"

msgid "Cancel"
msgstr ""
Expand All @@ -23,10 +23,10 @@ msgid ""
"this dashboard?"
msgstr ""

msgid "Exit without saving"
msgid "Exit Print preview"
msgstr ""

msgid "Go to dashboards"
msgid "Print preview"
msgstr ""

msgid "Save changes"
Expand All @@ -35,6 +35,12 @@ msgstr ""
msgid "Translate"
msgstr ""

msgid "Exit without saving"
msgstr ""

msgid "Go to dashboards"
msgstr ""

msgid "Search for a dashboard"
msgstr ""

Expand All @@ -44,13 +50,42 @@ msgstr ""
msgid "Show less"
msgstr ""

msgid "No dashboards found. Use the + button to create a new dashboard."
msgstr ""

msgid "Requested dashboard not found"
msgstr ""

msgid "No access"
msgstr ""

msgid "No dashboards found. Use the + button to create a new dashboard."
msgid "Exit print preview"
msgstr ""

msgid "Requested dashboard not found"
msgid "Print"
msgstr ""

msgid "The pages below are a preview of how the dashboard layout will be printed."
msgstr ""

msgid ""
"The pages below are a preview of how each dashboard item will be printed on "
"a separate page."
msgstr ""

msgid ""
"Use the default printer settings for best results and check that all "
"dashboard items have finished loading before printing. This text will not "
"be printed."
msgstr ""

msgid "dashboard layout"
msgstr ""

msgid "one item per page"
msgstr ""

msgid "Print Preview"
msgstr ""

msgid "{{count}} selected"
Expand All @@ -73,6 +108,9 @@ msgstr ""
msgid "Item type \"{{type}}\" not supported"
msgstr ""

msgid "Filters applied"
msgstr ""

msgid "Spacer"
msgstr ""

Expand Down Expand Up @@ -142,7 +180,16 @@ msgstr ""
msgid "Dashboard description"
msgstr ""

msgid "No description"
msgid "Hide description"
msgstr ""

msgid "Show description"
msgstr ""

msgid "Unstar dashboard"
msgstr ""

msgid "Star dashboard"
msgstr ""

msgid "Edit"
Expand All @@ -151,6 +198,18 @@ msgstr ""
msgid "Share"
msgstr ""

msgid "More"
msgstr ""

msgid "Dashboard layout"
msgstr ""

msgid "One item per page"
msgstr ""

msgid "No description"
msgstr ""

msgid "Visualizations"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"moment": "^2.27.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-grid-layout": "^0.18.3",
"react-grid-layout": "^1.0.0",
"react-redux": "^7.2.1",
"react-router-dom": "^5.2.0",
"redux": "^4.0.5",
Expand Down
3 changes: 2 additions & 1 deletion src/actions/dashboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
sGetDashboardById,
sGetDashboardsSortedByStarred,
} from '../reducers/dashboards'
import { NON_EXISTING_DASHBOARD_ID } from '../reducers/selected'
import { sGetUserUsername } from '../reducers/user'
import { tSetSelectedDashboardById, acSetSelectedId } from './selected'
import { acClearEditDashboard } from './editDashboard'
Expand Down Expand Up @@ -81,7 +82,7 @@ export const tSelectDashboard = id => async (dispatch, getState) => {
if (dashboardToSelect) {
dispatch(tSetSelectedDashboardById(dashboardToSelect.id))
} else {
dispatch(acSetSelectedId())
dispatch(acSetSelectedId(NON_EXISTING_DASHBOARD_ID))
}
} catch (err) {
return onError(err)
Expand Down
26 changes: 25 additions & 1 deletion src/actions/editDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import {
ADD_DASHBOARD_ITEM,
UPDATE_DASHBOARD_ITEM,
REMOVE_DASHBOARD_ITEM,
SET_PRINT_PREVIEW_VIEW,
CLEAR_PRINT_PREVIEW_VIEW,
} from '../reducers/editDashboard'
import { sGetEditDashboardRoot } from '../reducers/editDashboard'
import { updateDashboard, postDashboard } from '../api/editDashboard'
import { tSetSelectedDashboardById } from '../actions/selected'
import {
NEW_ITEM_SHAPE,
getGridItemProperties,
getPageBreakItemShape,
getPrintTitlePageItemShape,
} from '../components/ItemGrid/gridUtil'
import { itemTypeMap } from '../modules/itemTypes'
import { itemTypeMap, PAGEBREAK, PRINT_TITLE_PAGE } from '../modules/itemTypes'
import { convertUiItemsToBackend } from '../modules/uiBackendItemConverter'

const onError = error => {
Expand Down Expand Up @@ -48,6 +52,14 @@ export const acClearEditDashboard = () => ({
type: RECEIVED_NOT_EDITING,
})

export const acSetPrintPreviewView = () => ({
type: SET_PRINT_PREVIEW_VIEW,
})

export const acClearPrintPreviewView = () => ({
type: CLEAR_PRINT_PREVIEW_VIEW,
})

export const acSetDashboardTitle = value => ({
type: RECEIVED_TITLE,
value,
Expand All @@ -71,14 +83,26 @@ export const acAddDashboardItem = item => {
const id = generateUid()
const gridItemProperties = getGridItemProperties(id)

let shape
if (type === PAGEBREAK) {
const yPos = item.yPos || 0
shape = getPageBreakItemShape(yPos, item.isStatic)
} else if (type === PRINT_TITLE_PAGE) {
shape = getPrintTitlePageItemShape()
} else {
shape = NEW_ITEM_SHAPE
}

return {
type: ADD_DASHBOARD_ITEM,
value: {
id,
type,
position: item.position || null,
[itemPropName]: item.content,
...NEW_ITEM_SHAPE,
...gridItemProperties,
...shape,
},
}
}
Expand Down
21 changes: 0 additions & 21 deletions src/actions/editItemFilters.js

This file was deleted.

10 changes: 0 additions & 10 deletions src/actions/index.js

This file was deleted.

80 changes: 80 additions & 0 deletions src/actions/printDashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { generateUid } from 'd2/uid'

import {
SET_PRINT_DASHBOARD,
CLEAR_PRINT_DASHBOARD,
SET_PRINT_DASHBOARD_LAYOUT,
ADD_PRINT_DASHBOARD_ITEM,
REMOVE_PRINT_DASHBOARD_ITEM,
UPDATE_PRINT_DASHBOARD_ITEM,
} from '../reducers/printDashboard'
import {
NEW_ITEM_SHAPE,
getGridItemProperties,
getPageBreakItemShape,
getPrintTitlePageItemShape,
} from '../components/ItemGrid/gridUtil'
import { itemTypeMap, PAGEBREAK } from '../modules/itemTypes'

// actions

export const acSetPrintDashboard = (dashboard, items) => {
const val = {
...dashboard,
dashboardItems: items,
}

return {
type: SET_PRINT_DASHBOARD,
value: val,
}
}

export const acClearPrintDashboard = () => ({
type: CLEAR_PRINT_DASHBOARD,
})

export const acUpdatePrintDashboardLayout = value => ({
type: SET_PRINT_DASHBOARD_LAYOUT,
value,
})

export const acAddPrintDashboardItem = item => {
const type = item.type
delete item.type
const itemPropName = itemTypeMap[type].propName

const id = generateUid()
const gridItemProperties = getGridItemProperties(id)

let shape
if (type === PAGEBREAK) {
const yPos = item.yPos || 0
shape = getPageBreakItemShape(yPos, item.isStatic)
} else {
shape = getPrintTitlePageItemShape()
}

return {
type: ADD_PRINT_DASHBOARD_ITEM,
value: {
id,
type,
position: item.position || null,
[itemPropName]: item.content,
...NEW_ITEM_SHAPE,
...gridItemProperties,
...shape,
},
}
}

export const acRemovePrintDashboardItem = value => ({
type: REMOVE_PRINT_DASHBOARD_ITEM,
value,
})

export const acUpdatePrintDashboardItem = item => ({
type: UPDATE_PRINT_DASHBOARD_ITEM,
value: item,
})
Loading

0 comments on commit 20cb64f

Please sign in to comment.