Skip to content

Commit

Permalink
Fix validation issues with removeEmptyValues function
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   client/src/components/builder/components.js
	modified:   client/src/components/builder/provenanceDomain.js
	modified:   client/src/layouts/shared/ToolsDropDown.js
  • Loading branch information
HadleyKing committed Nov 30, 2023
1 parent d310fce commit c56017f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions client/src/components/builder/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import { useFormikContext } from "formik";
import { useDispatch, useSelector } from "react-redux";
import { updateBcoStatus } from "../../slices/bcoSlice";

export const removeEmptyValues = (myData) => {
export const removeEmptyValues = (myData, excludedKeys = []) => {
const obj = JSON.parse(JSON.stringify(myData))
for (const key in obj) {
if (typeof obj[key] === "object" && obj[key] !== null) {
obj[key] = removeEmptyValues(obj[key]);
if (Object.keys(obj[key]).length === 0) {
obj[key] = removeEmptyValues(obj[key], excludedKeys);
if (Object.keys(obj[key]).length === 0 && !excludedKeys.includes(key)) {
delete obj[key];
}
} else if (!obj[key]) {
} else if (!obj[key] && !excludedKeys.includes(key)) {
delete obj[key];
}
}
Expand Down
7 changes: 2 additions & 5 deletions client/src/components/builder/provenanceDomain.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import React, { useState } from "react";
import * as Yup from "yup";
import {Card, CardContent, CardHeader, Typography, Grid, Button, TextField } from "@material-ui/core";
import {Card, CardContent, CardHeader, Typography, Grid, Button } from "@material-ui/core";
import { Formik, Form, FieldArray } from "formik";
import { Contribution, FormObserver, Reviewer, Next } from "./components";
import { useSelector, useDispatch } from "react-redux"
import { BaisicDateTimePicker, MyTextField } from "./specialFeilds";
import { updateProvenanceDomain, updateModified } from "../../slices/bcoSlice";
import "../../App.css";
import AddCircleIcon from "@mui/icons-material/AddCircle";
import RemoveCircleIcon from "@mui/icons-material/RemoveCircle";
import HelpOutlineIcon from "@mui/icons-material/HelpOutline";
import Tooltip from "@mui/material/Tooltip";
import { isRejected } from "@reduxjs/toolkit";

export const ProvenanceDomain = ({onSave} ) => {
const dispatch = useDispatch();
const provenanceDomain = useSelector(state => state.bco.data.provenance_domain)
let has_obsolete = "obsolete_after" in provenanceDomain;
let has_embargo = "embargo" in provenanceDomain;
let has_review = "review" in provenanceDomain;
let is_derived = "derived_from" in provenanceDomain;
const [obsolete, setObsolete] = useState("obsolete_after" in provenanceDomain)
Expand Down Expand Up @@ -291,4 +288,4 @@ export const ProvenanceDomain = ({onSave} ) => {
</Card>
</>
)
}
}
4 changes: 3 additions & 1 deletion client/src/layouts/shared/ToolsDropDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default function ToolsDropDown() {
const validate = () => {
console.log("Validate", BCODB_URL, jsonData)
const bcoURL = BCODB_URL
const bcoObject = removeEmptyValues(jsonData)
const bcoObject = removeEmptyValues(jsonData, [
"input_list", "external_data_endpoints", "environment_variables","value"
])
dispatch(validateBco({bcoURL, bcoObject}))
}

Expand Down

0 comments on commit c56017f

Please sign in to comment.