| @@ -6,7 +6,8 @@ | |||
| "@emotion/react": "^11.5.0", | |||
| "@emotion/styled": "^11.3.0", | |||
| "@mui/icons-material": "^5.0.5", | |||
| "@mui/material": "^5.0.6", | |||
| "@mui/lab": "^5.0.0-alpha.120", | |||
| "@mui/material": "^5.11.10", | |||
| "@mui/x-data-grid": "^5.0.1", | |||
| "@mui/x-date-pickers": "^5.0.10", | |||
| "@reduxjs/toolkit": "^1.5.1", | |||
| @@ -0,0 +1,41 @@ | |||
| import React, { useEffect } from "react"; | |||
| import TreeView from "@mui/lab/TreeView"; | |||
| import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; | |||
| import ChevronRightIcon from "@mui/icons-material/ChevronRight"; | |||
| import TreeItem from "@mui/lab/TreeItem"; | |||
| import { useDispatch, useSelector } from "react-redux"; | |||
| import { setAllCategoriesReq } from "../../store/actions/categories/categoriesAction"; | |||
| import { selectAllCategories } from "../../store/selectors/categoriesSelector"; | |||
| function TreeViewFiles() { | |||
| const dispatch = useDispatch(); | |||
| const categories = useSelector(selectAllCategories); | |||
| useEffect(() => { | |||
| dispatch(setAllCategoriesReq()); | |||
| }, []); | |||
| const renderTree = (nodes) => ( | |||
| <TreeItem key={nodes.id} nodeId={nodes.id} label={nodes.name}> | |||
| {Array.isArray(nodes.treeViewCategories) | |||
| ? nodes.treeViewCategories.map((node) => renderTree(node)) | |||
| : null} | |||
| </TreeItem> | |||
| ); | |||
| return categories.length < 0 ? ( | |||
| <p>Loading....</p> | |||
| ) : ( | |||
| categories.map((category) => ( | |||
| <TreeView | |||
| key={category.id} | |||
| aria-label="rich object" | |||
| defaultCollapseIcon={<ExpandMoreIcon />} | |||
| defaultExpandIcon={<ChevronRightIcon />} | |||
| sx={{ flexGrow: 1, overflowY: "auto" }} | |||
| > | |||
| {renderTree(category)} | |||
| </TreeView> | |||
| )) | |||
| ); | |||
| } | |||
| export default TreeViewFiles; | |||
| @@ -1,10 +1,10 @@ | |||
| import React, { useState } from "react"; | |||
| import { Checkbox, FormControlLabel, MenuItem, Select } from "@mui/material"; | |||
| import { Checkbox, FormControlLabel } from "@mui/material"; | |||
| import { useTranslation } from "react-i18next"; | |||
| import uploadIcon from "../../assets/images/upload.png"; | |||
| import IconButton from "../../components/IconButton/IconButton"; | |||
| import { useSelector, useDispatch } from "react-redux"; | |||
| import { selectCategories } from "../../store/selectors/categoriesSelector"; | |||
| // import { selectCategories } from "../../store/selectors/categoriesSelector"; | |||
| import { useEffect } from "react"; | |||
| import { setCategoriesReq } from "../../store/actions/categories/categoriesAction"; | |||
| import { | |||
| @@ -16,6 +16,7 @@ import { selectTags } from "../../store/selectors/tagsSelector"; | |||
| import { uploadFileReq } from "../../store/actions/uploadFile/uploadFileActions"; | |||
| import { FILES_VIEW_PAGE } from "../../constants/pages"; | |||
| import PropTypes from "prop-types"; | |||
| import TreeViewFiles from "../../components/Files/TreeViewFiles"; | |||
| const AddFile = ({ history }) => { | |||
| const [dropzoneActive, setDropzoneActive] = useState(false); | |||
| @@ -23,9 +24,9 @@ const AddFile = ({ history }) => { | |||
| const [title, setTitle] = useState(""); | |||
| const [showMessage, setShowMessage] = useState(false); | |||
| const dispatch = useDispatch(); | |||
| const categories = useSelector(selectCategories); | |||
| // const categories = useSelector(selectCategories); | |||
| const tags = useSelector(selectTags); | |||
| const [selectedCategory, setSelectedCategory] = useState(null); | |||
| // const [selectedCategory, setSelectedCategory] = useState(null); | |||
| const { t } = useTranslation(); | |||
| useEffect(() => { | |||
| @@ -60,9 +61,9 @@ const AddFile = ({ history }) => { | |||
| setPdfFile(selectedFile); | |||
| }; | |||
| const selectCategoryHandler = (e) => { | |||
| setSelectedCategory(e.target.value); | |||
| }; | |||
| // const selectCategoryHandler = (e) => { | |||
| // setSelectedCategory(e.target.value); | |||
| // }; | |||
| const onChangeTagsCheckbox = (id) => { | |||
| dispatch(changeTagIsCheckedValue(id)); | |||
| @@ -83,7 +84,7 @@ const AddFile = ({ history }) => { | |||
| dispatch( | |||
| uploadFileReq({ | |||
| title, | |||
| categoryId: selectedCategory === null ? -1 : selectedCategory, | |||
| categoryId: -1, | |||
| tagsIds, | |||
| fileToUpload: pdfFile, | |||
| onSuccessUploadFile, | |||
| @@ -101,7 +102,7 @@ const AddFile = ({ history }) => { | |||
| <h1>Categories</h1> | |||
| </div> | |||
| <div className="files-page-card-content"> | |||
| <Select | |||
| {/* <Select | |||
| labelId="files-page-card-content-select" | |||
| id="files-page-card-content-selectt" | |||
| sx={{ width: "100%", borderColor: "#e4e4e4 !important" }} | |||
| @@ -118,7 +119,8 @@ const AddFile = ({ history }) => { | |||
| {category.name} | |||
| </MenuItem> | |||
| ))} | |||
| </Select> | |||
| </Select> */} | |||
| <TreeViewFiles/> | |||
| </div> | |||
| </div> | |||
| @@ -73,6 +73,7 @@ export default { | |||
| rootCategories: base + "/categories/root-categories", | |||
| isCategoriesChecked: base + "/categories/granted-categories", | |||
| grantCategory: base + "/users/grant-category", | |||
| allCategories:base + "/categories/all-categories" | |||
| }, | |||
| tags: { | |||
| allTags: base + "/tags/names", | |||
| @@ -1,14 +1,17 @@ | |||
| import { getRequest, postRequest } from "."; | |||
| import apiEndpoints from "./apiEndpoints"; | |||
| export const getRootCategories = () => | |||
| export const getRootCategories = () => | |||
| getRequest(apiEndpoints.categories.rootCategories); | |||
| export const getRootCategories2 = (parentCategoryId) => | |||
| export const getRootCategories2 = (parentCategoryId) => | |||
| getRequest(apiEndpoints.categories.rootCategories + "/" + parentCategoryId); | |||
| export const getIsCategoriesChecked = (userId) => | |||
| getRequest(apiEndpoints.categories.isCategoriesChecked + "?userId=" + userId); | |||
| export const grantCategoryRequest = (payload) => | |||
| postRequest(apiEndpoints.categories.grantCategory, payload); | |||
| export const getAllCategories = () => | |||
| getRequest(apiEndpoints.categories.allCategories); | |||
| @@ -9,6 +9,9 @@ import { | |||
| GRANT_CATEGORY_REQ, | |||
| GRANT_CATEGORY_ERR, | |||
| GRANT_CATEGORY_SUCCESS, | |||
| FETCH_ALL_CATEGORIES_ERR, | |||
| FETCH_ALL_CATEGORIES_REQ, | |||
| FETCH_ALL_CATEGORIES_SUCCESS, | |||
| } from "./categoriesActionConstants"; | |||
| export const setCategoriesReq = (payload) => ({ | |||
| @@ -60,3 +63,17 @@ export const setGrantCategories = (payload) => ({ | |||
| type: GRANT_CATEGORY_SUCCESS, | |||
| payload, | |||
| }); | |||
| export const setAllCategoriesReq = () => ({ | |||
| type: FETCH_ALL_CATEGORIES_REQ, | |||
| }); | |||
| export const setAllCategoriesError = (payload) => ({ | |||
| type: FETCH_ALL_CATEGORIES_ERR, | |||
| payload, | |||
| }); | |||
| export const setAllCategories = (payload) => ({ | |||
| type: FETCH_ALL_CATEGORIES_SUCCESS, | |||
| payload, | |||
| }); | |||
| @@ -7,6 +7,7 @@ import { | |||
| const FETCH_ROOT_CATEGORIES_SCOPE = "FETCH_ROOT_CATEGORIES"; | |||
| const FETCH_IS_CATEGORIES_CHECKED_SCOPE = "FETCH_IS_CATEGORIES_CHECKED"; | |||
| const GRANT_CATEGORY_SCOPE = "GRANT_CATEGORY"; | |||
| const FETCH_ALL_CATEGORIES_SCOPE = "FETCH_ALL_CATEGORIES"; | |||
| export const FETCH_ROOT_CATEGORIES_REQ = createFetchType( | |||
| FETCH_ROOT_CATEGORIES_SCOPE | |||
| @@ -31,4 +32,8 @@ export const GRANT_CATEGORY_REQ = createFetchType(GRANT_CATEGORY_SCOPE); | |||
| export const GRANT_CATEGORY_ERR = createErrorType(GRANT_CATEGORY_SCOPE); | |||
| export const GRANT_CATEGORY_SUCCESS = createSuccessType(GRANT_CATEGORY_SCOPE); | |||
| export const FETCH_ALL_CATEGORIES_REQ = createFetchType(FETCH_ALL_CATEGORIES_SCOPE); | |||
| export const FETCH_ALL_CATEGORIES_ERR = createErrorType(FETCH_ALL_CATEGORIES_SCOPE); | |||
| export const FETCH_ALL_CATEGORIES_SUCCESS = createSuccessType(FETCH_ALL_CATEGORIES_SCOPE); | |||
| export const CHANGE_IC_CHECKED_CATEGORY = "CHANGE_IC_CHECKED_CATEGORY"; | |||
| @@ -6,12 +6,15 @@ import { | |||
| FETCH_IS_CATEGORIES_CHECKED_SUCCESS, | |||
| GRANT_CATEGORY_ERR, | |||
| GRANT_CATEGORY_SUCCESS, | |||
| FETCH_ALL_CATEGORIES_ERR, | |||
| FETCH_ALL_CATEGORIES_SUCCESS | |||
| } from "../../actions/categories/categoriesActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| const initialState = { | |||
| categories: [], | |||
| childParentRelations: [], | |||
| allCategories:[], | |||
| isCategoriesChecked: [], | |||
| changedCategories: [], | |||
| errorMessage: "", | |||
| @@ -26,6 +29,8 @@ export default createReducer( | |||
| [CHANGE_IC_CHECKED_CATEGORY]: setIsCheckedCategory, | |||
| [GRANT_CATEGORY_SUCCESS]: setStateGrantCategories, | |||
| [GRANT_CATEGORY_ERR]: setGrantCategoriesErrorMessage, | |||
| [FETCH_ALL_CATEGORIES_SUCCESS]: setStateAllCategories, | |||
| [FETCH_ALL_CATEGORIES_ERR]: setStateAllCategoriesErrorMessage, | |||
| }, | |||
| initialState | |||
| ); | |||
| @@ -106,3 +111,17 @@ function setGrantCategoriesErrorMessage(state, action) { | |||
| errorMessage: action.payload, | |||
| }; | |||
| } | |||
| function setStateAllCategories(state, action) { | |||
| return { | |||
| ...state, | |||
| allCategories:action.payload | |||
| }; | |||
| } | |||
| function setStateAllCategoriesErrorMessage(state, action) { | |||
| return { | |||
| ...state, | |||
| errorMessage: action.payload, | |||
| }; | |||
| } | |||
| @@ -6,6 +6,8 @@ import { | |||
| setIsCategoriesCheckedError, | |||
| setGrantCategories, | |||
| setGrantCategoriesError, | |||
| setAllCategories, | |||
| setAllCategoriesError | |||
| } from "../actions/categories/categoriesAction"; | |||
| import { authScopeStringGetHelper } from "../../util/helpers/authScopeHelpers"; | |||
| import { JWT_TOKEN } from "../../constants/localStorage"; | |||
| @@ -15,12 +17,14 @@ import { | |||
| FETCH_ROOT_CATEGORIES_REQ, | |||
| FETCH_IS_CATEGORIES_CHECKED_REQ, | |||
| GRANT_CATEGORY_REQ, | |||
| FETCH_ALL_CATEGORIES_REQ | |||
| } from "../actions/categories/categoriesActionConstants"; | |||
| import { | |||
| getRootCategories, | |||
| getIsCategoriesChecked, | |||
| grantCategoryRequest, | |||
| getRootCategories2, | |||
| getAllCategories | |||
| } from "../../request/categoriesRequest"; | |||
| export function* getRootCategoriesSaga({ payload }) { | |||
| @@ -64,10 +68,23 @@ export function* grantCategoriesCheckedSaga({ payload }) { | |||
| } | |||
| } | |||
| export function* getAllCategoriesSaga() { | |||
| try { | |||
| const JwtToken = yield call(authScopeStringGetHelper, JWT_TOKEN); | |||
| yield call(addHeaderToken, JwtToken); | |||
| const result = yield call(getAllCategories); | |||
| yield put(setAllCategories(result.data)); | |||
| } catch (error) { | |||
| const errorMessage = yield call(rejectErrorCodeHelper, error); | |||
| yield put(setAllCategoriesError(errorMessage)); | |||
| } | |||
| } | |||
| export default function* categoriesSaga() { | |||
| yield all([ | |||
| takeLatest(FETCH_ROOT_CATEGORIES_REQ, getRootCategoriesSaga), | |||
| takeLatest(FETCH_IS_CATEGORIES_CHECKED_REQ, getIsCategoriesCheckedSaga), | |||
| takeLatest(GRANT_CATEGORY_REQ, grantCategoriesCheckedSaga), | |||
| takeLatest(FETCH_ALL_CATEGORIES_REQ, getAllCategoriesSaga), | |||
| ]); | |||
| } | |||
| @@ -31,3 +31,13 @@ export const selectChangedCategories = createSelector( | |||
| categoriesSelector, | |||
| (state) => state.changedCategories | |||
| ); | |||
| export const selectAllCategories = createSelector( | |||
| categoriesSelector, | |||
| (state) => state.allCategories | |||
| ); | |||
| export const selectAllCategoriesError = createSelector( | |||
| categoriesSelector, | |||
| (state) => state.errorMessage | |||
| ); | |||