Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MERGING release/24.04 into main #45

Merged
merged 11 commits into from
Jun 26, 2024
2 changes: 1 addition & 1 deletion src/components/GenerateReportPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const GenerateReportPicker = (props) => {
{children ? (
children({ toggle })
) : (
<Button onClick={toggle} variant="contained" size="small">
<Button onClick={toggle} size="small" variant="contained" color="primary">
{formatMessage("triggerBtn")}
</Button>
)}
Expand Down
117 changes: 92 additions & 25 deletions src/components/ReportSearcher.js
Original file line number Diff line number Diff line change
@@ -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 (
<Box display="flex" justifyContent="flex-start">
<strong>
<i>
{formatMessageWithValues("ReportSearcher.moduleName", {
module: capitalizedCategory,
})}
</i>
</strong>
</Box>
);
};

const formatReport = (report) => (
<Box display="flex" justifyContent="flex-start" marginLeft="18px">
{report.description}
</Box>
);

const formatActions = (report) =>
!report.category && (
<Box display="flex" justifyContent={"flex-end"} gridGap={12}>
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<Tooltip title={report.name}>
<HelpOutlineIcon fontSize="small" />
</Tooltip>
</div>
{rights.includes(RIGHT_REPORT_EDIT) && (
<Button onClick={() => setEditedReport(report)} size="small" startIcon={<EditIcon />}>
{formatMessage("ReportSearcher.editBtn")}
</Button>
)}
<GenerateReportPicker name={report.name} />
</Box>
);

const itemFormatters = useCallback(
() => [
(r) => r.description,
(r) => r.module,
(r) => r.name,
(r) => (
<Box display="flex" justifyContent={"flex-end"} gridGap={12}>
{
rights.includes(RIGHT_REPORT_ADD) &&
rights.includes(RIGHT_REPORT_EDIT) &&
<Button onClick={() => setEditedReport(r)} size="small">
{formatMessage("ReportSearcher.editBtn")}
</Button>
}
<GenerateReportPicker name={r.name} />
</Box>
),
(report) =>
report.isCategory ? formatCategory(report) : formatReport(report),
formatActions,
],
[]
);
Expand All @@ -40,17 +100,24 @@ const ReportSearcher = () => {
<>
<Searcher
module="report"
tableTitle={formatMessageWithValues("ReportSearcher.tableTitle", { count: data?.reports?.length })}
items={data?.reports ?? []}
tableTitle={formatMessageWithValues("ReportSearcher.tableTitle", {
count: data?.reports?.length,
})}
items={formattedReports ?? []}
fetchingItems={isLoading}
errorItems={error}
fetch={() => refetch()}
itemsPageInfo={{ totalCount: data?.reports?.length ?? 0 }}
headers={() => HEADERS}
headers={() => []}
itemFormatters={itemFormatters}
withPagination={false}
/>
{editedReport && <ReportDefinitionEditorDialog name={editedReport.name} onClose={() => setEditedReport(null)} />}
{editedReport && (
<ReportDefinitionEditorDialog
name={editedReport.name}
onClose={() => setEditedReport(null)}
/>
)}
</>
);
};
Expand Down
34 changes: 10 additions & 24 deletions src/components/ToolsMainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -15,28 +20,17 @@ 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"),
icon: <ImportExport />,
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: <Autorenew />, 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: <Feedback />, 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: <SaveAlt />, route: "/tools/extracts" },
Expand All @@ -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: <Build />, route: "/tools/utilities" },
// )
// }
// if (rights.includes(RIGHT_EMAILSETTING)) {
// entries.push(
// { text: formatMessage(this.props.intl, "tools", "menu.emails"), icon: <EmailOutlined />, route: "/tools/emailSettings" }
// )
// }

if (!entries.length) return null;

return (
<MainMenuContribution
{...this.props}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Uploader = ({
}
required
constants={acceptableFormats}
withNull
withNull={false}
/>
<Grid item>
<Button
Expand Down Expand Up @@ -105,7 +105,7 @@ const Uploader = ({
}
required
constants={strategies}
withNull
withNull={false}
/>
</Grid>
<Grid item>
Expand Down
14 changes: 7 additions & 7 deletions src/pages/RegistersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ const RegistersPage = () => {
}
required
constants={DIAGNOSES_STRATEGIES}
withNull
withNull={false}
/>
</Grid>
<Grid item>
Expand Down Expand Up @@ -492,7 +492,7 @@ const RegistersPage = () => {
}
required
constants={LOCATIONS_STRATEGIES}
withNull
withNull={false}
/>
</Grid>
<Grid item>
Expand Down Expand Up @@ -626,7 +626,7 @@ const RegistersPage = () => {
}
required
constants={HEALTH_FACILITIES_STRATEGIES}
withNull
withNull={false}
/>
</Grid>
<Grid item>
Expand Down Expand Up @@ -746,7 +746,7 @@ const RegistersPage = () => {
}
required
constants={EXPORT_TYPES}
withNull
withNull={false}
/>
<Grid item>
<Button
Expand Down Expand Up @@ -803,7 +803,7 @@ const RegistersPage = () => {
}
required
constants={MEDICAL_ITEMS_STRATEGIES}
withNull
withNull={false}
/>
</Grid>
<Grid item>
Expand Down Expand Up @@ -896,7 +896,7 @@ const RegistersPage = () => {
}
required
constants={EXPORT_TYPES}
withNull
withNull={false}
/>
<Grid item>
<Button
Expand Down Expand Up @@ -957,7 +957,7 @@ const RegistersPage = () => {
}
required
constants={MEDICAL_SERVICES_STRATEGIES}
withNull
withNull={false}
/>
</Grid>
<Grid item>
Expand Down
5 changes: 2 additions & 3 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
"tools.ReportForm.title": "Editing report {name}",
"tools.ReportForm.unknownReport": "Unknown report",
"tools.ReportSearcher.tableTitle": "Reports",
"tools.report.name": "Report Name",
"tools.report.module": "Module",
"tools.report.validityFrom": "Valid From",
"tools.report.description": "Description",
"tools.report.definition": "Definition",
Expand All @@ -109,5 +107,6 @@
"tools.RegistersPage.servicesBlockTitle": "Medical Services",
"tools.RegistersPage.insureesBlockTitle": "Insurees",
"tools.RegistersPage.insurees.uploadLabel": "Upload Insurees",
"tools.RegistersPage.insurees.downloadLabel": "Download Insurees"
"tools.RegistersPage.insurees.downloadLabel": "Download Insurees",
"tools.ReportSearcher.moduleName": "{module} Module"
}
Loading