Skip to content

Commit 52529af

Browse files
committed
make component autocomplete add components to model
1 parent 04e61ae commit 52529af

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

frontend/app/components/Autocomplete.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22
import { Autocomplete } from "@mantine/core";
33
import { useEffect, useState } from "react";
44
import { visualizations } from "./visualizations/Visualizations";
5+
import { layoutModel } from "./FlexLayoutComponent";
6+
import { Actions, DockLocation } from "flexlayout-react";
57

68
const componentArray = Object.keys(visualizations);
79

810
export default function AutocompleteSearchbar() {
911
const [value, setValue] = useState("");
1012

1113
useEffect(() => {
12-
if (componentArray.includes(value)) console.log(value);
14+
if (componentArray.includes(value)) {
15+
layoutModel.doAction(Actions.addNode({
16+
type: "tab",
17+
component: value,
18+
name: value,
19+
20+
}, "root", DockLocation.CENTER, 0));
21+
}
1322
}, [value]);
1423

1524
return (

frontend/app/components/FlexLayoutComponent.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { CornersOut, X } from "@phosphor-icons/react";
33
import { Dispatch, useCallback, useState } from "react";
44
import { visualizations } from "./visualizations/Visualizations";
55

6-
const model = Model.fromJson({
6+
export const layoutModel = Model.fromJson({
77
global: {},
88
borders: [],
99
layout: {
1010
type: "row",
11+
id: "root",
1112
weight: 100,
1213
children: [
1314
{
@@ -148,7 +149,7 @@ export default function FlexLayoutComponent() {
148149
// TODO: is this running too many times? idk about this function nesting
149150
const setStateAndSave = useCallback((newValue: T) => {
150151
setState(newValue);
151-
model.doAction(
152+
layoutModel.doAction(
152153
Actions.updateNodeAttributes(node.getId(), {
153154
config: { [path]: newValue },
154155
}),
@@ -167,7 +168,7 @@ export default function FlexLayoutComponent() {
167168
return (
168169
<Layout
169170
realtimeResize={true}
170-
model={model}
171+
model={layoutModel}
171172
factory={factory}
172173
icons={{
173174
close: <X color="gray" weight="bold" />,

frontend/app/components/Navbar.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default function Navbar() {
6868
const [opened, { open, close }] = useDisclosure(false);
6969
const [fileName, setFileName] = useState("No File Selected");
7070
const [recordings, setRecordings] = useState<string[] | null>(null);
71-
const [production, setProduction] = useState<boolean>(true);
71+
const [isProduction, setIsProduction] = useState<boolean>(true);
7272
const displayedName = fileName.split("/")[fileName.split("/").length - 1];
7373

7474
const { switchToRecording, switchToLiveData, subscribeNumRows } = useDataMethods();
@@ -80,16 +80,10 @@ export default function Navbar() {
8080
}
8181
});
8282
}, []);
83-
{
84-
/* <p>{myNumRows}</p> */
85-
}
86-
{
87-
/* <button onClick={() => switchToLiveData()}>blah</button> */
88-
}
8983

9084
useEffect(() => {
91-
availableRecordings(production).then((r) => setRecordings(r));
92-
}, [production]);
85+
availableRecordings(isProduction).then((r) => setRecordings(r));
86+
}, [isProduction]);
9387

9488
function SystemSelector() {
9589
const [opened, { open, close }] = useDisclosure(false);
@@ -118,8 +112,8 @@ export default function Navbar() {
118112
return (
119113
<Switch
120114
className="px-3"
121-
checked={production}
122-
onChange={(e) => setProduction(e.currentTarget.checked)}
115+
checked={isProduction}
116+
onChange={(e) => setIsProduction(e.currentTarget.checked)}
123117
label="production"
124118
/>
125119
);
@@ -249,8 +243,7 @@ export default function Navbar() {
249243
priority={true}
250244
/>
251245
</div>
252-
<AutocompleteSearchbar /> {/* Messing around with Mantine components */}{" "}
253-
{/* console.log("This is the component/widget added") */}
246+
<AutocompleteSearchbar />
254247
{/* Modal */}
255248
<div className="m-3">
256249
<SystemSelector />

0 commit comments

Comments
 (0)