diff --git a/src/components/GenerateReportPicker.js b/src/components/GenerateReportPicker.js index d0ebadd..368bb21 100644 --- a/src/components/GenerateReportPicker.js +++ b/src/components/GenerateReportPicker.js @@ -34,7 +34,7 @@ const GenerateReportPicker = (props) => { {children ? ( children({ toggle }) ) : ( - )} diff --git a/src/components/ReportSearcher.js b/src/components/ReportSearcher.js index 63cf417..2c58a54 100644 --- a/src/components/ReportSearcher.js +++ b/src/components/ReportSearcher.js @@ -1,37 +1,97 @@ import React, { useCallback, useState } from "react"; import { useSelector } from "react-redux"; + +import { Box, Button, Tooltip } from "@material-ui/core"; +import HelpOutlineIcon from "@material-ui/icons/HelpOutline"; +import EditIcon from '@material-ui/icons/Edit'; + +import { + Searcher, + useTranslations, + useModulesManager, +} from "@openimis/fe-core"; +import { RIGHT_REPORT_EDIT } from "../constants"; import { useReportsQuery } from "../hooks"; -import { Searcher, useTranslations, useModulesManager } from "@openimis/fe-core"; import GenerateReportPicker from "./GenerateReportPicker"; -import { Box, Button } from "@material-ui/core"; import ReportDefinitionEditorDialog from "./ReportDefinitionEditorDialog"; -import { RIGHT_REPORT_EDIT, RIGHT_REPORT_ADD } from "../constants" - -const HEADERS = ["tools.report.description", "tools.report.module", "tools.report.name", ""]; const ReportSearcher = () => { const modulesManager = useModulesManager(); - const { formatMessageWithValues, formatMessage } = useTranslations("tools", modulesManager); + const { formatMessageWithValues, formatMessage } = useTranslations( + "tools", + modulesManager + ); const { data, isLoading, error, refetch } = useReportsQuery(); const [editedReport, setEditedReport] = useState(); const rights = useSelector((state) => state.core?.user?.i_user?.rights ?? []); + + const reportsByModule = data?.reports?.reduce((acc, report) => { + const { module } = report; + if (!acc[module]) { + acc[module] = []; + } + acc[module].push(report); + return acc; + }, {}); + + const formattedReports = + reportsByModule && + Object.keys(reportsByModule).reduce((acc, moduleName) => { + acc.push({ isCategory: true, category: moduleName }); + reportsByModule[moduleName].forEach((report) => acc.push(report)); + return acc; + }, []); + + const formatCategory = (report) => { + const capitalizedCategory = + report.category.charAt(0).toUpperCase() + report.category.slice(1); + return ( + + + + {formatMessageWithValues("ReportSearcher.moduleName", { + module: capitalizedCategory, + })} + + + + ); + }; + + const formatReport = (report) => ( + + {report.description} + + ); + + const formatActions = (report) => + !report.category && ( + +
+ + + +
+ {rights.includes(RIGHT_REPORT_EDIT) && ( + + )} + +
+ ); + const itemFormatters = useCallback( () => [ - (r) => r.description, - (r) => r.module, - (r) => r.name, - (r) => ( - - { - rights.includes(RIGHT_REPORT_ADD) && - rights.includes(RIGHT_REPORT_EDIT) && - - } - - - ), + (report) => + report.isCategory ? formatCategory(report) : formatReport(report), + formatActions, ], [] ); @@ -40,17 +100,24 @@ const ReportSearcher = () => { <> refetch()} itemsPageInfo={{ totalCount: data?.reports?.length ?? 0 }} - headers={() => HEADERS} + headers={() => []} itemFormatters={itemFormatters} withPagination={false} /> - {editedReport && setEditedReport(null)} />} + {editedReport && ( + setEditedReport(null)} + /> + )} ); }; diff --git a/src/components/ToolsMainMenu.js b/src/components/ToolsMainMenu.js index 9fedd64..62f4fec 100644 --- a/src/components/ToolsMainMenu.js +++ b/src/components/ToolsMainMenu.js @@ -6,6 +6,11 @@ import { connect } from "react-redux"; import { RIGHT_REGISTERS, RIGHT_REPORTS, RIGHT_EXTRACTS } from "../constants"; class ToolsMainMenu extends Component { + constructor(props) { + super(props); + this.isWorker = props.modulesManager.getConf("fe-core", "isWorker", false); + } + enablers = (enablers) => { var e; for (e of enablers) { @@ -15,8 +20,10 @@ class ToolsMainMenu extends Component { }; render() { - const { rights } = this.props; + if (this.isWorker) return null; + let entries = []; + if (this.enablers(RIGHT_REGISTERS)) { entries.push({ text: formatMessage(this.props.intl, "tools", "menu.registers"), @@ -24,19 +31,6 @@ class ToolsMainMenu extends Component { route: "/tools/registers", }); } - // Renewals are preformed automatically now. - // if (rights.includes(RIGHT_POLICY_RENEWALS)) { - // entries.push( - // { text: formatMessage(this.props.intl, "tools", "menu.renewals"), icon: , route: "/tools/policyRenewals" } - // ) - // } - // SMS sending feature is normally done automatically now. We'll consider adding this back if necessary - // if (rights.includes(RIGHT_FEEDBACK_PROMPT)) { - // entries.push( - // { text: formatMessage(this.props.intl, "tools", "menu.feedbacks"), icon: , route: "/tools/feedbackPrompts" }, - // ) - // } - // Extracts page is not implemented in the modular version yet. As it's not used as of now. if (this.enablers(RIGHT_EXTRACTS)) { entries.push( { text: formatMessage(this.props.intl, "tools", "menu.extracts"), icon: , route: "/tools/extracts" }, @@ -49,17 +43,9 @@ class ToolsMainMenu extends Component { route: "/tools/reports", }); } - // if (this.enablers(RIGHT_UTILITIES)) { - // entries.push( - // { text: formatMessage(this.props.intl, "tools", "menu.utilities"), icon: , route: "/tools/utilities" }, - // ) - // } - // if (rights.includes(RIGHT_EMAILSETTING)) { - // entries.push( - // { text: formatMessage(this.props.intl, "tools", "menu.emails"), icon: , route: "/tools/emailSettings" } - // ) - // } + if (!entries.length) return null; + return (