Skip to content

Commit

Permalink
fix: xml import params
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfuboy committed Aug 3, 2022
1 parent 5964c43 commit 8e59e11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EoMessageService } from 'eo/workbench/browser/src/app/eoui/message/eo-m
import { whatType } from '../../../utils';
import { flatData } from '../../../utils/tree/tree.utils';
import qs from 'qs';
import { form2json, parseTree, xml2UiData, xml2json, isXML } from '../../../utils/data-transfer/data-transfer.utils';
import { form2json, parseTree, xml2UiData, isXML } from '../../../utils/data-transfer/data-transfer.utils';
@Component({
selector: 'params-import',
templateUrl: './params-import.component.html',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,24 @@ export const xml2json = (tmpl) => {
return result;
};

interface uiData {
type uiData = {
textType: ApiBodyType | string;
rootType: JsonRootType | string;
data: any;
}
};
export const xml2UiData = (text) => {
const data: any[] = xml2json(text);
const result = {};
const mapAttr = (obj: any) => {
const { tagName, attr, children, content } = obj;
return {
[tagName]: children.length ? mapAttr(children[0]) : attr,
};
};
data.forEach((it) => {
const { tagName, attr, children } = it;
result[tagName] = children.length ? mapAttr(children[0]) : attr;
});
const deep = (list = []) =>
list.reduce(
(total, { tagName, content, attr, children }) => ({
...total,
[tagName]: children?.length > 0 ? deep(children || []) : content,
// attribute: attr, // * not support the key for now cause ui has not show it
}),
{}
);
const result = deep(data);
console.log('result', result);
return JSON.parse(JSON.stringify(result));
};
/**
Expand Down

0 comments on commit 8e59e11

Please sign in to comment.