Skip to content

Commit

Permalink
Merge pull request #178 from eclipse-tractusx/feat/frontend/add-new-f…
Browse files Browse the repository at this point in the history
…ield-for-negotiation-catalog

Add new Field on negotiation catalog
  • Loading branch information
fabiodmota authored May 14, 2024
2 parents 5b8a2b1 + 8ef5a0a commit e94ecd3
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 38 deletions.
2 changes: 2 additions & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ REACT_APP_DELETE_REPORTS=/api/dashboard/deleteReport
REACT_APP_GET_USER_BPDM_GATES=/api/dashboard/getAllUserBPDMGates?
REACT_APP_DELETE_RATINGS=/api/dashboard/deleteRating
REACT_APP_GET_COMPANY_USERS=/api/dashboard/getUserFromCompany?
REACT_APP_GET_QUERY_CATALOG=/api/negotiation/queryCatalog?
REACT_APP_POST_TRIGGER_NEGOTIATION=/api/negotiation/triggerNegotiation?
64 changes: 34 additions & 30 deletions frontend/DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
npm/npmjs/-/axios/1.6.4, MIT, approved, #11338
npm/npmjs/-/clsx/2.0.0, MIT, approved, clearlydefined
npm/npmjs/-/cssstyle/3.0.0, MIT, approved, clearlydefined
npm/npmjs/-/data-urls/4.0.0, MIT, approved, clearlydefined
npm/npmjs/-/domexception/4.0.0, MIT, approved, clearlydefined
npm/npmjs/-/follow-redirects/1.15.5, MIT, approved, #10782
npm/npmjs/-/html-encoding-sniffer/3.0.0, MIT, approved, clearlydefined
npm/npmjs/-/html-parse-stringify/3.0.1, MIT, approved, clearlydefined
npm/npmjs/-/http-proxy-agent/5.0.0, MIT, approved, clearlydefined
npm/npmjs/-/i18next/22.5.1, MIT, approved, #9143
npm/npmjs/-/jsdom/22.0.0, MIT AND LGPL-2.0-or-later, approved, #8188
npm/npmjs/-/react-i18next/13.5.0, MIT AND Apache-2.0, approved, #11697
npm/npmjs/-/rrweb-cssom/0.6.0, MIT, approved, clearlydefined
npm/npmjs/-/saxes/6.0.0, ISC, approved, clearlydefined
npm/npmjs/-/tr46/4.1.1, MIT, approved, clearlydefined
npm/npmjs/-/void-elements/3.1.0, MIT, approved, clearlydefined
npm/npmjs/-/w3c-xmlserializer/4.0.0, MIT, approved, clearlydefined
npm/npmjs/-/webidl-conversions/7.0.0, BSD-2-Clause, approved, clearlydefined
npm/npmjs/-/whatwg-encoding/2.0.0, MIT, approved, clearlydefined
npm/npmjs/-/whatwg-mimetype/3.0.0, MIT, approved, clearlydefined
npm/npmjs/-/whatwg-url/12.0.1, MIT, approved, clearlydefined
npm/npmjs/-/xml-name-validator/4.0.0, Apache-2.0, approved, clearlydefined
npm/npmjs/@adobe/css-tools/4.3.2, MIT, approved, #9985
npm/npmjs/@catena-x/portal-shared-components/2.1.30, Apache-2.0 AND CC-BY-4.0, approved, #10502
npm/npmjs/@mui/private-theming/5.14.20, MIT, approved, #10973
npm/npmjs/@mui/styled-engine/5.14.20, MIT, approved, #10971
npm/npmjs/@mui/system/5.14.20, MIT AND CC-BY-3.0, approved, #9905
npm/npmjs/@mui/types/7.2.12, MIT, approved, clearlydefined
npm/npmjs/@mui/x-data-grid/6.18.4, MIT AND ISC, approved, #11696
npm/npmjs/@tootallnate/once/2.0.0, MIT, approved, clearlydefined
npm/npmjs/-/ansi-styles/3.2.1, MIT, approved, clearlydefined
npm/npmjs/-/attr-accept/2.2.2, MIT, approved, clearlydefined
npm/npmjs/-/browserslist/4.23.0, MIT, approved, clearlydefined
npm/npmjs/-/caniuse-lite/1.0.30001607, CC-BY-4.0, approved, #1196
npm/npmjs/-/chalk/2.4.2, MIT, approved, clearlydefined
npm/npmjs/-/color-convert/1.9.3, MIT, approved, clearlydefined
npm/npmjs/-/color-name/1.1.3, MIT, approved, clearlydefined
npm/npmjs/-/country-data/0.0.31, MIT, approved, #14666
npm/npmjs/-/currency-symbol-map/2.2.0, BSD-2-Clause, approved, clearlydefined
npm/npmjs/-/electron-to-chromium/1.4.729, ISC, approved, #1950
npm/npmjs/-/escape-string-regexp/1.0.5, MIT, approved, clearlydefined
npm/npmjs/-/file-selector/0.6.0, MIT, approved, #3230
npm/npmjs/-/has-flag/3.0.0, MIT, approved, clearlydefined
npm/npmjs/-/node-releases/2.0.14, MIT, approved, #1954
npm/npmjs/-/postcss/8.4.38, MIT, approved, #3545
npm/npmjs/-/react-dropzone/14.2.3, MIT, approved, clearlydefined
npm/npmjs/-/source-map-js/1.2.0, BSD-3-Clause, approved, #13911
npm/npmjs/-/supports-color/5.5.0, MIT, approved, clearlydefined
npm/npmjs/@babel/code-frame/7.24.2, MIT AND (BSD-2-Clause AND ISC AND MIT) AND BSD-2-Clause AND BSD-3-Clause, approved, #13943
npm/npmjs/@babel/compat-data/7.24.4, MIT AND (BSD-2-Clause AND ISC AND MIT) AND BSD-2-Clause AND BSD-3-Clause, approved, #13915
npm/npmjs/@babel/core/7.24.4, MIT AND (BSD-2-Clause AND ISC AND MIT) AND BSD-2-Clause AND BSD-3-Clause, approved, #13942
npm/npmjs/@babel/generator/7.24.4, MIT AND (BSD-2-Clause AND ISC AND MIT) AND BSD-2-Clause AND BSD-3-Clause, approved, #13919
npm/npmjs/@babel/helper-compilation-targets/7.23.6, MIT, approved, clearlydefined
npm/npmjs/@babel/helper-validator-option/7.23.5, MIT, approved, clearlydefined
npm/npmjs/@babel/helpers/7.24.4, MIT AND (BSD-2-Clause AND ISC AND MIT) AND BSD-2-Clause AND BSD-3-Clause, approved, #13922
npm/npmjs/@babel/highlight/7.24.2, MIT AND (BSD-2-Clause AND ISC AND MIT) AND BSD-2-Clause AND BSD-3-Clause, approved, #13941
npm/npmjs/@babel/parser/7.24.4, MIT AND (BSD-2-Clause AND ISC AND MIT) AND BSD-2-Clause AND BSD-3-Clause, approved, #13492
npm/npmjs/@babel/template/7.24.0, MIT, approved, clearlydefined
npm/npmjs/@babel/traverse/7.24.1, MIT AND (BSD-2-Clause AND ISC AND MIT) AND BSD-2-Clause AND BSD-3-Clause, approved, #13926
npm/npmjs/@babel/types/7.24.0, MIT, approved, clearlydefined
npm/npmjs/@catena-x/portal-shared-components/2.1.40, Apache-2.0 AND CC-BY-4.0, approved, #10502
npm/npmjs/@jridgewell/gen-mapping/0.3.5, MIT, approved, clearlydefined
npm/npmjs/@jridgewell/set-array/1.2.1, MIT, approved, clearlydefined
npm/npmjs/@jridgewell/trace-mapping/0.3.25, MIT, approved, #9904
15 changes: 15 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@testing-library/user-event": "^14.5.1",
"axios": "1.6.4",
"buffer": "^6.0.3",
"country-data": "^0.0.31",
"cx-portal-shared-components": "0.4.5",
"d3-fetch": "^3.0.1",
"env-cmd": "^10.1.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script>
window.ENV = {
REACT_APP_COUNTRY_RISK_API: "http://localhost:8080",
REACT_APP_AUTH_URL: "https://localhost:8081/auth",
REACT_APP_AUTH_URL: "http://localhost:8080/auth",
REACT_APP_PORTAL_FRONTEND: "http://localhost:3000",
REACT_APP_PORTAL_BACKEND: "http://localhost:8080",
REACT_APP_COUNTRY_RISK_CLIENT: "country_risk_client",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import UserService from "../../services/UserService";
import { CompanyUserContext } from "../../../contexts/companyuser";
import { GatesContext } from "../../../contexts/gates";
import DetailDialog from "../DetailDialog/DetailDialog";
import { countries } from "country-data";

const DashboardTable2 = (ratings, years) => {
//Data Fetch
Expand Down Expand Up @@ -100,7 +101,10 @@ const DashboardTable2 = (ratings, years) => {
if (countryS !== "none") {
const array = [];
globalData.forEach((gd) => {
if (gd.country === countryS.country) {
const countryFullName = countries[gd.country]
? countries[gd.country].name
: "";
if (countryFullName === countryS.country) {
array.push(gd);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { useState, useRef, useContext } from "react";
import { useState, useRef, useContext, useEffect } from "react";
import {
UserAvatar,
UserMenu,
Expand All @@ -36,7 +36,16 @@ import { CompanyUserContext } from "../../../../contexts/companyuser";
export const UserInfo = () => {
const [menuOpen, setMenuOpen] = useState(false);
const wrapperRef = useRef(null);
const { companyUser } = useContext(CompanyUserContext);
const { companyUser, setCompanyUser } = useContext(CompanyUserContext);
const [cleanedRoles, setCleanedRoles] = useState([]);

useEffect(() => {
// Clean up roles by trimming whitespace
if (companyUser && companyUser.roles) {
const cleanedRoles = companyUser.roles.map((role) => role.trim());
setCleanedRoles(cleanedRoles);
}
}, [companyUser]);

const openCloseMenu = () => setMenuOpen((prevVal) => !prevVal);

Expand All @@ -58,8 +67,9 @@ export const UserInfo = () => {

// Add negotiation link for users with Negotiator or Admin roles
if (
companyUser.roles.includes("Negotiator") ||
companyUser.roles.includes("Admin")
cleanedRoles.includes("Negotiator") ||
cleanedRoles.includes("Admin") ||
cleanedRoles.includes("Company Admin")
) {
menuItems = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ const NegotiationPage = () => {
const navigate = useNavigate();
const [catalogItems, setCatalogItems] = useState([]);
const [selectedItems, setSelectedItems] = useState([]);
const [cleanedRoles, setCleanedRoles] = useState([]);

useEffect(() => {
// Clean up roles by trimming whitespace
if (companyUser && companyUser.roles) {
const cleanedRoles = companyUser.roles.map((role) => role.trim());
setCleanedRoles(cleanedRoles);
}
}, [companyUser]);

useEffect(() => {
// Fetch catalog items from the API
Expand Down Expand Up @@ -111,6 +120,7 @@ const NegotiationPage = () => {
const negotiationRequest = selectedItems.map((item) => ({
id: item.id,
offerId: item.offerId,
usagePurpose: item.usagePurpose,
}));

try {
Expand Down Expand Up @@ -146,8 +156,13 @@ const NegotiationPage = () => {

// Check if the user has permission to initiate negotiations
const userCanNegotiate =
companyUser.roles.includes("Negotiator") ||
companyUser.roles.includes("Admin"); // Adjust the role check as necessary
cleanedRoles.includes("Negotiator") ||
cleanedRoles.includes("Admin") ||
cleanedRoles.includes("Company Admin"); // Adjust the role check as necessary

console.log("cleanedRoles", cleanedRoles);
console.log("companyUser", companyUser);
console.log("userCanNegotiate", userCanNegotiate);

return (
<div className="negotiation-page">
Expand Down

0 comments on commit e94ecd3

Please sign in to comment.