diff --git a/backend/SC4SNMP_UI_backend/ui_handling/routes.py b/backend/SC4SNMP_UI_backend/ui_handling/routes.py index 1894812..7c76aca 100644 --- a/backend/SC4SNMP_UI_backend/ui_handling/routes.py +++ b/backend/SC4SNMP_UI_backend/ui_handling/routes.py @@ -69,10 +69,15 @@ def get_all_profiles_list(): @cross_origin() def add_profile_record(): profile_obj = request.json - profile_obj = profile_conversion.ui2backend(profile_obj) - mongo_profiles.insert_one(profile_obj) - return jsonify("success") - + same_name_profiles = list(mongo_profiles.find({f"{profile_obj['profileName']}": {"$exists": True}})) + if len(same_name_profiles) > 0: + result = jsonify( + {"message": f"Profile with name {profile_obj['profileName']} already exists. Profile was not added."}), 400 + else: + profile_obj = profile_conversion.ui2backend(profile_obj) + mongo_profiles.insert_one(profile_obj) + result = jsonify("success") + return result @ui.route('/profiles/delete/', methods=['POST']) @cross_origin() @@ -96,6 +101,12 @@ def delete_profile(index, record_to_update, kwargs): def update_profile_record(profile_id): profile_obj = request.json new_profile_name = profile_obj['profileName'] + + same_name_profiles = list(mongo_profiles.find({f"{new_profile_name}": {"$exists": True}})) + if len(same_name_profiles) > 0: + return jsonify( + {"message": f"Profile with name {new_profile_name} already exists. Profile was not edited."}), 400 + profile_obj = profile_conversion.ui2backend(profile_obj) old_profile = list(mongo_profiles.find({'_id': ObjectId(profile_id)}, {"_id": 0}))[0] diff --git a/frontend/packages/manager/src/components/inventory/AddInventoryModal.jsx b/frontend/packages/manager/src/components/inventory/AddInventoryModal.jsx index 7f17a8d..5621c6d 100644 --- a/frontend/packages/manager/src/components/inventory/AddInventoryModal.jsx +++ b/frontend/packages/manager/src/components/inventory/AddInventoryModal.jsx @@ -78,8 +78,6 @@ function AddInventoryModal() { .catch((error) => { ErrCtx.setOpen(true); ErrCtx.setMessage(error.response.data.message); - console.log(error.response.data); - console.log(error.response.status); }) }; @@ -91,8 +89,6 @@ function AddInventoryModal() { .catch((error) => { ErrCtx.setOpen(true); ErrCtx.setMessage(error.response.data.message); - console.log(error.response.data); - console.log(error.response.status); }) }; diff --git a/frontend/packages/manager/src/components/profiles/AddProfileModal.jsx b/frontend/packages/manager/src/components/profiles/AddProfileModal.jsx index 39aa931..8bd80ca 100644 --- a/frontend/packages/manager/src/components/profiles/AddProfileModal.jsx +++ b/frontend/packages/manager/src/components/profiles/AddProfileModal.jsx @@ -54,8 +54,13 @@ function AddProfileModal(props) { .then((response) => { console.log(response); ProfCtx.makeProfilesChange(); - }) - } + }) + .catch((error) => { + console.log(error); + ErrCtx.setOpen(true); + ErrCtx.setMessage(error.response.data.message); + }); + }; const updateProfile = (profileObj, profileId) => { axios.post(`http://${backendHost}/profiles/update/${profileId}`, profileObj) @@ -65,8 +70,12 @@ function AddProfileModal(props) { ErrCtx.setOpen(true); ErrCtx.setMessage(response.data.message); } - }) - } + }) + .catch((error) => { + ErrCtx.setOpen(true); + ErrCtx.setMessage(error.response.data.message); + }); + }; const handleRequestClose = useCallback( (e) => { diff --git a/frontend/packages/manager/src/components/profiles/ProfilesList.jsx b/frontend/packages/manager/src/components/profiles/ProfilesList.jsx index c476cc2..b7fb029 100644 --- a/frontend/packages/manager/src/components/profiles/ProfilesList.jsx +++ b/frontend/packages/manager/src/components/profiles/ProfilesList.jsx @@ -12,6 +12,40 @@ import ErrorsModalContext from "../../store/errors-modal-contxt"; import {backendHost} from "../../host"; import {Pagination} from "../../styles/groups/GroupsStyle"; import DeleteModal from "../DeleteModal"; +import P from "@splunk/react-ui/Paragraph"; + + +function getExpansionRow(row) { + return ( + + {/* Empty cell */} + {/* Empty cell */} + {/* Empty cell */} + {row.conditions.field} + {row.conditions.patterns && row.conditions.patterns.map(value => +

{value.pattern}

)}
+ + {row.varBinds.map((value) => ( +

{value.family}

+ ))} +
+ + + {row.varBinds.map((value) => ( +

{value.category}

+ ))} +
+ + + {row.varBinds.map((value) => ( +

{value.index}

+ ))} +
+ + +
+ ); +} function ProfilesList() { @@ -31,6 +65,7 @@ function ProfilesList() { const [pageNum, setPageNum] = useState(1); const [totalPages, setTotalPages] = useState(1); const [profilesRecords, setProfilesRecords] = useState([]); + const [expandedRowId, setExpandedRowId] = useState(null); const ProfCtx = useContext(ProfileContext); const ErrCtx = useContext(ErrorsModalContext); @@ -102,6 +137,14 @@ function ProfilesList() { ProfCtx.addModalToggle?.current?.focus(); }; + const handleRowExpansion = (rowId) => { + if (expandedRowId === rowId) { + setExpandedRowId(null); + } else { + setExpandedRowId(rowId); + } + }; + return (
@@ -132,7 +175,12 @@ function ProfilesList() { {profilesRecords .map((row) => ( - + handleRowExpansion(row._id)} + expanded={row._id === expandedRowId} + > {row.profileName} {row.frequency} {row.conditions.condition}