Procházet zdrojové kódy

represent categories and files as tree vire

FE_dev
Dzenis Hadzifejzovic před 2 roky
rodič
revize
dc2f0945ee

+ 1511
- 243
package-lock.json
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 2
- 1
package.json Zobrazit soubor

"@emotion/react": "^11.5.0", "@emotion/react": "^11.5.0",
"@emotion/styled": "^11.3.0", "@emotion/styled": "^11.3.0",
"@mui/icons-material": "^5.0.5", "@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-data-grid": "^5.0.1",
"@mui/x-date-pickers": "^5.0.10", "@mui/x-date-pickers": "^5.0.10",
"@reduxjs/toolkit": "^1.5.1", "@reduxjs/toolkit": "^1.5.1",

+ 41
- 0
src/components/Files/TreeViewFiles.js Zobrazit soubor

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;

+ 12
- 10
src/pages/FilesPage/AddFile.js Zobrazit soubor

import React, { useState } from "react"; 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 { useTranslation } from "react-i18next";
import uploadIcon from "../../assets/images/upload.png"; import uploadIcon from "../../assets/images/upload.png";
import IconButton from "../../components/IconButton/IconButton"; import IconButton from "../../components/IconButton/IconButton";
import { useSelector, useDispatch } from "react-redux"; import { useSelector, useDispatch } from "react-redux";
import { selectCategories } from "../../store/selectors/categoriesSelector";
// import { selectCategories } from "../../store/selectors/categoriesSelector";
import { useEffect } from "react"; import { useEffect } from "react";
import { setCategoriesReq } from "../../store/actions/categories/categoriesAction"; import { setCategoriesReq } from "../../store/actions/categories/categoriesAction";
import { import {
import { uploadFileReq } from "../../store/actions/uploadFile/uploadFileActions"; import { uploadFileReq } from "../../store/actions/uploadFile/uploadFileActions";
import { FILES_VIEW_PAGE } from "../../constants/pages"; import { FILES_VIEW_PAGE } from "../../constants/pages";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import TreeViewFiles from "../../components/Files/TreeViewFiles";


const AddFile = ({ history }) => { const AddFile = ({ history }) => {
const [dropzoneActive, setDropzoneActive] = useState(false); const [dropzoneActive, setDropzoneActive] = useState(false);
const [title, setTitle] = useState(""); const [title, setTitle] = useState("");
const [showMessage, setShowMessage] = useState(false); const [showMessage, setShowMessage] = useState(false);
const dispatch = useDispatch(); const dispatch = useDispatch();
const categories = useSelector(selectCategories);
// const categories = useSelector(selectCategories);
const tags = useSelector(selectTags); const tags = useSelector(selectTags);
const [selectedCategory, setSelectedCategory] = useState(null);
// const [selectedCategory, setSelectedCategory] = useState(null);
const { t } = useTranslation(); const { t } = useTranslation();


useEffect(() => { useEffect(() => {
setPdfFile(selectedFile); setPdfFile(selectedFile);
}; };


const selectCategoryHandler = (e) => {
setSelectedCategory(e.target.value);
};
// const selectCategoryHandler = (e) => {
// setSelectedCategory(e.target.value);
// };


const onChangeTagsCheckbox = (id) => { const onChangeTagsCheckbox = (id) => {
dispatch(changeTagIsCheckedValue(id)); dispatch(changeTagIsCheckedValue(id));
dispatch( dispatch(
uploadFileReq({ uploadFileReq({
title, title,
categoryId: selectedCategory === null ? -1 : selectedCategory,
categoryId: -1,
tagsIds, tagsIds,
fileToUpload: pdfFile, fileToUpload: pdfFile,
onSuccessUploadFile, onSuccessUploadFile,
<h1>Categories</h1> <h1>Categories</h1>
</div> </div>
<div className="files-page-card-content"> <div className="files-page-card-content">
<Select
{/* <Select
labelId="files-page-card-content-select" labelId="files-page-card-content-select"
id="files-page-card-content-selectt" id="files-page-card-content-selectt"
sx={{ width: "100%", borderColor: "#e4e4e4 !important" }} sx={{ width: "100%", borderColor: "#e4e4e4 !important" }}
{category.name} {category.name}
</MenuItem> </MenuItem>
))} ))}
</Select>
</Select> */}
<TreeViewFiles/>
</div> </div>
</div> </div>



+ 1
- 0
src/request/apiEndpoints.js Zobrazit soubor

rootCategories: base + "/categories/root-categories", rootCategories: base + "/categories/root-categories",
isCategoriesChecked: base + "/categories/granted-categories", isCategoriesChecked: base + "/categories/granted-categories",
grantCategory: base + "/users/grant-category", grantCategory: base + "/users/grant-category",
allCategories:base + "/categories/all-categories"
}, },
tags: { tags: {
allTags: base + "/tags/names", allTags: base + "/tags/names",

+ 6
- 3
src/request/categoriesRequest.js Zobrazit soubor

import { getRequest, postRequest } from "."; import { getRequest, postRequest } from ".";
import apiEndpoints from "./apiEndpoints"; import apiEndpoints from "./apiEndpoints";


export const getRootCategories = () =>
export const getRootCategories = () =>
getRequest(apiEndpoints.categories.rootCategories); getRequest(apiEndpoints.categories.rootCategories);


export const getRootCategories2 = (parentCategoryId) =>
export const getRootCategories2 = (parentCategoryId) =>
getRequest(apiEndpoints.categories.rootCategories + "/" + parentCategoryId); getRequest(apiEndpoints.categories.rootCategories + "/" + parentCategoryId);
export const getIsCategoriesChecked = (userId) => export const getIsCategoriesChecked = (userId) =>
getRequest(apiEndpoints.categories.isCategoriesChecked + "?userId=" + userId); getRequest(apiEndpoints.categories.isCategoriesChecked + "?userId=" + userId);


export const grantCategoryRequest = (payload) => export const grantCategoryRequest = (payload) =>
postRequest(apiEndpoints.categories.grantCategory, payload); postRequest(apiEndpoints.categories.grantCategory, payload);

export const getAllCategories = () =>
getRequest(apiEndpoints.categories.allCategories);

+ 17
- 0
src/store/actions/categories/categoriesAction.js Zobrazit soubor

GRANT_CATEGORY_REQ, GRANT_CATEGORY_REQ,
GRANT_CATEGORY_ERR, GRANT_CATEGORY_ERR,
GRANT_CATEGORY_SUCCESS, GRANT_CATEGORY_SUCCESS,
FETCH_ALL_CATEGORIES_ERR,
FETCH_ALL_CATEGORIES_REQ,
FETCH_ALL_CATEGORIES_SUCCESS,
} from "./categoriesActionConstants"; } from "./categoriesActionConstants";


export const setCategoriesReq = (payload) => ({ export const setCategoriesReq = (payload) => ({
type: GRANT_CATEGORY_SUCCESS, type: GRANT_CATEGORY_SUCCESS,
payload, 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,
});

+ 5
- 0
src/store/actions/categories/categoriesActionConstants.js Zobrazit soubor

const FETCH_ROOT_CATEGORIES_SCOPE = "FETCH_ROOT_CATEGORIES"; const FETCH_ROOT_CATEGORIES_SCOPE = "FETCH_ROOT_CATEGORIES";
const FETCH_IS_CATEGORIES_CHECKED_SCOPE = "FETCH_IS_CATEGORIES_CHECKED"; const FETCH_IS_CATEGORIES_CHECKED_SCOPE = "FETCH_IS_CATEGORIES_CHECKED";
const GRANT_CATEGORY_SCOPE = "GRANT_CATEGORY"; const GRANT_CATEGORY_SCOPE = "GRANT_CATEGORY";
const FETCH_ALL_CATEGORIES_SCOPE = "FETCH_ALL_CATEGORIES";


export const FETCH_ROOT_CATEGORIES_REQ = createFetchType( export const FETCH_ROOT_CATEGORIES_REQ = createFetchType(
FETCH_ROOT_CATEGORIES_SCOPE FETCH_ROOT_CATEGORIES_SCOPE
export const GRANT_CATEGORY_ERR = createErrorType(GRANT_CATEGORY_SCOPE); export const GRANT_CATEGORY_ERR = createErrorType(GRANT_CATEGORY_SCOPE);
export const GRANT_CATEGORY_SUCCESS = createSuccessType(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"; export const CHANGE_IC_CHECKED_CATEGORY = "CHANGE_IC_CHECKED_CATEGORY";

+ 19
- 0
src/store/reducers/category/categoriesReducer.js Zobrazit soubor

FETCH_IS_CATEGORIES_CHECKED_SUCCESS, FETCH_IS_CATEGORIES_CHECKED_SUCCESS,
GRANT_CATEGORY_ERR, GRANT_CATEGORY_ERR,
GRANT_CATEGORY_SUCCESS, GRANT_CATEGORY_SUCCESS,
FETCH_ALL_CATEGORIES_ERR,
FETCH_ALL_CATEGORIES_SUCCESS
} from "../../actions/categories/categoriesActionConstants"; } from "../../actions/categories/categoriesActionConstants";
import createReducer from "../../utils/createReducer"; import createReducer from "../../utils/createReducer";


const initialState = { const initialState = {
categories: [], categories: [],
childParentRelations: [], childParentRelations: [],
allCategories:[],
isCategoriesChecked: [], isCategoriesChecked: [],
changedCategories: [], changedCategories: [],
errorMessage: "", errorMessage: "",
[CHANGE_IC_CHECKED_CATEGORY]: setIsCheckedCategory, [CHANGE_IC_CHECKED_CATEGORY]: setIsCheckedCategory,
[GRANT_CATEGORY_SUCCESS]: setStateGrantCategories, [GRANT_CATEGORY_SUCCESS]: setStateGrantCategories,
[GRANT_CATEGORY_ERR]: setGrantCategoriesErrorMessage, [GRANT_CATEGORY_ERR]: setGrantCategoriesErrorMessage,
[FETCH_ALL_CATEGORIES_SUCCESS]: setStateAllCategories,
[FETCH_ALL_CATEGORIES_ERR]: setStateAllCategoriesErrorMessage,
}, },
initialState initialState
); );
errorMessage: action.payload, errorMessage: action.payload,
}; };
} }

function setStateAllCategories(state, action) {
return {
...state,
allCategories:action.payload
};
}

function setStateAllCategoriesErrorMessage(state, action) {
return {
...state,
errorMessage: action.payload,
};
}

+ 17
- 0
src/store/saga/categoriesSaga.js Zobrazit soubor

setIsCategoriesCheckedError, setIsCategoriesCheckedError,
setGrantCategories, setGrantCategories,
setGrantCategoriesError, setGrantCategoriesError,
setAllCategories,
setAllCategoriesError
} from "../actions/categories/categoriesAction"; } from "../actions/categories/categoriesAction";
import { authScopeStringGetHelper } from "../../util/helpers/authScopeHelpers"; import { authScopeStringGetHelper } from "../../util/helpers/authScopeHelpers";
import { JWT_TOKEN } from "../../constants/localStorage"; import { JWT_TOKEN } from "../../constants/localStorage";
FETCH_ROOT_CATEGORIES_REQ, FETCH_ROOT_CATEGORIES_REQ,
FETCH_IS_CATEGORIES_CHECKED_REQ, FETCH_IS_CATEGORIES_CHECKED_REQ,
GRANT_CATEGORY_REQ, GRANT_CATEGORY_REQ,
FETCH_ALL_CATEGORIES_REQ
} from "../actions/categories/categoriesActionConstants"; } from "../actions/categories/categoriesActionConstants";
import { import {
getRootCategories, getRootCategories,
getIsCategoriesChecked, getIsCategoriesChecked,
grantCategoryRequest, grantCategoryRequest,
getRootCategories2, getRootCategories2,
getAllCategories
} from "../../request/categoriesRequest"; } from "../../request/categoriesRequest";


export function* getRootCategoriesSaga({ payload }) { export function* getRootCategoriesSaga({ 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() { export default function* categoriesSaga() {
yield all([ yield all([
takeLatest(FETCH_ROOT_CATEGORIES_REQ, getRootCategoriesSaga), takeLatest(FETCH_ROOT_CATEGORIES_REQ, getRootCategoriesSaga),
takeLatest(FETCH_IS_CATEGORIES_CHECKED_REQ, getIsCategoriesCheckedSaga), takeLatest(FETCH_IS_CATEGORIES_CHECKED_REQ, getIsCategoriesCheckedSaga),
takeLatest(GRANT_CATEGORY_REQ, grantCategoriesCheckedSaga), takeLatest(GRANT_CATEGORY_REQ, grantCategoriesCheckedSaga),
takeLatest(FETCH_ALL_CATEGORIES_REQ, getAllCategoriesSaga),
]); ]);
} }

+ 10
- 0
src/store/selectors/categoriesSelector.js Zobrazit soubor

categoriesSelector, categoriesSelector,
(state) => state.changedCategories (state) => state.changedCategories
); );

export const selectAllCategories = createSelector(
categoriesSelector,
(state) => state.allCategories
);

export const selectAllCategoriesError = createSelector(
categoriesSelector,
(state) => state.errorMessage
);

+ 13044
- 12615
yarn.lock
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


Načítá se…
Zrušit
Uložit