changes for tree structure
This commit is contained in:
parent
cddd6586f2
commit
02d841a1b1
|
|
@ -437,6 +437,7 @@ function getFieldFromValue(
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
const childrens: any = [];
|
||||||
if (value.indexOf("run") !== -1) {
|
if (value.indexOf("run") !== -1) {
|
||||||
const matches = [...value.matchAll(ACTION_TRIGGER_REGEX)];
|
const matches = [...value.matchAll(ACTION_TRIGGER_REGEX)];
|
||||||
if (matches.length) {
|
if (matches.length) {
|
||||||
|
|
@ -471,7 +472,7 @@ function getFieldFromValue(
|
||||||
successFields[0].label = "onSuccess";
|
successFields[0].label = "onSuccess";
|
||||||
successFields[0].level = level + 1;
|
successFields[0].level = level + 1;
|
||||||
successFields[0].start = true;
|
successFields[0].start = true;
|
||||||
fields.push(successFields);
|
childrens.push(successFields);
|
||||||
|
|
||||||
let errorValue;
|
let errorValue;
|
||||||
if (errorArg && errorArg.length > 0) {
|
if (errorArg && errorArg.length > 0) {
|
||||||
|
|
@ -499,13 +500,14 @@ function getFieldFromValue(
|
||||||
errorFields[0].label = "onError";
|
errorFields[0].label = "onError";
|
||||||
errorFields[0].level = level + 1;
|
errorFields[0].level = level + 1;
|
||||||
errorFields[0].start = false;
|
errorFields[0].start = false;
|
||||||
fields.push(errorFields);
|
childrens.push(errorFields);
|
||||||
|
fields[0].childrens = childrens;
|
||||||
}
|
}
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.indexOf("navigateTo") !== -1) {
|
if (value.indexOf("navigateTo") !== -1) {
|
||||||
fields.push({
|
childrens.push({
|
||||||
field: FieldType.URL_FIELD,
|
field: FieldType.URL_FIELD,
|
||||||
level: level + 1,
|
level: level + 1,
|
||||||
levelSeparator,
|
levelSeparator,
|
||||||
|
|
@ -514,7 +516,7 @@ function getFieldFromValue(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.indexOf("showModal") !== -1) {
|
if (value.indexOf("showModal") !== -1) {
|
||||||
fields.push({
|
childrens.push({
|
||||||
field: FieldType.SHOW_MODAL_FIELD,
|
field: FieldType.SHOW_MODAL_FIELD,
|
||||||
level: level + 1,
|
level: level + 1,
|
||||||
levelSeparator,
|
levelSeparator,
|
||||||
|
|
@ -522,7 +524,7 @@ function getFieldFromValue(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (value.indexOf("closeModal") !== -1) {
|
if (value.indexOf("closeModal") !== -1) {
|
||||||
fields.push({
|
childrens.push({
|
||||||
field: FieldType.CLOSE_MODAL_FIELD,
|
field: FieldType.CLOSE_MODAL_FIELD,
|
||||||
level: level + 1,
|
level: level + 1,
|
||||||
levelSeparator,
|
levelSeparator,
|
||||||
|
|
@ -530,21 +532,21 @@ function getFieldFromValue(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (value.indexOf("showAlert") !== -1) {
|
if (value.indexOf("showAlert") !== -1) {
|
||||||
fields.push(
|
childrens.push({
|
||||||
{
|
field: FieldType.ALERT_TEXT_FIELD,
|
||||||
field: FieldType.ALERT_TEXT_FIELD,
|
level: level + 1,
|
||||||
level: level + 1,
|
levelSeparator,
|
||||||
levelSeparator,
|
start: true,
|
||||||
start: true,
|
});
|
||||||
},
|
childrens.push({
|
||||||
{
|
field: FieldType.ALERT_TYPE_SELECTOR_FIELD,
|
||||||
field: FieldType.ALERT_TYPE_SELECTOR_FIELD,
|
level: level + 1,
|
||||||
level: level + 1,
|
levelSeparator,
|
||||||
levelSeparator,
|
start: false,
|
||||||
start: false,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
fields[0].childrens = childrens.length ? childrens : undefined;
|
||||||
|
// fields[].push(childrens);
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -560,6 +562,7 @@ function Fields(props: {
|
||||||
onValueChange: Function;
|
onValueChange: Function;
|
||||||
value: string;
|
value: string;
|
||||||
fields: any;
|
fields: any;
|
||||||
|
childrens?: any;
|
||||||
label?: string;
|
label?: string;
|
||||||
isValid: boolean;
|
isValid: boolean;
|
||||||
validationMessage?: string;
|
validationMessage?: string;
|
||||||
|
|
@ -570,7 +573,12 @@ function Fields(props: {
|
||||||
depth: number;
|
depth: number;
|
||||||
maxDepth: number;
|
maxDepth: number;
|
||||||
}) {
|
}) {
|
||||||
|
console.log("props.fields", props.fields);
|
||||||
|
if (!props.fields) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const ui = props.fields.map((field: any) => {
|
const ui = props.fields.map((field: any) => {
|
||||||
|
console.log("field", field);
|
||||||
if (Array.isArray(field)) {
|
if (Array.isArray(field)) {
|
||||||
if (props.depth > props.maxDepth) {
|
if (props.depth > props.maxDepth) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -730,7 +738,43 @@ function Fields(props: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div key={fieldType}>{viewElement}</div>;
|
return (
|
||||||
|
<div key={fieldType} data-key={fieldType}>
|
||||||
|
{viewElement}
|
||||||
|
{field.childrens && (
|
||||||
|
<div className="childrens">
|
||||||
|
{field.childrens.map((childField: any, index: number) => {
|
||||||
|
const firstChild = Array.isArray(childField)
|
||||||
|
? childField[0]
|
||||||
|
: childField;
|
||||||
|
return (
|
||||||
|
<Fields
|
||||||
|
key={index}
|
||||||
|
value={firstChild.value}
|
||||||
|
fields={Array.isArray(childField) ? childField : [childField]}
|
||||||
|
label={firstChild.label}
|
||||||
|
isValid={props.isValid}
|
||||||
|
validationMessage={props.validationMessage}
|
||||||
|
apiOptionTree={props.apiOptionTree}
|
||||||
|
queryOptionTree={props.queryOptionTree}
|
||||||
|
modalDropdownList={props.modalDropdownList}
|
||||||
|
pageDropdownOptions={props.pageDropdownOptions}
|
||||||
|
depth={props.depth + 1}
|
||||||
|
maxDepth={props.maxDepth}
|
||||||
|
onValueChange={(value: any) => {
|
||||||
|
props.onValueChange(
|
||||||
|
firstChild.getParentValue(
|
||||||
|
value.substring(2, value.length - 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return <>{ui}</>;
|
return <>{ui}</>;
|
||||||
|
|
@ -843,6 +887,11 @@ export function ActionCreator(props: ActionCreatorProps) {
|
||||||
const modalDropdownList = useModalDropdownList();
|
const modalDropdownList = useModalDropdownList();
|
||||||
const pageDropdownOptions = useSelector(getPageDropdownOptions);
|
const pageDropdownOptions = useSelector(getPageDropdownOptions);
|
||||||
const fields = getFieldFromValue(props.value, 0, false);
|
const fields = getFieldFromValue(props.value, 0, false);
|
||||||
|
if (fields.length > 1) {
|
||||||
|
fields[0].childrens = fields.splice(1, fields.length - 1);
|
||||||
|
console.log(fields);
|
||||||
|
}
|
||||||
|
console.log("fields", fields);
|
||||||
return (
|
return (
|
||||||
<Fields
|
<Fields
|
||||||
value={props.value}
|
value={props.value}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ function getSelectedOption(
|
||||||
defaultText: string,
|
defaultText: string,
|
||||||
options: TreeDropdownOption[],
|
options: TreeDropdownOption[],
|
||||||
) {
|
) {
|
||||||
let selectedOption = {
|
let selectedOption: TreeDropdownOption = {
|
||||||
label: defaultText,
|
label: defaultText,
|
||||||
value: "",
|
value: "",
|
||||||
};
|
};
|
||||||
|
|
@ -88,7 +88,9 @@ export default function TreeDropdown(props: TreeDropdownProps) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function renderTreeOption(option: TreeDropdownOption) {
|
function renderTreeOption(option: TreeDropdownOption) {
|
||||||
const isSelected = selectedOption.value === option.value;
|
const isSelected =
|
||||||
|
selectedOption.value === option.value ||
|
||||||
|
selectedOption.type === option.value;
|
||||||
return (
|
return (
|
||||||
<StyledMenuItem
|
<StyledMenuItem
|
||||||
className={option.className || "single-select"}
|
className={option.className || "single-select"}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user