Skip to content

Commit

Permalink
Add style
Browse files Browse the repository at this point in the history
  • Loading branch information
AleClaudia committed Feb 10, 2020
2 parents 3cb48c5 + 0bd7de4 commit 65d543a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 63 deletions.
15 changes: 6 additions & 9 deletions utils/StateAndPropsToValues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ function ParseAndReplace(object: object, stateAndProps: object): object {
const parts = object[key].split(".");
if (parts[0] === "$props" || parts[0] === "$prop") {
object[key] =
stateAndProps["propDefinitions"][parts[1]]?.defaultValue || "";
stateAndProps["propDefinitions"][parts[1]]?.defaultValue ?? "";
} else if (parts[0] === "$state") {
console.log("Before:", object);
object[key] =
stateAndProps["stateDefinitions"][parts[1]]?.defaultValue || "";
console.log("After:", object);
} // TO-DO: else for local
stateAndProps["stateDefinitions"][parts[1]]?.defaultValue ?? "";
}
}
}
if (typeof object[key] === "object") {
Expand All @@ -21,13 +19,13 @@ function ParseAndReplace(object: object, stateAndProps: object): object {
object[key].referenceType === "props"
) {
object[key] =
stateAndProps["propDefinitions"][object[key].id]?.defaultValue ||
stateAndProps["propDefinitions"][object[key].id]?.defaultValue ??
"";
} else if (object[key].referenceType === "state") {
object[key] =
stateAndProps["stateDefinitions"][object[key].id]?.defaultValue ||
stateAndProps["stateDefinitions"][object[key].id]?.defaultValue ??
"";
} // TO-DO: else for local
}
} else {
object[key] = ParseAndReplace(object[key], stateAndProps);
}
Expand All @@ -47,7 +45,6 @@ const StateAndPropsToValues = (FlattenedUIDL: object[]) => {
let ref = result[i]["elementInfo"]["reference"];
if (ref) {
if (ref["content"] !== result[i]["elementInfo"]["value"]) {
console.log(ref["content"], result[i]["elementInfo"]["value"]);
result[i - 1]["elementInfo"] = { filterCondition: "filter" };
}
}
Expand Down
57 changes: 3 additions & 54 deletions utils/UIDLParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,18 @@ import { UIDLElementContent } from "../interfaces/UIDL";
const htmlMap = require("../utils/html-mapping.json");

const UILDParser = (obj: UIDLElementContent, depthLevel: number = -1) => {
let defaultState;
let defaultProps;
const array: UIDLElementContent[] = Array.isArray(obj) ? obj : [obj];

return array.reduce(
(acc: UIDLElementContent[], value: UIDLElementContent) => {
if (value.reference && !value.value) {
if (value.reference && value.value != "0" && !value.value) {
value.filterCondition = "filter";
delete value.node;
delete value.reference;
}
if (value.node) {
if (depthLevel !== -1) {
value.filterCondition = "filter";
} else {
if (value.stateDefinitions) {
defaultState = value.stateDefinitions;
}
if (value.propDefinitions) {
defaultProps = value.propDefinitions;
}
}
const nestedNode = UILDParser(value.node.content, depthLevel + 1);
acc = acc.concat(...nestedNode);
Expand All @@ -43,7 +34,7 @@ const UILDParser = (obj: UIDLElementContent, depthLevel: number = -1) => {
}
//check if children is an array of strings
if (typeof value.children[0] === "string") {
let test = value.children.map((child: any, i) => {
let reference = value.children.map((child: any, i) => {
// treated dynamic children if it's a prop
if (child.includes("$")) {
let neededValue = child.split(".");
Expand All @@ -56,8 +47,7 @@ const UILDParser = (obj: UIDLElementContent, depthLevel: number = -1) => {
return { type: "static", content: child };
}
});

value.children = test;
value.children = reference;
}
const newValues = value.children.map(child => {
if (child.type === "conditional") {
Expand All @@ -75,45 +65,4 @@ const UILDParser = (obj: UIDLElementContent, depthLevel: number = -1) => {
);
};

// delete?
const fixSpecialCases = (
result: UIDLElementContent[],
state,
props: object
) => {
// filter values that can't be transformed into HTML ex: reference
const filteredResult = result.filter(
element => element.elementInfo["filterCondition"] !== "filter"
);
// Treat DefaultProps Case
if (props && Object.keys(props).length) {
const consideringProps = filteredResult.map((element, i) => {
let myFindById = Object.keys(props).find(
prop => prop === element.elementInfo["id"]
);

if (element.elementInfo["attrs"]) {
let myFindByAttr = Object.keys(props).find(
prop => prop === element.elementInfo["attrs"]
);
// console.log(element);
// element.elementInfo["attrs"][props[i]];
}
// console.log("Element: ", element.elementInfo);
// console.log("*****************BREAK************************");

if (myFindById) {
return (element = {
elementInfo: props[myFindById].defaultValue,
depthLevel: element.depthLevel
});
} else {
return element;
}
});
return consideringProps;
}
return filteredResult;
};

export default UILDParser;

0 comments on commit 65d543a

Please sign in to comment.