Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

85 рядки
2.5 KiB

  1. // material-ui
  2. import {
  3. DataGrid,
  4. } from "@mui/x-data-grid";
  5. import {useEffect, useState} from "react";
  6. import axios from "axios";
  7. import {apiPath} from "../../auth/utils";
  8. //import LoadingComponent from "../extra-pages/LoadingComponent";
  9. import * as React from "react";
  10. import {GET_AUTH_LIST} from "../../utils/ApiPathConst";
  11. import Loadable from 'components/Loadable';
  12. import { lazy } from 'react';
  13. const LoadingComponent = Loadable(lazy(() => import('../extra-pages/LoadingComponent')));
  14. // ==============================|| EVENT TABLE ||============================== //
  15. export default function UserAuthTable({setSelectedRow, userAuth}) {
  16. const [authData, setAuthData] = useState([]);
  17. const [onReady, setOnReady] = useState(false);
  18. const [currentSelectedRow, setCurrentSelectedRow] = useState(userAuth);
  19. useEffect(() => {
  20. axios.get(`${apiPath}${GET_AUTH_LIST}`)
  21. .then((response) => {
  22. if (response.status === 200) {
  23. setAuthData(response.data.records);
  24. }
  25. })
  26. .catch(error => {
  27. console.log(error);
  28. return false;
  29. });
  30. }, []);
  31. useEffect(() => {
  32. //if state data are ready and assign to different field
  33. if (authData.length > 0) {
  34. setOnReady(true);
  35. }
  36. }, [authData]);
  37. const columns = [
  38. {
  39. id: 'module',
  40. field: 'module',
  41. headerName: 'Module',
  42. flex: 1,
  43. },
  44. {
  45. id: 'authority',
  46. field: 'name',
  47. headerName: 'Authority',
  48. flex: 2,
  49. },
  50. ];
  51. return (
  52. !onReady ?
  53. <LoadingComponent/>
  54. :
  55. <div style={{height: '100%', width: '100%'}}>
  56. <DataGrid
  57. rows={authData}
  58. columns={columns}
  59. editMode="row"
  60. initialState={{
  61. pagination: {
  62. paginationModel: {page: 0, pageSize: 20},
  63. },
  64. }}
  65. pageSizeOptions={[10, 20, 30]}
  66. checkboxSelection
  67. rowSelectionModel={currentSelectedRow}
  68. onRowSelectionModelChange={(ids) => {
  69. console.log(ids);
  70. setSelectedRow(ids);
  71. setCurrentSelectedRow(ids);
  72. }}
  73. autoHeight
  74. />
  75. </div>
  76. );
  77. }