Skip to content

Commit a074508

Browse files
author
Ryan Sites
authored
Feature/include types (#8)
* bump version * refactor to include typescript.types exported
1 parent baec883 commit a074508

File tree

18 files changed

+1537
-1525
lines changed

18 files changed

+1537
-1525
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "@optum/json-schema-editor",
3-
"version": "2.0.1",
3+
"version": "2.0.3",
44
"description": "JsonSchema Editor React Control",
55
"repository": "https://github.com/optum/jsonschema-editor-react",
66
"license": "Apache 2.0",
77
"engines": {
88
"node": ">=10.18.0 <11 || >=12.14.0 <13 || >=13.5.0"
99
},
10-
"source": "src/JsonSchemaEditor/index.ts",
10+
"source": "src/index.ts",
1111
"publishConfig": {
1212
"access": "public",
1313
"registry": "https://registry.npmjs.org"

src/JsonSchemaEditor.test.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
import React from "react";
22
import { render } from "@testing-library/react";
33

4-
import JsonSchemaEditor from "./JsonSchemaEditor";
5-
import { SchemaEditorProps } from "./JsonSchemaEditor/JsonSchemaEditor.types";
4+
import JsonSchemaEditor from ".";
5+
import { SchemaEditorProps } from "./JsonSchemaEditor.types";
66

77
const printIt = (schema: string) => {
8-
console.log(schema);
8+
console.log(schema);
99
};
1010

1111
describe("JsonSchemaEditor", () => {
12-
let props: SchemaEditorProps;
12+
let props: SchemaEditorProps;
1313

14-
beforeEach(() => {
15-
props = {
16-
onSchemaChange: printIt,
17-
};
18-
});
14+
beforeEach(() => {
15+
props = {
16+
onSchemaChange: printIt,
17+
};
18+
});
1919

20-
const renderComponent = () => render(<JsonSchemaEditor {...props} />);
20+
const renderComponent = () => render(<JsonSchemaEditor {...props} />);
2121

22-
it("should have primary className with default props", () => {
23-
renderComponent();
22+
it("should have primary className with default props", () => {
23+
renderComponent();
2424

25-
const { container } = renderComponent();
25+
const { container } = renderComponent();
2626

27-
// const testComponent = getByTestId("jsonschema-editor");
28-
console.log(container.innerHTML);
27+
// const testComponent = getByTestId("jsonschema-editor");
28+
console.log(container.innerHTML);
2929

30-
// expect(testComponent).toHaveClass("test-component-primary");
30+
// expect(testComponent).toHaveClass("test-component-primary");
3131

32-
// console.log(result.asFragment.toString);
33-
// // expect(screen.getByText("root")).toBeInTheDocument();
34-
// expect(true).toBe(true);
35-
});
32+
// console.log(result.asFragment.toString);
33+
// // expect(screen.getByText("root")).toBeInTheDocument();
34+
// expect(true).toBe(true);
35+
});
3636
});
3737

3838
// test("renders learn react link", () => {
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
import * as React from "react";
22
import { useState } from "@hookstate/core";
33
import { useSchemaState, defaultSchema } from "./state";
4-
import { SchemaEditorProps } from "./JsonSchemaEditor.types";
4+
import { SchemaEditorProps } from "../JsonSchemaEditor.types";
55
import { Flex, ChakraProvider, theme } from "@chakra-ui/react";
66

77
import { SchemaRoot } from "./schema-root";
88
import { Whoops } from "./whoops";
99
import { SchemaObject } from "./schema-object";
1010
import { SchemaArray } from "./schema-array";
1111

12-
export * from "./JsonSchemaEditor.types";
12+
export * from "../JsonSchemaEditor.types";
1313

1414
export const JsonSchemaEditor = (props: SchemaEditorProps) => {
15-
const { onSchemaChange, readOnly, data } = props;
15+
const { onSchemaChange, readOnly, data } = props;
1616

17-
const schemaState = useSchemaState({
18-
jsonSchema: data ?? defaultSchema(),
19-
isReadOnly: readOnly ?? false,
20-
fieldId: 0,
21-
});
17+
const schemaState = useSchemaState({
18+
jsonSchema: data ?? defaultSchema(),
19+
isReadOnly: readOnly ?? false,
20+
fieldId: 0,
21+
});
2222

23-
const jsonSchemaState = useState(schemaState.jsonSchema);
23+
const jsonSchemaState = useState(schemaState.jsonSchema);
2424

25-
return (
26-
<ChakraProvider theme={theme}>
27-
{schemaState.isValidSchema ? (
28-
<Flex m={2} direction="column">
29-
<SchemaRoot
30-
onSchemaChange={onSchemaChange}
31-
schemaState={schemaState.jsonSchema}
32-
isReadOnly={schemaState.isReadOnly}
33-
/>
25+
return (
26+
<ChakraProvider theme={theme}>
27+
{schemaState.isValidSchema ? (
28+
<Flex m={2} direction="column">
29+
<SchemaRoot
30+
onSchemaChange={onSchemaChange}
31+
schemaState={schemaState.jsonSchema}
32+
isReadOnly={schemaState.isReadOnly}
33+
/>
3434

35-
{jsonSchemaState.type.value === "object" && (
36-
<SchemaObject
37-
schemaState={jsonSchemaState}
38-
isReadOnly={schemaState.isReadOnly ?? false}
39-
/>
40-
)}
35+
{jsonSchemaState.type.value === "object" && (
36+
<SchemaObject
37+
schemaState={jsonSchemaState}
38+
isReadOnly={schemaState.isReadOnly ?? false}
39+
/>
40+
)}
4141

42-
{jsonSchemaState.type.value === "array" && (
43-
<SchemaArray
44-
schemaState={jsonSchemaState}
45-
isReadOnly={schemaState.isReadOnly ?? false}
46-
/>
47-
)}
48-
</Flex>
49-
) : (
50-
<Flex alignContent="center" justifyContent="center">
51-
<Whoops />
52-
</Flex>
53-
)}
54-
{/* <Modal
42+
{jsonSchemaState.type.value === "array" && (
43+
<SchemaArray
44+
schemaState={jsonSchemaState}
45+
isReadOnly={schemaState.isReadOnly ?? false}
46+
/>
47+
)}
48+
</Flex>
49+
) : (
50+
<Flex alignContent="center" justifyContent="center">
51+
<Whoops />
52+
</Flex>
53+
)}
54+
{/* <Modal
5555
isOpen={localState.isAdvancedOpen.get()}
5656
finalFocusRef={focusRef}
5757
size="lg"
@@ -77,6 +77,6 @@ export const JsonSchemaEditor = (props: SchemaEditorProps) => {
7777
</ModalFooter>
7878
</ModalContent>
7979
</Modal> */}
80-
</ChakraProvider>
81-
);
80+
</ChakraProvider>
81+
);
8282
};
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
import * as React from "react";
22
import { Flex, FormLabel, Stack, Select } from "@chakra-ui/react";
33

4-
import { AdvancedItemStateProps } from "../JsonSchemaEditor.types";
4+
import { AdvancedItemStateProps } from "../../JsonSchemaEditor.types";
55
import { useState } from "@hookstate/core";
66

77
export const AdvancedBoolean: React.FunctionComponent<AdvancedItemStateProps> = (
8-
props: React.PropsWithChildren<AdvancedItemStateProps>
8+
props: React.PropsWithChildren<AdvancedItemStateProps>
99
) => {
10-
const { itemStateProp } = props;
10+
const { itemStateProp } = props;
1111

12-
const item = useState(itemStateProp);
12+
const item = useState(itemStateProp);
1313

14-
return (
15-
<Flex direction="column" wrap="nowrap">
16-
<Stack
17-
isInline
18-
alignItems="center"
19-
justifyContent="center"
20-
alignContent="center"
21-
m={1}
22-
>
23-
<FormLabel mr={2} htmlFor="default">
24-
Default:{" "}
25-
</FormLabel>
26-
<Select
27-
variant="outline"
28-
value={(item.default.value as string) ?? ""}
29-
size="sm"
30-
margin={2}
31-
placeholder="Choose data type"
32-
onChange={(evt: React.ChangeEvent<HTMLSelectElement>) => {
33-
item.default.set(evt.target.value);
34-
}}
35-
>
36-
<option key="true" value="true">
37-
true
38-
</option>
39-
<option key="false" value="false">
40-
false
41-
</option>
42-
</Select>
43-
</Stack>
44-
</Flex>
45-
);
14+
return (
15+
<Flex direction="column" wrap="nowrap">
16+
<Stack
17+
isInline
18+
alignItems="center"
19+
justifyContent="center"
20+
alignContent="center"
21+
m={1}
22+
>
23+
<FormLabel mr={2} htmlFor="default">
24+
Default:{" "}
25+
</FormLabel>
26+
<Select
27+
variant="outline"
28+
value={(item.default.value as string) ?? ""}
29+
size="sm"
30+
margin={2}
31+
placeholder="Choose data type"
32+
onChange={(evt: React.ChangeEvent<HTMLSelectElement>) => {
33+
item.default.set(evt.target.value);
34+
}}
35+
>
36+
<option key="true" value="true">
37+
true
38+
</option>
39+
<option key="false" value="false">
40+
false
41+
</option>
42+
</Select>
43+
</Stack>
44+
</Flex>
45+
);
4646
};

0 commit comments

Comments
 (0)