From 2ded36807ea7b7a57a7271fbb287900f22d853ae Mon Sep 17 00:00:00 2001 From: Kalyan540 Date: Mon, 16 Dec 2024 00:23:57 +0530 Subject: [PATCH] Fix: UserManagement Page --- .../src/pages/Dashboard/index.tsx | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/superset-frontend/src/pages/Dashboard/index.tsx b/superset-frontend/src/pages/Dashboard/index.tsx index 7671158c9..294e56950 100644 --- a/superset-frontend/src/pages/Dashboard/index.tsx +++ b/superset-frontend/src/pages/Dashboard/index.tsx @@ -25,46 +25,46 @@ import './index.css'; import { DashboardPage } from 'src/dashboard/containers/DashboardPage'; import AlertList from '../AlertReportList'; import { addDangerToast, addSuccessToast } from 'src/components/MessageToasts/actions'; -import { SupersetClient } from '@superset-ui/core'; const DashboardRoute: FC = () => { const { idOrSlug } = useParams<{ idOrSlug: string }>(); const [activeButton, setActiveButton] = useState('Dashboard'); + const [htmlContent, setHtmlContent] = useState(null); const currentUser = useSelector( state => state.user, ); const handleButtonClick = (buttonName: string) => { setActiveButton(buttonName); + + // Fetch user list when the active button is "User Management" + if (buttonName === 'User Management') { + fetchUserList(); + } }; - useEffect(() => { - async function fetchUserList() { - try { - // Get the base URL (e.g., http://localhost:9000) - const baseUrl = window.location.origin; + const fetchUserList = async () => { + try { + // Get the base URL (e.g., http://localhost:9000) + const baseUrl = window.location.origin; - // Build the full URL for the API request - const apiUrl = `${baseUrl}/users/list`; + // Build the full URL for the API request + const apiUrl = `${baseUrl}/users/list/`; - // Fetch user list from the API - const response = await fetch(apiUrl); - - // Log the response object - console.log(response); + // Fetch user list from the API + const response = await fetch(apiUrl); - // If the response is OK, print the response body as text - if (response.ok) { - const responseText = await response.text(); // Parse the response as text - console.log('Response Text:', responseText); - } else { - console.error('Error fetching data:', response.status); - } - } catch (error) { - console.error('Error fetching user list:', error); + // If the response is OK, save the response body as text + if (response.ok) { + const responseText = await response.text(); // Parse the response as text + setHtmlContent(responseText); // Save the HTML content in state + } else { + console.error('Error fetching data:', response.status); + setHtmlContent('

Error loading user management page

'); // Show an error message } + } catch (error) { + console.error('Error fetching user list:', error); + setHtmlContent('

Error loading user management page

'); // Show an error message } - - fetchUserList(); - }, []); + }; //return ; return ( @@ -122,8 +122,11 @@ const DashboardRoute: FC = () => { ) : activeButton === 'User Management' ? ( - // -

This page is in development.

+
Loading User Management Page...', + }} + /> ): activeButton === 'Alerts' ? (