-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.tsx
108 lines (96 loc) · 2.07 KB
/
schema.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React, { useState } from "react";
import Editor from "@monaco-editor/react";
import Select from "react-select";
import * as AtlasHCL from "../../lib";
const styles = {
container: {
display: "flex",
justifyContent: "center",
},
title: {
padding: 20,
fontSize: "x-large",
},
select: {
control: (provided) => ({
...provided,
width: "fit-content",
marginTop: 15,
}),
},
};
const languages = [
{ value: AtlasHCL.langIds.schema.sqlite, label: "sqlite" },
{ value: AtlasHCL.langIds.schema.mysql, label: "mysql" },
{ value: AtlasHCL.langIds.schema.postgresql, label: "postgresql" },
];
function HCLSchemaEditor() {
const [selectedOption, setSelectedOption] = useState(languages[0]);
const handleChange = (option) => {
setSelectedOption(option);
};
function handleEditorDidMount(editor, monaco) {
AtlasHCL.AutoRegister(monaco);
AtlasHCL.ConnectEditor(monaco, editor);
}
const text = `
/*
SQL RESOURCES
*/
table "logs" {
schema = schema.public
column "date" {
type = date
}
column "text" {
type = integer
}
partition {
type = RANGE
columns = [column.date]
}
}
table "metrics" {
schema = schema.public
column "x" {
type = integer
}
column "y" {
type = integer
}
partition {
type = RANGE
by {
column = column.x
}
by {
expr = "floor(y)"
}
}
}
`;
return (
<div>
<div style={styles.container}>
<div style={styles.title}>AtlasHCL Schema</div>
<Select
styles={styles.select}
options={languages}
value={selectedOption}
onChange={handleChange}
/>
</div>
<Editor
height="90vh"
language={selectedOption.value}
defaultLanguage={languages[0].value}
defaultValue={text}
onMount={handleEditorDidMount}
options={{
wordBasedSuggestions: false,
}}
/>
</div>
);
}
export default HCLSchemaEditor;