@devtools-ui/object-inspector 0.2.0 → 0.2.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +70 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +72 -9
- package/dist/index.mjs +72 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/components/ObjectInspectorComponent.tsx +102 -9
- package/src/components/__tests__/object-inspector.test.tsx +118 -0
- package/src/components/__tests__/pureFunctions.test.ts +37 -0
- package/src/dsl/__tests__/ObjectInspector.test.tsx +22 -0
- package/src/types/index.ts +3 -0
- package/types/components/ObjectInspectorComponent.d.ts +2 -0
- package/types/types/index.d.ts +2 -0
package/dist/cjs/index.cjs
CHANGED
|
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
ObjectInspector: () =>
|
|
33
|
+
ObjectInspector: () => ObjectInspector2,
|
|
34
34
|
ObjectInspectorComponent: () => ObjectInspectorComponent,
|
|
35
35
|
objectInspectorTransform: () => objectInspectorTransform
|
|
36
36
|
});
|
|
@@ -41,9 +41,68 @@ var import_react = __toESM(require("react"));
|
|
|
41
41
|
var import_react2 = require("@chakra-ui/react");
|
|
42
42
|
var import_object_inspector = require("@devtools-ds/object-inspector");
|
|
43
43
|
var import_react3 = require("@player-ui/react");
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
var isObject = (value) => {
|
|
45
|
+
return value != null && (value.constructor === Object || !value.constructor && typeof value === "object" || Array.isArray(value));
|
|
46
|
+
};
|
|
47
|
+
var getPathvalue = (object, path) => {
|
|
48
|
+
const keys = path.split(".");
|
|
49
|
+
let result = object;
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
const arrayIndex = key.search(/\[\d+\]$/);
|
|
52
|
+
if (result[key] === void 0 && arrayIndex === -1)
|
|
53
|
+
return "No result for the given path";
|
|
54
|
+
if (arrayIndex > -1) {
|
|
55
|
+
const subkey = key.substring(0, arrayIndex);
|
|
56
|
+
const subIndexMatch = key.match(/(?<=\[)\d+(?=\])/);
|
|
57
|
+
result = result[subkey][subIndexMatch ? subIndexMatch[0] : 0];
|
|
58
|
+
if (result === void 0)
|
|
59
|
+
return "No result for the given index";
|
|
60
|
+
} else {
|
|
61
|
+
result = result[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
};
|
|
66
|
+
var FilterObjectInspector = (props) => {
|
|
67
|
+
const { data, id } = props;
|
|
68
|
+
const [filterCriteria, setFilterCriteria] = (0, import_react.useState)("");
|
|
69
|
+
const [resultData, setResultData] = (0, import_react.useState)(data);
|
|
70
|
+
const onChangeHandler = (e) => {
|
|
71
|
+
setFilterCriteria(e.target.value);
|
|
72
|
+
const result = getPathvalue(data, e.target.value);
|
|
73
|
+
setResultData(e.target.value.length ? result : data);
|
|
74
|
+
};
|
|
75
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { style: { margin: "16px" } }, /* @__PURE__ */ import_react.default.createElement(
|
|
76
|
+
import_react2.Input,
|
|
77
|
+
{
|
|
78
|
+
placeholder: "Search path...",
|
|
79
|
+
value: filterCriteria,
|
|
80
|
+
onChange: onChangeHandler
|
|
81
|
+
}
|
|
82
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
83
|
+
"div",
|
|
84
|
+
{
|
|
85
|
+
style: {
|
|
86
|
+
border: "1px solid #e0e0e0",
|
|
87
|
+
borderRadius: "8px",
|
|
88
|
+
padding: "8px"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
!isObject(resultData) ? /* @__PURE__ */ import_react.default.createElement(import_react2.Text, { style: { padding: "0 16px", color: "#EE8956" } }, resultData) : null,
|
|
92
|
+
isObject(resultData) ? /* @__PURE__ */ import_react.default.createElement(
|
|
93
|
+
import_object_inspector.ObjectInspector,
|
|
94
|
+
{
|
|
95
|
+
data: resultData,
|
|
96
|
+
includePrototypes: false,
|
|
97
|
+
expandLevel: 3,
|
|
98
|
+
id: `filter-${id}`
|
|
99
|
+
}
|
|
100
|
+
) : null
|
|
101
|
+
));
|
|
102
|
+
};
|
|
103
|
+
var ObjectInspector = (props) => {
|
|
104
|
+
const { data, id } = props;
|
|
105
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
47
106
|
import_object_inspector.ObjectInspector,
|
|
48
107
|
{
|
|
49
108
|
data,
|
|
@@ -51,7 +110,11 @@ var ObjectInspectorComponent = (props) => {
|
|
|
51
110
|
expandLevel: 7,
|
|
52
111
|
id
|
|
53
112
|
}
|
|
54
|
-
)
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
var ObjectInspectorComponent = (props) => {
|
|
116
|
+
const { filter, data, label } = props;
|
|
117
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, label && /* @__PURE__ */ import_react.default.createElement(import_react3.ReactAsset, { ...label }), data ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, filter ? /* @__PURE__ */ import_react.default.createElement(FilterObjectInspector, { ...props }) : /* @__PURE__ */ import_react.default.createElement(ObjectInspector, { ...props })) : /* @__PURE__ */ import_react.default.createElement(import_react2.Text, null, "No data available"));
|
|
55
118
|
};
|
|
56
119
|
|
|
57
120
|
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/dsl/ObjectInspector.tsx
|
|
@@ -59,14 +122,14 @@ var import_react4 = __toESM(require("react"));
|
|
|
59
122
|
var import_dsl = require("@player-tools/dsl");
|
|
60
123
|
var import_text = require("@devtools-ui/text");
|
|
61
124
|
var import_collection = require("@devtools-ui/collection");
|
|
62
|
-
var
|
|
125
|
+
var ObjectInspector2 = (props) => {
|
|
63
126
|
const { children, binding, ...rest } = props;
|
|
64
127
|
return /* @__PURE__ */ import_react4.default.createElement(import_dsl.Asset, { type: "object-inspector", ...rest }, binding && /* @__PURE__ */ import_react4.default.createElement("property", { name: "binding" }, binding.toValue()), children);
|
|
65
128
|
};
|
|
66
129
|
var CollectionComp = (props) => {
|
|
67
130
|
return /* @__PURE__ */ import_react4.default.createElement(import_collection.Collection, null, /* @__PURE__ */ import_react4.default.createElement(import_collection.Collection.Values, null, props.children));
|
|
68
131
|
};
|
|
69
|
-
|
|
132
|
+
ObjectInspector2.Label = (0, import_dsl.createSlot)({
|
|
70
133
|
name: "label",
|
|
71
134
|
TextComp: import_text.Text,
|
|
72
135
|
CollectionComp,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/components/ObjectInspectorComponent.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/dsl/ObjectInspector.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/transformer/index.ts"],"sourcesContent":["export * from \"./components\";\nexport * from \"./dsl\";\nexport * from \"./types\";\nexport * from \"./transformer\";\n","import React from \"react\";\nimport { Text } from \"@chakra-ui/react\";\nimport { ObjectInspector as ObjectorInspectorDS } from \"@devtools-ds/object-inspector\";\nimport { ReactAsset } from \"@player-ui/react\";\nimport { ObjectInspectorAsset } from \"../types\";\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/components/ObjectInspectorComponent.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/dsl/ObjectInspector.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/transformer/index.ts"],"sourcesContent":["export * from \"./components\";\nexport * from \"./dsl\";\nexport * from \"./types\";\nexport * from \"./transformer\";\n","import React, { useState } from \"react\";\nimport { Text, Input } from \"@chakra-ui/react\";\nimport { ObjectInspector as ObjectorInspectorDS } from \"@devtools-ds/object-inspector\";\nimport { ReactAsset } from \"@player-ui/react\";\nimport { Flow } from \"@player-ui/types\";\nimport { ObjectInspectorAsset } from \"../types\";\n\nexport const isObject = (value: any): boolean => {\n return (\n value != null &&\n (value.constructor === Object ||\n (!value.constructor && typeof value === \"object\") ||\n Array.isArray(value))\n );\n};\n\nexport const getPathvalue = (object: object, path: string) => {\n const keys = path.split(\".\");\n let result: any = object;\n for (const key of keys) {\n const arrayIndex = key.search(/\\[\\d+\\]$/);\n\n if (result[key] === undefined && arrayIndex === -1)\n return \"No result for the given path\";\n\n // If key has a numeric index, e.g. for Multi-copy and/or array values.\n if (arrayIndex > -1) {\n const subkey = key.substring(0, arrayIndex);\n const subIndexMatch = key.match(/(?<=\\[)\\d+(?=\\])/);\n\n result = result[subkey][subIndexMatch ? subIndexMatch[0] : 0];\n if (result === undefined) return \"No result for the given index\";\n } else {\n result = result[key];\n }\n }\n return result;\n};\n\nconst FilterObjectInspector = (props: ObjectInspectorAsset) => {\n const { data, id } = props;\n\n const [filterCriteria, setFilterCriteria] = useState(\"\");\n const [resultData, setResultData] = useState(data);\n\n const onChangeHandler: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setFilterCriteria(e.target.value);\n\n const result = getPathvalue(data as Flow, e.target.value);\n setResultData(e.target.value.length ? result : data);\n };\n\n return (\n <div style={{ margin: \"16px\" }}>\n <Input\n placeholder=\"Search path...\"\n value={filterCriteria}\n onChange={onChangeHandler}\n />\n <div\n style={{\n border: \"1px solid #e0e0e0\",\n borderRadius: \"8px\",\n padding: \"8px\",\n }}\n >\n {!isObject(resultData) ? (\n <Text style={{ padding: \"0 16px\", color: \"#EE8956\" }}>\n {resultData as any}\n </Text>\n ) : null}\n\n {isObject(resultData) ? (\n <ObjectorInspectorDS\n data={resultData as Flow}\n includePrototypes={false}\n expandLevel={3}\n id={`filter-${id}`}\n />\n ) : null}\n </div>\n </div>\n );\n};\n\nconst ObjectInspector = (props: ObjectInspectorAsset) => {\n const { data, id } = props;\n\n return (\n <ObjectorInspectorDS\n data={data as Flow}\n includePrototypes={false}\n expandLevel={7}\n id={id}\n />\n );\n};\n\nexport const ObjectInspectorComponent = (props: ObjectInspectorAsset) => {\n const { filter, data, label } = props;\n\n return (\n <>\n {label && <ReactAsset {...label} />}\n {data ? (\n <>\n {filter ? (\n <FilterObjectInspector {...props} />\n ) : (\n <ObjectInspector {...props} />\n )}\n </>\n ) : (\n <Text>No data available</Text>\n )}\n </>\n );\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n createSlot,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { Asset as AssetType } from \"@player-ui/player\";\nimport { Text } from \"@devtools-ui/text\";\nimport { Collection } from \"@devtools-ui/collection\";\nimport type { ObjectInspectorAsset } from \"../types\";\n\nexport const ObjectInspector = (\n props: Omit<AssetPropsWithChildren<ObjectInspectorAsset>, \"binding\"> & {\n /** The binding */\n binding?: BindingTemplateInstance;\n }\n) => {\n const { children, binding, ...rest } = props;\n\n return (\n <Asset type=\"object-inspector\" {...rest}>\n {binding && <property name=\"binding\">{binding.toValue()}</property>}\n {children}\n </Asset>\n );\n};\n\nconst CollectionComp = (props: AssetPropsWithChildren<AssetType>) => {\n return (\n <Collection>\n <Collection.Values>{props.children}</Collection.Values>\n </Collection>\n );\n};\n\nObjectInspector.Label = createSlot({\n name: \"label\",\n TextComp: Text,\n CollectionComp,\n isArray: false,\n wrapInAsset: true,\n});\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { ObjectInspectorAsset, TransformedObjectInspector } from \"../types\";\n\n/**\n * Access the object from the data model\n */\nexport const objectInspectorTransform: TransformFunction<\n ObjectInspectorAsset,\n TransformedObjectInspector\n> = (asset, options) => {\n return {\n ...asset,\n data:\n asset.binding === undefined\n ? undefined\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: false,\n }),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,yBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAgC;AAChC,IAAAC,gBAA4B;AAC5B,8BAAuD;AACvD,IAAAA,gBAA2B;AAIpB,IAAM,WAAW,CAAC,UAAwB;AAC/C,SACE,SAAS,SACR,MAAM,gBAAgB,UACpB,CAAC,MAAM,eAAe,OAAO,UAAU,YACxC,MAAM,QAAQ,KAAK;AAEzB;AAEO,IAAM,eAAe,CAAC,QAAgB,SAAiB;AAC5D,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,MAAI,SAAc;AAClB,aAAW,OAAO,MAAM;AACtB,UAAM,aAAa,IAAI,OAAO,UAAU;AAExC,QAAI,OAAO,GAAG,MAAM,UAAa,eAAe;AAC9C,aAAO;AAGT,QAAI,aAAa,IAAI;AACnB,YAAM,SAAS,IAAI,UAAU,GAAG,UAAU;AAC1C,YAAM,gBAAgB,IAAI,MAAM,kBAAkB;AAElD,eAAS,OAAO,MAAM,EAAE,gBAAgB,cAAc,CAAC,IAAI,CAAC;AAC5D,UAAI,WAAW;AAAW,eAAO;AAAA,IACnC,OAAO;AACL,eAAS,OAAO,GAAG;AAAA,IACrB;AAAA,EACF;AACA,SAAO;AACT;AAEA,IAAM,wBAAwB,CAAC,UAAgC;AAC7D,QAAM,EAAE,MAAM,GAAG,IAAI;AAErB,QAAM,CAAC,gBAAgB,iBAAiB,QAAI,uBAAS,EAAE;AACvD,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,IAAI;AAEjD,QAAM,kBAA8D,CAAC,MAAM;AACzE,sBAAkB,EAAE,OAAO,KAAK;AAEhC,UAAM,SAA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hC,IAEA,6BAAAA,QAAA,cAAC,0BAAK,mBAAiB,CAE3B;AAEJ;;;ACrHA,IAAAE,gBAAkB;AAClB,iBAKO;AAEP,kBAAqB;AACrB,wBAA2B;AAGpB,IAAMC,mBAAkB,CAC7B,UAIG;AACH,QAAM,EAAE,UAAU,SAAS,GAAG,KAAK,IAAI;AAEvC,SACE,8BAAAC,QAAA,cAAC,oBAAM,MAAK,oBAAoB,GAAG,QAChC,WAAW,8BAAAA,QAAA,cAAC,cAAS,MAAK,aAAW,QAAQ,QAAQ,CAAE,GACvD,QACH;AAEJ;AAEA,IAAM,iBAAiB,CAAC,UAA6C;AACnE,SACE,8BAAAA,QAAA,cAAC,oCACC,8BAAAA,QAAA,cAAC,6BAAW,QAAX,MAAmB,MAAM,QAAS,CACrC;AAEJ;AAEAD,iBAAgB,YAAQ,uBAAW;AAAA,EACjC,MAAM;AAAA,EACN,UAAU;AAAA,EACV;AAAA,EACA,SAAS;AAAA,EACT,aAAa;AACf,CAAC;;;ACpCM,IAAM,2BAGT,CAAC,OAAO,YAAY;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MACE,MAAM,YAAY,SACd,SACA,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC;AAAA,EACT;AACF;","names":["ObjectInspector","import_react","React","ObjectorInspectorDS","import_react","ObjectInspector","React"]}
|
package/dist/index.legacy-esm.js
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
1
|
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/components/ObjectInspectorComponent.tsx
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { Text } from "@chakra-ui/react";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import { Text, Input } from "@chakra-ui/react";
|
|
4
4
|
import { ObjectInspector as ObjectorInspectorDS } from "@devtools-ds/object-inspector";
|
|
5
5
|
import { ReactAsset } from "@player-ui/react";
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
var isObject = (value) => {
|
|
7
|
+
return value != null && (value.constructor === Object || !value.constructor && typeof value === "object" || Array.isArray(value));
|
|
8
|
+
};
|
|
9
|
+
var getPathvalue = (object, path) => {
|
|
10
|
+
const keys = path.split(".");
|
|
11
|
+
let result = object;
|
|
12
|
+
for (const key of keys) {
|
|
13
|
+
const arrayIndex = key.search(/\[\d+\]$/);
|
|
14
|
+
if (result[key] === void 0 && arrayIndex === -1)
|
|
15
|
+
return "No result for the given path";
|
|
16
|
+
if (arrayIndex > -1) {
|
|
17
|
+
const subkey = key.substring(0, arrayIndex);
|
|
18
|
+
const subIndexMatch = key.match(/(?<=\[)\d+(?=\])/);
|
|
19
|
+
result = result[subkey][subIndexMatch ? subIndexMatch[0] : 0];
|
|
20
|
+
if (result === void 0)
|
|
21
|
+
return "No result for the given index";
|
|
22
|
+
} else {
|
|
23
|
+
result = result[key];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
var FilterObjectInspector = (props) => {
|
|
29
|
+
const { data, id } = props;
|
|
30
|
+
const [filterCriteria, setFilterCriteria] = useState("");
|
|
31
|
+
const [resultData, setResultData] = useState(data);
|
|
32
|
+
const onChangeHandler = (e) => {
|
|
33
|
+
setFilterCriteria(e.target.value);
|
|
34
|
+
const result = getPathvalue(data, e.target.value);
|
|
35
|
+
setResultData(e.target.value.length ? result : data);
|
|
36
|
+
};
|
|
37
|
+
return /* @__PURE__ */ React.createElement("div", { style: { margin: "16px" } }, /* @__PURE__ */ React.createElement(
|
|
38
|
+
Input,
|
|
39
|
+
{
|
|
40
|
+
placeholder: "Search path...",
|
|
41
|
+
value: filterCriteria,
|
|
42
|
+
onChange: onChangeHandler
|
|
43
|
+
}
|
|
44
|
+
), /* @__PURE__ */ React.createElement(
|
|
45
|
+
"div",
|
|
46
|
+
{
|
|
47
|
+
style: {
|
|
48
|
+
border: "1px solid #e0e0e0",
|
|
49
|
+
borderRadius: "8px",
|
|
50
|
+
padding: "8px"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
!isObject(resultData) ? /* @__PURE__ */ React.createElement(Text, { style: { padding: "0 16px", color: "#EE8956" } }, resultData) : null,
|
|
54
|
+
isObject(resultData) ? /* @__PURE__ */ React.createElement(
|
|
55
|
+
ObjectorInspectorDS,
|
|
56
|
+
{
|
|
57
|
+
data: resultData,
|
|
58
|
+
includePrototypes: false,
|
|
59
|
+
expandLevel: 3,
|
|
60
|
+
id: `filter-${id}`
|
|
61
|
+
}
|
|
62
|
+
) : null
|
|
63
|
+
));
|
|
64
|
+
};
|
|
65
|
+
var ObjectInspector = (props) => {
|
|
66
|
+
const { data, id } = props;
|
|
67
|
+
return /* @__PURE__ */ React.createElement(
|
|
9
68
|
ObjectorInspectorDS,
|
|
10
69
|
{
|
|
11
70
|
data,
|
|
@@ -13,7 +72,11 @@ var ObjectInspectorComponent = (props) => {
|
|
|
13
72
|
expandLevel: 7,
|
|
14
73
|
id
|
|
15
74
|
}
|
|
16
|
-
)
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
var ObjectInspectorComponent = (props) => {
|
|
78
|
+
const { filter, data, label } = props;
|
|
79
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, label && /* @__PURE__ */ React.createElement(ReactAsset, { ...label }), data ? /* @__PURE__ */ React.createElement(React.Fragment, null, filter ? /* @__PURE__ */ React.createElement(FilterObjectInspector, { ...props }) : /* @__PURE__ */ React.createElement(ObjectInspector, { ...props })) : /* @__PURE__ */ React.createElement(Text, null, "No data available"));
|
|
17
80
|
};
|
|
18
81
|
|
|
19
82
|
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/dsl/ObjectInspector.tsx
|
|
@@ -24,14 +87,14 @@ import {
|
|
|
24
87
|
} from "@player-tools/dsl";
|
|
25
88
|
import { Text as Text2 } from "@devtools-ui/text";
|
|
26
89
|
import { Collection } from "@devtools-ui/collection";
|
|
27
|
-
var
|
|
90
|
+
var ObjectInspector2 = (props) => {
|
|
28
91
|
const { children, binding, ...rest } = props;
|
|
29
92
|
return /* @__PURE__ */ React2.createElement(Asset, { type: "object-inspector", ...rest }, binding && /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()), children);
|
|
30
93
|
};
|
|
31
94
|
var CollectionComp = (props) => {
|
|
32
95
|
return /* @__PURE__ */ React2.createElement(Collection, null, /* @__PURE__ */ React2.createElement(Collection.Values, null, props.children));
|
|
33
96
|
};
|
|
34
|
-
|
|
97
|
+
ObjectInspector2.Label = createSlot({
|
|
35
98
|
name: "label",
|
|
36
99
|
TextComp: Text2,
|
|
37
100
|
CollectionComp,
|
|
@@ -50,7 +113,7 @@ var objectInspectorTransform = (asset, options) => {
|
|
|
50
113
|
};
|
|
51
114
|
};
|
|
52
115
|
export {
|
|
53
|
-
ObjectInspector,
|
|
116
|
+
ObjectInspector2 as ObjectInspector,
|
|
54
117
|
ObjectInspectorComponent,
|
|
55
118
|
objectInspectorTransform
|
|
56
119
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
1
|
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/components/ObjectInspectorComponent.tsx
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { Text } from "@chakra-ui/react";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import { Text, Input } from "@chakra-ui/react";
|
|
4
4
|
import { ObjectInspector as ObjectorInspectorDS } from "@devtools-ds/object-inspector";
|
|
5
5
|
import { ReactAsset } from "@player-ui/react";
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
var isObject = (value) => {
|
|
7
|
+
return value != null && (value.constructor === Object || !value.constructor && typeof value === "object" || Array.isArray(value));
|
|
8
|
+
};
|
|
9
|
+
var getPathvalue = (object, path) => {
|
|
10
|
+
const keys = path.split(".");
|
|
11
|
+
let result = object;
|
|
12
|
+
for (const key of keys) {
|
|
13
|
+
const arrayIndex = key.search(/\[\d+\]$/);
|
|
14
|
+
if (result[key] === void 0 && arrayIndex === -1)
|
|
15
|
+
return "No result for the given path";
|
|
16
|
+
if (arrayIndex > -1) {
|
|
17
|
+
const subkey = key.substring(0, arrayIndex);
|
|
18
|
+
const subIndexMatch = key.match(/(?<=\[)\d+(?=\])/);
|
|
19
|
+
result = result[subkey][subIndexMatch ? subIndexMatch[0] : 0];
|
|
20
|
+
if (result === void 0)
|
|
21
|
+
return "No result for the given index";
|
|
22
|
+
} else {
|
|
23
|
+
result = result[key];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
var FilterObjectInspector = (props) => {
|
|
29
|
+
const { data, id } = props;
|
|
30
|
+
const [filterCriteria, setFilterCriteria] = useState("");
|
|
31
|
+
const [resultData, setResultData] = useState(data);
|
|
32
|
+
const onChangeHandler = (e) => {
|
|
33
|
+
setFilterCriteria(e.target.value);
|
|
34
|
+
const result = getPathvalue(data, e.target.value);
|
|
35
|
+
setResultData(e.target.value.length ? result : data);
|
|
36
|
+
};
|
|
37
|
+
return /* @__PURE__ */ React.createElement("div", { style: { margin: "16px" } }, /* @__PURE__ */ React.createElement(
|
|
38
|
+
Input,
|
|
39
|
+
{
|
|
40
|
+
placeholder: "Search path...",
|
|
41
|
+
value: filterCriteria,
|
|
42
|
+
onChange: onChangeHandler
|
|
43
|
+
}
|
|
44
|
+
), /* @__PURE__ */ React.createElement(
|
|
45
|
+
"div",
|
|
46
|
+
{
|
|
47
|
+
style: {
|
|
48
|
+
border: "1px solid #e0e0e0",
|
|
49
|
+
borderRadius: "8px",
|
|
50
|
+
padding: "8px"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
!isObject(resultData) ? /* @__PURE__ */ React.createElement(Text, { style: { padding: "0 16px", color: "#EE8956" } }, resultData) : null,
|
|
54
|
+
isObject(resultData) ? /* @__PURE__ */ React.createElement(
|
|
55
|
+
ObjectorInspectorDS,
|
|
56
|
+
{
|
|
57
|
+
data: resultData,
|
|
58
|
+
includePrototypes: false,
|
|
59
|
+
expandLevel: 3,
|
|
60
|
+
id: `filter-${id}`
|
|
61
|
+
}
|
|
62
|
+
) : null
|
|
63
|
+
));
|
|
64
|
+
};
|
|
65
|
+
var ObjectInspector = (props) => {
|
|
66
|
+
const { data, id } = props;
|
|
67
|
+
return /* @__PURE__ */ React.createElement(
|
|
9
68
|
ObjectorInspectorDS,
|
|
10
69
|
{
|
|
11
70
|
data,
|
|
@@ -13,7 +72,11 @@ var ObjectInspectorComponent = (props) => {
|
|
|
13
72
|
expandLevel: 7,
|
|
14
73
|
id
|
|
15
74
|
}
|
|
16
|
-
)
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
var ObjectInspectorComponent = (props) => {
|
|
78
|
+
const { filter, data, label } = props;
|
|
79
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, label && /* @__PURE__ */ React.createElement(ReactAsset, { ...label }), data ? /* @__PURE__ */ React.createElement(React.Fragment, null, filter ? /* @__PURE__ */ React.createElement(FilterObjectInspector, { ...props }) : /* @__PURE__ */ React.createElement(ObjectInspector, { ...props })) : /* @__PURE__ */ React.createElement(Text, null, "No data available"));
|
|
17
80
|
};
|
|
18
81
|
|
|
19
82
|
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/dsl/ObjectInspector.tsx
|
|
@@ -24,14 +87,14 @@ import {
|
|
|
24
87
|
} from "@player-tools/dsl";
|
|
25
88
|
import { Text as Text2 } from "@devtools-ui/text";
|
|
26
89
|
import { Collection } from "@devtools-ui/collection";
|
|
27
|
-
var
|
|
90
|
+
var ObjectInspector2 = (props) => {
|
|
28
91
|
const { children, binding, ...rest } = props;
|
|
29
92
|
return /* @__PURE__ */ React2.createElement(Asset, { type: "object-inspector", ...rest }, binding && /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()), children);
|
|
30
93
|
};
|
|
31
94
|
var CollectionComp = (props) => {
|
|
32
95
|
return /* @__PURE__ */ React2.createElement(Collection, null, /* @__PURE__ */ React2.createElement(Collection.Values, null, props.children));
|
|
33
96
|
};
|
|
34
|
-
|
|
97
|
+
ObjectInspector2.Label = createSlot({
|
|
35
98
|
name: "label",
|
|
36
99
|
TextComp: Text2,
|
|
37
100
|
CollectionComp,
|
|
@@ -50,7 +113,7 @@ var objectInspectorTransform = (asset, options) => {
|
|
|
50
113
|
};
|
|
51
114
|
};
|
|
52
115
|
export {
|
|
53
|
-
ObjectInspector,
|
|
116
|
+
ObjectInspector2 as ObjectInspector,
|
|
54
117
|
ObjectInspectorComponent,
|
|
55
118
|
objectInspectorTransform
|
|
56
119
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/components/ObjectInspectorComponent.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/dsl/ObjectInspector.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/transformer/index.ts"],"sourcesContent":["import React from \"react\";\nimport { Text } from \"@chakra-ui/react\";\nimport { ObjectInspector as ObjectorInspectorDS } from \"@devtools-ds/object-inspector\";\nimport { ReactAsset } from \"@player-ui/react\";\nimport { ObjectInspectorAsset } from \"../types\";\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/components/ObjectInspectorComponent.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/dsl/ObjectInspector.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/object-inspector/src/transformer/index.ts"],"sourcesContent":["import React, { useState } from \"react\";\nimport { Text, Input } from \"@chakra-ui/react\";\nimport { ObjectInspector as ObjectorInspectorDS } from \"@devtools-ds/object-inspector\";\nimport { ReactAsset } from \"@player-ui/react\";\nimport { Flow } from \"@player-ui/types\";\nimport { ObjectInspectorAsset } from \"../types\";\n\nexport const isObject = (value: any): boolean => {\n return (\n value != null &&\n (value.constructor === Object ||\n (!value.constructor && typeof value === \"object\") ||\n Array.isArray(value))\n );\n};\n\nexport const getPathvalue = (object: object, path: string) => {\n const keys = path.split(\".\");\n let result: any = object;\n for (const key of keys) {\n const arrayIndex = key.search(/\\[\\d+\\]$/);\n\n if (result[key] === undefined && arrayIndex === -1)\n return \"No result for the given path\";\n\n // If key has a numeric index, e.g. for Multi-copy and/or array values.\n if (arrayIndex > -1) {\n const subkey = key.substring(0, arrayIndex);\n const subIndexMatch = key.match(/(?<=\\[)\\d+(?=\\])/);\n\n result = result[subkey][subIndexMatch ? subIndexMatch[0] : 0];\n if (result === undefined) return \"No result for the given index\";\n } else {\n result = result[key];\n }\n }\n return result;\n};\n\nconst FilterObjectInspector = (props: ObjectInspectorAsset) => {\n const { data, id } = props;\n\n const [filterCriteria, setFilterCriteria] = useState(\"\");\n const [resultData, setResultData] = useState(data);\n\n const onChangeHandler: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setFilterCriteria(e.target.value);\n\n const result = getPathvalue(data as Flow, e.target.value);\n setResultData(e.target.value.length ? result : data);\n };\n\n return (\n <div style={{ margin: \"16px\" }}>\n <Input\n placeholder=\"Search path...\"\n value={filterCriteria}\n onChange={onChangeHandler}\n />\n <div\n style={{\n border: \"1px solid #e0e0e0\",\n borderRadius: \"8px\",\n padding: \"8px\",\n }}\n >\n {!isObject(resultData) ? (\n <Text style={{ padding: \"0 16px\", color: \"#EE8956\" }}>\n {resultData as any}\n </Text>\n ) : null}\n\n {isObject(resultData) ? (\n <ObjectorInspectorDS\n data={resultData as Flow}\n includePrototypes={false}\n expandLevel={3}\n id={`filter-${id}`}\n />\n ) : null}\n </div>\n </div>\n );\n};\n\nconst ObjectInspector = (props: ObjectInspectorAsset) => {\n const { data, id } = props;\n\n return (\n <ObjectorInspectorDS\n data={data as Flow}\n includePrototypes={false}\n expandLevel={7}\n id={id}\n />\n );\n};\n\nexport const ObjectInspectorComponent = (props: ObjectInspectorAsset) => {\n const { filter, data, label } = props;\n\n return (\n <>\n {label && <ReactAsset {...label} />}\n {data ? (\n <>\n {filter ? (\n <FilterObjectInspector {...props} />\n ) : (\n <ObjectInspector {...props} />\n )}\n </>\n ) : (\n <Text>No data available</Text>\n )}\n </>\n );\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n createSlot,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { Asset as AssetType } from \"@player-ui/player\";\nimport { Text } from \"@devtools-ui/text\";\nimport { Collection } from \"@devtools-ui/collection\";\nimport type { ObjectInspectorAsset } from \"../types\";\n\nexport const ObjectInspector = (\n props: Omit<AssetPropsWithChildren<ObjectInspectorAsset>, \"binding\"> & {\n /** The binding */\n binding?: BindingTemplateInstance;\n }\n) => {\n const { children, binding, ...rest } = props;\n\n return (\n <Asset type=\"object-inspector\" {...rest}>\n {binding && <property name=\"binding\">{binding.toValue()}</property>}\n {children}\n </Asset>\n );\n};\n\nconst CollectionComp = (props: AssetPropsWithChildren<AssetType>) => {\n return (\n <Collection>\n <Collection.Values>{props.children}</Collection.Values>\n </Collection>\n );\n};\n\nObjectInspector.Label = createSlot({\n name: \"label\",\n TextComp: Text,\n CollectionComp,\n isArray: false,\n wrapInAsset: true,\n});\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { ObjectInspectorAsset, TransformedObjectInspector } from \"../types\";\n\n/**\n * Access the object from the data model\n */\nexport const objectInspectorTransform: TransformFunction<\n ObjectInspectorAsset,\n TransformedObjectInspector\n> = (asset, options) => {\n return {\n ...asset,\n data:\n asset.binding === undefined\n ? undefined\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: false,\n }),\n };\n};\n"],"mappings":";AAAA,OAAO,SAAS,gBAAgB;AACh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,MAAmB,MAAM,QAAS,CACrC;AAEJ;AAEAE,iBAAgB,QAAQ,WAAW;AAAA,EACjC,MAAM;AAAA,EACN,UAAUD;AAAA,EACV;AAAA,EACA,SAAS;AAAA,EACT,aAAa;AACf,CAAC;;;ACpCM,IAAM,2BAGT,CAAC,OAAO,YAAY;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MACE,MAAM,YAAY,SACd,SACA,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC;AAAA,EACT;AACF;","names":["React","Text","ObjectInspector"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtools-ui/object-inspector",
|
|
3
|
-
"version": "0.2.0",
|
|
3
|
+
"version": "0.2.1-next.0",
|
|
4
4
|
"main": "dist/cjs/index.cjs",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@devtools-ui/collection": "0.2.0",
|
|
7
|
-
"@devtools-ui/text": "0.2.0",
|
|
6
|
+
"@devtools-ui/collection": "0.2.1-next.0",
|
|
7
|
+
"@devtools-ui/text": "0.2.1-next.0",
|
|
8
8
|
"@types/react": "^18.2.51",
|
|
9
9
|
"react": "^18.2.0",
|
|
10
10
|
"@devtools-ds/object-inspector": "^1.1.2",
|
|
@@ -1,22 +1,115 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Text } from "@chakra-ui/react";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Text, Input } from "@chakra-ui/react";
|
|
3
3
|
import { ObjectInspector as ObjectorInspectorDS } from "@devtools-ds/object-inspector";
|
|
4
4
|
import { ReactAsset } from "@player-ui/react";
|
|
5
|
+
import { Flow } from "@player-ui/types";
|
|
5
6
|
import { ObjectInspectorAsset } from "../types";
|
|
6
7
|
|
|
8
|
+
export const isObject = (value: any): boolean => {
|
|
9
|
+
return (
|
|
10
|
+
value != null &&
|
|
11
|
+
(value.constructor === Object ||
|
|
12
|
+
(!value.constructor && typeof value === "object") ||
|
|
13
|
+
Array.isArray(value))
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const getPathvalue = (object: object, path: string) => {
|
|
18
|
+
const keys = path.split(".");
|
|
19
|
+
let result: any = object;
|
|
20
|
+
for (const key of keys) {
|
|
21
|
+
const arrayIndex = key.search(/\[\d+\]$/);
|
|
22
|
+
|
|
23
|
+
if (result[key] === undefined && arrayIndex === -1)
|
|
24
|
+
return "No result for the given path";
|
|
25
|
+
|
|
26
|
+
// If key has a numeric index, e.g. for Multi-copy and/or array values.
|
|
27
|
+
if (arrayIndex > -1) {
|
|
28
|
+
const subkey = key.substring(0, arrayIndex);
|
|
29
|
+
const subIndexMatch = key.match(/(?<=\[)\d+(?=\])/);
|
|
30
|
+
|
|
31
|
+
result = result[subkey][subIndexMatch ? subIndexMatch[0] : 0];
|
|
32
|
+
if (result === undefined) return "No result for the given index";
|
|
33
|
+
} else {
|
|
34
|
+
result = result[key];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const FilterObjectInspector = (props: ObjectInspectorAsset) => {
|
|
41
|
+
const { data, id } = props;
|
|
42
|
+
|
|
43
|
+
const [filterCriteria, setFilterCriteria] = useState("");
|
|
44
|
+
const [resultData, setResultData] = useState(data);
|
|
45
|
+
|
|
46
|
+
const onChangeHandler: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
|
47
|
+
setFilterCriteria(e.target.value);
|
|
48
|
+
|
|
49
|
+
const result = getPathvalue(data as Flow, e.target.value);
|
|
50
|
+
setResultData(e.target.value.length ? result : data);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div style={{ margin: "16px" }}>
|
|
55
|
+
<Input
|
|
56
|
+
placeholder="Search path..."
|
|
57
|
+
value={filterCriteria}
|
|
58
|
+
onChange={onChangeHandler}
|
|
59
|
+
/>
|
|
60
|
+
<div
|
|
61
|
+
style={{
|
|
62
|
+
border: "1px solid #e0e0e0",
|
|
63
|
+
borderRadius: "8px",
|
|
64
|
+
padding: "8px",
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
{!isObject(resultData) ? (
|
|
68
|
+
<Text style={{ padding: "0 16px", color: "#EE8956" }}>
|
|
69
|
+
{resultData as any}
|
|
70
|
+
</Text>
|
|
71
|
+
) : null}
|
|
72
|
+
|
|
73
|
+
{isObject(resultData) ? (
|
|
74
|
+
<ObjectorInspectorDS
|
|
75
|
+
data={resultData as Flow}
|
|
76
|
+
includePrototypes={false}
|
|
77
|
+
expandLevel={3}
|
|
78
|
+
id={`filter-${id}`}
|
|
79
|
+
/>
|
|
80
|
+
) : null}
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const ObjectInspector = (props: ObjectInspectorAsset) => {
|
|
87
|
+
const { data, id } = props;
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<ObjectorInspectorDS
|
|
91
|
+
data={data as Flow}
|
|
92
|
+
includePrototypes={false}
|
|
93
|
+
expandLevel={7}
|
|
94
|
+
id={id}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
7
99
|
export const ObjectInspectorComponent = (props: ObjectInspectorAsset) => {
|
|
8
|
-
const { data, label
|
|
100
|
+
const { filter, data, label } = props;
|
|
9
101
|
|
|
10
102
|
return (
|
|
11
103
|
<>
|
|
12
104
|
{label && <ReactAsset {...label} />}
|
|
13
105
|
{data ? (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
106
|
+
<>
|
|
107
|
+
{filter ? (
|
|
108
|
+
<FilterObjectInspector {...props} />
|
|
109
|
+
) : (
|
|
110
|
+
<ObjectInspector {...props} />
|
|
111
|
+
)}
|
|
112
|
+
</>
|
|
20
113
|
) : (
|
|
21
114
|
<Text>No data available</Text>
|
|
22
115
|
)}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, test } from "vitest";
|
|
4
|
+
import { ObjectInspectorComponent } from "../index";
|
|
5
|
+
import { TransformedObjectInspector } from "../../types";
|
|
6
|
+
|
|
7
|
+
describe("ObjectInspectorComponent test", () => {
|
|
8
|
+
const objectInspectorAssetPropsMock: TransformedObjectInspector = {
|
|
9
|
+
id: "default-objectIns",
|
|
10
|
+
type: "object-inspector",
|
|
11
|
+
data: { test: "test", b: { foo: "bar", arr: [{ prop1: "Arr prop" }] } },
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const objectInspectorAssetFilterPropsMock: TransformedObjectInspector = {
|
|
15
|
+
...objectInspectorAssetPropsMock,
|
|
16
|
+
id: "filterObjIns",
|
|
17
|
+
filter: true,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
test("Renders default ObjectInspector asset", async () => {
|
|
21
|
+
const { findByText } = render(
|
|
22
|
+
<ObjectInspectorComponent {...objectInspectorAssetPropsMock} />
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const testText = await findByText("test");
|
|
26
|
+
|
|
27
|
+
expect(testText).toBeDefined();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("Testing Object Inspecor with filter", () => {
|
|
31
|
+
test("Renders default ObjectInspector asset with filter", async () => {
|
|
32
|
+
const { findByPlaceholderText, findByText } = render(
|
|
33
|
+
<ObjectInspectorComponent {...objectInspectorAssetPropsMock} filter />
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const filterInput = await findByPlaceholderText("Search path...");
|
|
37
|
+
|
|
38
|
+
const leafText = await findByText('"bar"');
|
|
39
|
+
|
|
40
|
+
expect(filterInput).toBeDefined();
|
|
41
|
+
expect(leafText).toBeDefined();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("Filters data tree on path", async () => {
|
|
45
|
+
const { container, findByPlaceholderText, findByText, queryByText } =
|
|
46
|
+
render(
|
|
47
|
+
<ObjectInspectorComponent {...objectInspectorAssetFilterPropsMock} />
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
await findByPlaceholderText("Search path...");
|
|
51
|
+
|
|
52
|
+
const FilterInput = container.querySelector("input") as HTMLInputElement;
|
|
53
|
+
|
|
54
|
+
fireEvent.change(FilterInput, { target: { value: "b.foo" } });
|
|
55
|
+
|
|
56
|
+
const fooText = await findByText("bar");
|
|
57
|
+
const testText = queryByText("test");
|
|
58
|
+
|
|
59
|
+
expect(fooText).toBeDefined();
|
|
60
|
+
expect(testText).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("Filters data tree on path with array index", async () => {
|
|
64
|
+
const { container, findByPlaceholderText, findByText, queryByText } =
|
|
65
|
+
render(
|
|
66
|
+
<ObjectInspectorComponent {...objectInspectorAssetFilterPropsMock} />
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
await findByPlaceholderText("Search path...");
|
|
70
|
+
|
|
71
|
+
const FilterInput = container.querySelector("input") as HTMLInputElement;
|
|
72
|
+
|
|
73
|
+
fireEvent.change(FilterInput, { target: { value: "b.arr[0]" } });
|
|
74
|
+
|
|
75
|
+
const fooText = await findByText("prop1");
|
|
76
|
+
const testText = queryByText("test");
|
|
77
|
+
|
|
78
|
+
expect(fooText).toBeDefined();
|
|
79
|
+
expect(testText).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("Shows 'no path result' message", async () => {
|
|
83
|
+
const { container, findByPlaceholderText, findByText, queryByText } =
|
|
84
|
+
render(
|
|
85
|
+
<ObjectInspectorComponent {...objectInspectorAssetFilterPropsMock} />
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
await findByPlaceholderText("Search path...");
|
|
89
|
+
|
|
90
|
+
const FilterInput = container.querySelector("input") as HTMLInputElement;
|
|
91
|
+
|
|
92
|
+
fireEvent.change(FilterInput, { target: { value: "whatever" } });
|
|
93
|
+
|
|
94
|
+
const noResultText = await findByText("No result for the given path");
|
|
95
|
+
|
|
96
|
+
expect(noResultText).toBeDefined();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("Shows 'no given index found' message", async () => {
|
|
100
|
+
const { container, findByPlaceholderText, findByText, queryByText } =
|
|
101
|
+
render(
|
|
102
|
+
<ObjectInspectorComponent {...objectInspectorAssetFilterPropsMock} />
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
await findByPlaceholderText("Search path...");
|
|
106
|
+
|
|
107
|
+
const FilterInput = container.querySelector("input") as HTMLInputElement;
|
|
108
|
+
|
|
109
|
+
fireEvent.change(FilterInput, { target: { value: "b.arr[1]" } });
|
|
110
|
+
|
|
111
|
+
const noResultIndexText = await findByText(
|
|
112
|
+
"No result for the given index"
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
expect(noResultIndexText).toBeDefined();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { isObject, getPathvalue } from "../ObjectInspectorComponent";
|
|
3
|
+
|
|
4
|
+
describe("Testing the isObject pure utility function", () => {
|
|
5
|
+
test("It verifies correct item values as objects", () => {
|
|
6
|
+
expect(isObject({ some: "prop" })).toBe(true);
|
|
7
|
+
expect(isObject([{ arr: "prop" }])).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
test("It verifies incorrect item values as no objects", () => {
|
|
10
|
+
expect(isObject("prop")).toBe(false);
|
|
11
|
+
expect(isObject(20)).toBe(false);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("Testing the getPathvalue pure utility function", () => {
|
|
16
|
+
const testObject = {
|
|
17
|
+
mainProp: "Some value",
|
|
18
|
+
arrProp: [
|
|
19
|
+
{
|
|
20
|
+
someProp: "foo",
|
|
21
|
+
booleanProp: "false",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
test("It verifies regular path in object", () => {
|
|
26
|
+
expect(getPathvalue(testObject, "mainProp")).toBe(testObject.mainProp);
|
|
27
|
+
expect(getPathvalue(testObject, "something")).toBe(
|
|
28
|
+
"No result for the given path"
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
test("It verifies path with array index", () => {
|
|
32
|
+
expect(getPathvalue(testObject, "arrProp[0].someProp")).toBe("foo");
|
|
33
|
+
expect(getPathvalue(testObject, "arrProp[1].someProp")).toBe(
|
|
34
|
+
"No result for the given index"
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -24,4 +24,26 @@ describe("DSL: Object Inspector", () => {
|
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
|
+
|
|
28
|
+
test("with filter", async () => {
|
|
29
|
+
const rendered = await render(
|
|
30
|
+
<ObjectInspector binding={b`foo`} filter>
|
|
31
|
+
<ObjectInspector.Label>With Filter</ObjectInspector.Label>
|
|
32
|
+
</ObjectInspector>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(rendered.jsonValue).toStrictEqual({
|
|
36
|
+
id: "root",
|
|
37
|
+
type: "object-inspector",
|
|
38
|
+
binding: "foo",
|
|
39
|
+
filter: true,
|
|
40
|
+
label: {
|
|
41
|
+
asset: {
|
|
42
|
+
id: "label",
|
|
43
|
+
type: "text",
|
|
44
|
+
value: "With Filter",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
});
|
|
27
49
|
});
|
package/src/types/index.ts
CHANGED
|
@@ -7,6 +7,9 @@ export interface ObjectInspectorAsset<AnyTextAsset extends Asset = Asset>
|
|
|
7
7
|
|
|
8
8
|
/** A text-like asset for the action's label */
|
|
9
9
|
label?: AssetWrapper<AnyTextAsset>;
|
|
10
|
+
|
|
11
|
+
/** Flag if a path-to-prop filter is to get included */
|
|
12
|
+
filter?: boolean;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
export interface TransformedObjectInspector extends ObjectInspectorAsset {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ObjectInspectorAsset } from "../types";
|
|
3
|
+
export declare const isObject: (value: any) => boolean;
|
|
4
|
+
export declare const getPathvalue: (object: object, path: string) => any;
|
|
3
5
|
export declare const ObjectInspectorComponent: (props: ObjectInspectorAsset) => React.JSX.Element;
|
|
4
6
|
//# sourceMappingURL=ObjectInspectorComponent.d.ts.map
|
package/types/types/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export interface ObjectInspectorAsset<AnyTextAsset extends Asset = Asset> extend
|
|
|
4
4
|
binding?: string;
|
|
5
5
|
/** A text-like asset for the action's label */
|
|
6
6
|
label?: AssetWrapper<AnyTextAsset>;
|
|
7
|
+
/** Flag if a path-to-prop filter is to get included */
|
|
8
|
+
filter?: boolean;
|
|
7
9
|
}
|
|
8
10
|
export interface TransformedObjectInspector extends ObjectInspectorAsset {
|
|
9
11
|
/** A stateful instance of an action */
|