UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

82 lines (79 loc) 3.38 kB
import { LoadType, ReportType } from '../types/UserReports.js'; import localsHelper, { getRouteLocals } from './localsHelper.js'; import { setNestedPath } from './urlHelper.js'; const getTypeTagColor = (type) => { let tagColourClass = ''; switch (type) { case ReportType.DASHBOARD: tagColourClass = 'govuk-tag--purple'; break; case ReportType.UNAVAILABLE: tagColourClass = 'govuk-tag--grey'; break; default: tagColourClass = ''; break; } return tagColourClass; }; const createListItemProductMin = (reportName, type, schedule) => { const tagColor = getTypeTagColor(type); const reportType = toSentenceCase(type); let heading = `<div> <p class="govuk-body-s govuk-!-margin-bottom-2"><strong>${reportName}</strong></p> <strong class="govuk-tag ${tagColor} dpr-request-status-tag--small">${reportType}</strong>`; if (schedule) { heading += `<br><br><strong class="govuk-tag govuk-tag--magenta dpr-request-status-tag--small">Scheduled: ${schedule}</strong></div>`; } else { heading += `<div>`; } return heading; }; const createListActions = (href, type, loadType, bookmarkHtml, subsHtml, authorised = true, missing = false) => { if (!authorised) { return `<strong class="govuk-tag govuk-tag--red dpr-request-status-tag dpr-request-status-tag--small dpr-unauthorised-report" aria-label="You are unauthorised to view this report">Unauthorised</strong>`; } let actions = `<ul class="dpr-my-reports__actions-list">`; let actionText; if (missing) { actionText = `Request report`; actions = `${actions} <li><a class='govuk-link dpr-user-list-action govuk-link--no-visited-state' href="${href}">${actionText}</a></li>`; } else { actionText = `Request ${type}`; if (loadType && loadType === LoadType.SYNC) { actionText = `Load ${type}`; } actions = `${actions} <li><a class='govuk-link dpr-user-list-action govuk-link--no-visited-state dpr-live-report dpr-type__${type}' href="${href}">${actionText}</a></li>`; } if (bookmarkHtml) { actions = `${actions} <li>${bookmarkHtml}</li>`; } if (subsHtml) { actions = `${actions} <li>${subsHtml}</li>`; } return `${actions} </ul>`; }; const toSentenceCase = (text) => { return text.charAt(0).toUpperCase() + text.substring(1).toLowerCase(); }; const setInitialHref = (loadType, type, reportId, id, res, isMissing = false) => { const { pathSuffix, dpdPathFromQuery } = localsHelper.getValues(res); const { nestedBaseUrl } = getRouteLocals(res); const rootPath = setNestedPath(`/dpr`, nestedBaseUrl); let href = ''; if (isMissing) { href = `${rootPath}/request-missing-report/${reportId}/${id}/form`; } else { const dpdPathQueryParam = dpdPathFromQuery ? pathSuffix : ''; href = `${rootPath}/request-report/${type}/${reportId}/${id}/filters${dpdPathQueryParam}`; if (loadType && loadType === LoadType.SYNC) { href = `${rootPath}/view-report/sync/${type}/${reportId}/${id}/load-report${dpdPathQueryParam}`; } } return href; }; export { createListActions, createListItemProductMin, setInitialHref, toSentenceCase }; //# sourceMappingURL=reportListsHelper.js.map