This is an automated email from the ASF dual-hosted git repository.

dineshkumar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new 7931a6141 RANGER-4305: Two api requests for single export request 
triggered from Reports page
7931a6141 is described below

commit 7931a61419aee35baee9abe06a9a326259ea7190
Author: Mugdha Varadkar <mug...@apache.org>
AuthorDate: Tue Jun 27 01:17:58 2023 +0530

    RANGER-4305: Two api requests for single export request triggered from 
Reports page
    
    Signed-off-by: Dineshkumar Yadav <dineshkumar.ya...@outlook.com>
---
 .../main/webapp/react-webapp/src/styles/style.css  |  3 ++-
 .../src/views/Reports/UserAccessLayout.jsx         | 28 ++++++++++++++++++----
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/security-admin/src/main/webapp/react-webapp/src/styles/style.css 
b/security-admin/src/main/webapp/react-webapp/src/styles/style.css
index 77c0ab7ac..c330299ff 100644
--- a/security-admin/src/main/webapp/react-webapp/src/styles/style.css
+++ b/security-admin/src/main/webapp/react-webapp/src/styles/style.css
@@ -2528,7 +2528,8 @@ li.list-group-item:hover {
   text-decoration: none;
   background-color: #e9ecef;
 }
-.manage-service .dropdown-toggle:focus {
+.manage-service .dropdown-toggle:focus,
+.manage-export .dropdown-toggle:focus {
   color: #0b7fad;
   background-color: #fff;
   border-color: #0062cc;
diff --git 
a/security-admin/src/main/webapp/react-webapp/src/views/Reports/UserAccessLayout.jsx
 
b/security-admin/src/main/webapp/react-webapp/src/views/Reports/UserAccessLayout.jsx
index 05c68b762..fc4d50093 100644
--- 
a/security-admin/src/main/webapp/react-webapp/src/views/Reports/UserAccessLayout.jsx
+++ 
b/security-admin/src/main/webapp/react-webapp/src/views/Reports/UserAccessLayout.jsx
@@ -51,6 +51,7 @@ import { useQuery } from "../../components/CommonComponents";
 import SearchPolicyTable from "./SearchPolicyTable";
 import { getBaseUrl, isKeyAdmin, isKMSAuditor } from "../../utils/XAUtils";
 import CustomBreadcrumb from "../CustomBreadcrumb";
+import moment from "moment-timezone";
 
 function UserAccessLayout(props) {
   const isKMSRole = isKeyAdmin() || isKMSAuditor();
@@ -451,12 +452,14 @@ function UserAccessLayout(props) {
     try {
       exportResp = await fetchApi({
         url: exportApiUrl,
-        params: searchParamsObj
+        params: searchParamsObj,
+        responseType: "blob"
       });
 
       if (exportResp.status === 200) {
         downloadFile({
-          apiUrl: exportApiUrl
+          exportType: exportType,
+          apiResponse: exportResp.data
         });
       } else {
         toast.warning("No policies found to export");
@@ -466,11 +469,27 @@ function UserAccessLayout(props) {
     }
   };
 
-  const downloadFile = ({ apiUrl }) => {
-    let downloadUrl = getBaseUrl() + "service" + apiUrl + location.search;
+  const downloadFile = ({ exportType, apiResponse }) => {
+    let fileExtension;
 
+    if (exportType === "downloadExcel") {
+      fileExtension = ".xls";
+    } else if (exportType === "csv") {
+      fileExtension = ".csv";
+    } else {
+      fileExtension = ".json";
+    }
+
+    const fileName =
+      "Ranger_Policies_" +
+      moment(moment()).format("YYYYMMDD_hhmmss") +
+      fileExtension;
+
+    const downloadUrl = window.URL.createObjectURL(apiResponse);
     const link = document.createElement("a");
+
     link.href = downloadUrl;
+    link.download = fileName;
 
     const clickEvt = new MouseEvent("click", {
       view: window,
@@ -738,6 +757,7 @@ function UserAccessLayout(props) {
               key="left"
               drop="left"
               size="sm"
+              className="manage-export"
               title="Export all below policies"
             >
               <Dropdown.Toggle

Reply via email to