Skip to content

Commit

Permalink
🌳 required root fields
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-cvit committed Feb 28, 2024
1 parent cf45350 commit 0024538
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
34 changes: 8 additions & 26 deletions cyclops-ui/src/components/pages/edit_module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ const EditModule = () => {
const [config, setConfig] = useState({
name: "",
manifest: "",
fields: [],
properties: [],
root: {
properties: [],
required: []
}
})
const [error, setError] = useState({
message: "",
Expand Down Expand Up @@ -154,7 +156,7 @@ const EditModule = () => {
setConfig(templatesRes.data);
setLoadTemplate(true);

let values = mapsToArray(templatesRes.data.fields, res.data.values);
let values = mapsToArray(templatesRes.data.root.properties, res.data.values);

setModule({
name: res.data.name,
Expand All @@ -174,26 +176,6 @@ const EditModule = () => {
setError(error.response.data);
}
});

// form.setFieldsValue(res.data.values);
// form.setFieldValue('chains.0.name', "ja sam prvi name")
// form.setFieldValue('chains.1.name', "ja sam drugi name")
//
// form.setFieldValue("chains", [
// {
// name: "ja sam name",
// type: "ja sam type",
// numValidators: 1,
// "ports.rest": 80,
// },
// {
// name: "ja sam name 2",
// type: "ja sam type 2",
// numValidators: 2,
// "ports.rest": 81,
// },
// ])

}).catch(error => {
if (error.response === undefined) {
setError({
Expand Down Expand Up @@ -276,7 +258,7 @@ const EditModule = () => {
}

const handleSubmit = (values: any) => {
values = findMaps(config.fields, values)
values = findMaps(config.root.properties, values)

axios.post(`/api/modules/update`,
{
Expand Down Expand Up @@ -374,7 +356,7 @@ const EditModule = () => {
switch (field.items.type) {
case "object":
return <div>
{mapFields(field.items.properties, parentFieldID, "", level + 1, 2, arrayField)}
{mapFields(field.items.properties, parentFieldID, "", level + 1, 2, arrayField, field.items.required)}
<MinusCircleOutlined style={{ fontSize: '16px' }} onClick={() => remove(arrayField.name)} />
</div>
case "string":
Expand Down Expand Up @@ -697,7 +679,7 @@ const EditModule = () => {
Edit Module
</Divider>
{formLoading()}
{mapFields(config.fields, "", "" , 0, 0)}
{mapFields(config.root.properties, "", "" , 0, 0, undefined, config.root.required)}
<div style={{textAlign: "right"}}>
<Button type="primary" htmlType="submit" name="Save">
Save
Expand Down
22 changes: 13 additions & 9 deletions cyclops-ui/src/components/pages/new_module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from 'antd';
import axios from 'axios';
import {useNavigate} from 'react-router';
import {MinusCircleOutlined, PlusOutlined, InfoCircleOutlined, StarFilled} from "@ant-design/icons";
import {MinusCircleOutlined, PlusOutlined, InfoCircleOutlined} from "@ant-design/icons";
import {fileExtension, flattenObjectKeys} from "../../utils/form";
import './custom.css';

Expand Down Expand Up @@ -49,8 +49,10 @@ const NewModule = () => {
name: "",
version: "",
manifest: "",
fields: [],
properties: [],
root: {
properties: [],
required: []
},
dependencies: []
})

Expand Down Expand Up @@ -236,7 +238,7 @@ const NewModule = () => {
const handleSubmit = (values: any) => {
const moduleName = values["cyclops_module_name"]

values = findMaps(config.fields, values)
values = findMaps(config.root.properties, values)

axios.post(`/api/modules/new`,
{
Expand Down Expand Up @@ -269,8 +271,10 @@ const NewModule = () => {
name: "",
version: "",
manifest: "",
fields: [],
properties: [],
root: {
properties: [],
required: []
},
dependencies: []
});
form.setFieldsValue({})
Expand Down Expand Up @@ -319,7 +323,7 @@ const NewModule = () => {
});

axios.get(`/api/templates/initial?repo=` + repo + `&path=` + path + `&commit=` + commit).then(res => {
let initialValuesMapped = mapsToArray(tmpConfig.fields, res.data)
let initialValuesMapped = mapsToArray(tmpConfig.root.properties, res.data)

setInitialValues(initialValuesMapped)
form.setFieldsValue(initialValuesMapped)
Expand Down Expand Up @@ -439,7 +443,7 @@ const NewModule = () => {
switch (field.items.type) {
case "object":
return <div>
{mapFields(field.items.properties, parentFieldID, "", level + 1, 2, arrayField)}
{mapFields(field.items.properties, parentFieldID, "", level + 1, 2, arrayField, field.items.required)}
<MinusCircleOutlined style={{ fontSize: '16px' }} onClick={() => remove(arrayField.name)} />
</div>
case "string":
Expand Down Expand Up @@ -724,7 +728,7 @@ const NewModule = () => {

function renderFormFields() {
if (!loadingTemplate && !loadingTemplateInitialValues) {
return mapFields(config.fields, [], "" , 0, 0)
return mapFields(config.root.properties, [], "" , 0, 0, undefined, config.root.required)
}

return <Spin size="large"/>
Expand Down

0 comments on commit 0024538

Please sign in to comment.