Skip to content

Commit

Permalink
Merge pull request #1332 from rahul6603/search-index-management
Browse files Browse the repository at this point in the history
Add SearchIndexManagement component in the Admin page
  • Loading branch information
mozzy11 authored Dec 16, 2024
2 parents 64350e8 + 9116411 commit 9718e23
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 5 deletions.
8 changes: 8 additions & 0 deletions frontend/src/components/admin/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
User,
BatchJob,
Popup,
Search,
} from "@carbon/icons-react";
import PathRoute from "../utils/PathRoute";
import CalculatedValue from "./calculatedValue/CalculatedValueForm";
Expand Down Expand Up @@ -57,6 +58,7 @@ import ManageMethod from "./testManagement/ManageMethod.js";
import BatchTestReassignmentAndCancelation from "./BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js";
import TestNotificationConfigMenu from "./testNotificationConfigMenu/TestNotificationConfigMenu.js";
import TestNotificationConfigEdit from "./testNotificationConfigMenu/TestNotificationConfigEdit.js";
import SearchIndexManagement from "./searchIndexManagement/SearchIndexManagement";

function Admin() {
const intl = useIntl();
Expand Down Expand Up @@ -200,6 +202,9 @@ function Admin() {
<SideNavLink href="#NotifyUser" renderIcon={Bullhorn}>
<FormattedMessage id="Notify User" />
</SideNavLink>
<SideNavLink href="#SearchIndexManagement" renderIcon={Search}>
<FormattedMessage id="searchindexmanagement.label" />
</SideNavLink>
<SideNavLink
renderIcon={Catalog}
target="_blank"
Expand Down Expand Up @@ -343,6 +348,9 @@ function Admin() {
<PathRoute path="#PluginFile">
<PluginList />
</PathRoute>
<PathRoute path="#SearchIndexManagement">
<SearchIndexManagement />
</PathRoute>
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React, { useState, useContext } from "react";
import { Button, Loading, Grid, Column, Section, Heading } from "@carbon/react";
import { FormattedMessage, useIntl, injectIntl } from "react-intl";
import { getFromOpenElisServer } from "../../utils/Utils";
import PageBreadCrumb from "../../common/PageBreadCrumb";
import { NotificationContext } from "../../layout/Layout";
import {
AlertDialog,
NotificationKinds,
} from "../../common/CustomNotification";

function SearchIndexManagement() {
const [loading, setLoading] = useState(false);
const { notificationVisible, setNotificationVisible, addNotification } =
useContext(NotificationContext);
const intl = useIntl();
const rebuildIndex = async (res) => {
setNotificationVisible(true);
if (res) {
addNotification({
kind: NotificationKinds.success,
title: intl.formatMessage({ id: "notification.title" }),
message: intl.formatMessage({
id: "searchindexmanagement.reindex.success",
}),
});
} else {
addNotification({
kind: NotificationKinds.error,
title: intl.formatMessage({ id: "notification.title" }),
message: intl.formatMessage({
id: "searchindexmanagement.reindex.error",
}),
});
}
setLoading(false);
};
const handleReindexClick = async () => {
setLoading(true);
getFromOpenElisServer("/rest/reindex", rebuildIndex);
};

const breadcrumbs = [
{ label: "home.label", link: "/" },
{
label: "breadcrums.admin.managment",
link: "/MasterListsPage",
},
{
label: "searchindexmanagement.label",
link: "/MasterListsPage#SearchIndexManagement",
},
];

return (
<>
{notificationVisible === true ? <AlertDialog /> : ""}
{loading && <Loading />}
<div className="adminPageContent">
<PageBreadCrumb breadcrumbs={breadcrumbs} />
<Grid fullWidth={true}>
<Column lg={16} md={8} sm={4}>
<Section>
<Heading>
<FormattedMessage id="searchindexmanagement.label" />
</Heading>
</Section>
</Column>
</Grid>
<div className="orderLegendBody">
<Grid>
<Column lg={16} md={8} sm={4}>
<Section>
<Section>
<Heading>
<FormattedMessage id="searchindexmanagement.reindex" />
</Heading>
</Section>
</Section>
<br />
<Section>
<FormattedMessage id="searchindexmanagement.description" />
</Section>
<br />
<Button onClick={handleReindexClick} disabled={loading}>
<FormattedMessage id="searchindexmanagement.reindex" />
</Button>
</Column>
</Grid>
</div>
</div>
</>
);
}

export default injectIntl(SearchIndexManagement);
7 changes: 6 additions & 1 deletion frontend/src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1271,5 +1271,10 @@
"testnotification.testdefault.template": "Default Message for Test",
"testnotification.testdefault.editIcon": "Edit Test Notification",
"testnotification.bcc": "BCC",
"column.name.testId": "Test Id"
"column.name.testId": "Test Id",
"searchindexmanagement.label": "Search Index Management",
"searchindexmanagement.reindex.success": "Reindexing completed successfully",
"searchindexmanagement.reindex.error": "Reindexing failed",
"searchindexmanagement.description": "The search index updates automatically when data is added or modified. If you need to manually update the search index, click the Start Reindexing button. This may take some time.",
"searchindexmanagement.reindex": "Start Reindexing"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ public class MassIndexerRestController {
MassIndexerService massIndexerService;

@GetMapping("/reindex")
public ResponseEntity<String> reindex() {
public ResponseEntity<Boolean> reindex() {
try {
massIndexerService.reindex();
return ResponseEntity.ok("Reindexing completed successfully.");
return ResponseEntity.ok(true);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("Error occurred during reindexing: " + e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(false);
}
}
}

0 comments on commit 9718e23

Please sign in to comment.