@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
71 lines (70 loc) • 2.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const actionsTemplate_1 = require("./actionsTemplate");
const getActions = ({ refresh, print, share, copy, download }) => {
const actions = [];
if (refresh && refresh.url && refresh.executionId) {
actions.push(setRefreshAction(actionsTemplate_1.actionTemplates.refresh, refresh));
}
if (print) {
actions.push(setPrintAction(actionsTemplate_1.actionTemplates.printable, print));
}
if (share) {
actions.push(setShareAction(actionsTemplate_1.actionTemplates.sharable, share));
}
if (copy) {
actions.push(setCopyAction(actionsTemplate_1.actionTemplates.copy, copy));
}
if (download) {
actions.push(setDownloadAction(actionsTemplate_1.actionTemplates.downloadable, download));
}
return actions;
};
const setRefreshAction = (template, data) => {
const { url: href } = data;
return {
...template,
href,
};
};
const setShareAction = (template, data) => {
const { reportName, name, url } = data;
const href = `mailto:?subject=${reportName}-${name}&body=${encodeURIComponent(url)}`;
return {
...template,
href,
};
};
const setCopyAction = (template, data) => {
const { url: href } = data;
return {
...template,
href,
};
};
const setDownloadAction = (template, data) => {
const { canDownload, enabled } = data;
const { tooltipText, ariaLabelText } = template;
return {
...template,
tooltipText: canDownload ? tooltipText : 'Enable download',
disabled: !enabled,
attributes: {
...data,
},
ariaLabelText: !enabled ? `${ariaLabelText}, disabled` : ariaLabelText,
};
};
const setPrintAction = (template, data) => {
const { enabled } = data;
const { ariaLabelText } = template;
return {
...template,
disabled: !enabled,
href: '#',
ariaLabelText: !enabled ? `${ariaLabelText}, disabled` : ariaLabelText,
};
};
exports.default = {
getActions,
};