Skip to content

Commit 6ae94ed

Browse files
authored
Open files in editor (#115)
* Attempt at autocompleting frankdoc elements * Editor now suggests frank-elements when opening a tag: '<' and inserts any mandatory attributes when the suggestion is inserted. Also suggests attribute names when typing within a tag * Doesnt show attribute suggestions when inside of quotation marks * Restructed backend and endpoints to now point to a projectname/filename for fetching configurations. * Can now update xmlcontent in memory * Fixed issue with sidebar close button not properly showing up, moved savebutton to sidebar * Applied feedback from review * Forgot two instances of assuming a project was loaded in when that was not necessarily true, also removed the default tab
1 parent 06cb97b commit 6ae94ed

14 files changed

Lines changed: 464 additions & 145 deletions

File tree

src/main/frontend/app/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ body {
5454
}
5555
}
5656

57+
.monaco-editor .highlight-line {
58+
@apply bg-yellow-200/30 border-l-4 border-yellow-400 transition-colors;
59+
}
60+
5761
:root {
5862
/* Allotment Styling */
5963
--focus-border: var(--color-brand);

src/main/frontend/app/routes/builder/builder-structure.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default function BuilderStructure() {
5454
setIsLoading: state.setIsLoading,
5555
})),
5656
)
57+
const project = useProjectStore.getState().project
5758
const [searchTerm, setSearchTerm] = useState('')
5859
const tree = useRef<TreeRef>(null)
5960
const dataProviderReference = useRef(new BuilderFilesDataProvider([]))
@@ -73,12 +74,14 @@ export default function BuilderStructure() {
7374
try {
7475
const loaded: ConfigWithAdapters[] = await Promise.all(
7576
configurationNames.map(async (configName) => {
76-
const adapterNames = await getAdapterNamesFromConfiguration(configName)
77+
if (!project) return
78+
const adapterNames = await getAdapterNamesFromConfiguration(project.name, configName)
7779

7880
// Fetch listener name for each adapter
7981
const adapters = await Promise.all(
8082
adapterNames.map(async (adapterName) => {
81-
const listenerName = await getAdapterListenerType(configName, adapterName)
83+
const listenerName = await getAdapterListenerType(project.name, configName, adapterName)
84+
console.log(listenerName)
8285
return { adapterName, listenerName }
8386
}),
8487
)

src/main/frontend/app/routes/builder/canvas/flow.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ import { convertAdapterXmlToJson, getAdapterFromConfiguration } from '~/routes/b
2727
import { exportFlowToXml } from '~/routes/builder/flow-to-xml-parser'
2828
import useNodeContextStore from '~/stores/node-context-store'
2929
import CreateNodeModal from '~/components/flow/create-node-modal'
30+
import { useProjectStore } from "~/stores/project-store";
3031

3132
export type FlowNode = FrankNode | ExitNode | StickyNote | GroupNode | Node
3233

33-
const NodeContextMenuContext = createContext<(visible: boolean) => void>(() => {})
34+
const NodeContextMenuContext = createContext<(visible: boolean) => void>(() => { })
3435
export const useNodeContextMenu = () => useContext(NodeContextMenuContext)
3536

3637
const selector = (state: FlowState) => ({
@@ -68,6 +69,7 @@ function FlowCanvas({ showNodeContextMenu }: Readonly<{ showNodeContextMenu: (b:
6869
const { nodes, edges, viewport, onNodesChange, onEdgesChange, onConnect, onReconnect } = useFlowStore(
6970
useShallow(selector),
7071
)
72+
const project = useProjectStore.getState().project
7173

7274
const sourceInfoReference = useRef<{
7375
nodeId: string | null
@@ -430,7 +432,8 @@ function FlowCanvas({ showNodeContextMenu }: Readonly<{ showNodeContextMenu: (b:
430432
if (tab.flowJson && Object.keys(tab.flowJson).length > 0) {
431433
restoreFlowFromTab(tab.value)
432434
} else if (tab.configurationName && tab.value) {
433-
const adapter = await getAdapterFromConfiguration(tab.configurationName, tab.value)
435+
if (!project) return
436+
const adapter = await getAdapterFromConfiguration(project.name, tab.configurationName, tab.value)
434437
if (!adapter) return
435438
const adapterJson = await convertAdapterXmlToJson(adapter)
436439
flowStore.setEdges(adapterJson.edges)

src/main/frontend/app/routes/builder/xml-to-json-parser.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ interface IdCounter {
88
current: number
99
}
1010

11-
export async function getXmlString(filename: string): Promise<string> {
11+
export async function getXmlString(projectName: string, filename: string): Promise<string> {
1212
try {
13-
const response = await fetch(`/configurations/${filename}`)
13+
const response = await fetch(`/projects/${projectName}/${filename}`);
1414
if (!response.ok) {
15-
throw new Error(`HTTP error! Status: ${response.status}`)
15+
throw new Error(`HTTP error! Status: ${response.status}`);
1616
}
17-
const data = await response.json()
18-
return data.xmlContent
17+
18+
const data = await response.json();
19+
return data.xmlContent;
1920
} catch (error) {
20-
throw new Error(`Failed to fetch XML file: ${error}`)
21+
throw new Error(`Failed to fetch XML file for ${projectName}/${filename}: ${error}`);
2122
}
2223
}
2324

24-
export async function getAdapterNamesFromConfiguration(filename: string): Promise<string[]> {
25-
const xmlString = await getXmlString(filename)
25+
export async function getAdapterNamesFromConfiguration(projectName: string, filename: string): Promise<string[]> {
26+
const xmlString = await getXmlString(projectName, filename)
2627

2728
return new Promise((resolve, reject) => {
2829
const adapterNames: string[] = []
@@ -50,8 +51,8 @@ export async function getAdapterNamesFromConfiguration(filename: string): Promis
5051
})
5152
}
5253

53-
export async function getAdapterFromConfiguration(filename: string, adapterName: string): Promise<Element | null> {
54-
const xmlString = await getXmlString(filename)
54+
export async function getAdapterFromConfiguration(projectname: string, filename: string, adapterName: string): Promise<Element | null> {
55+
const xmlString = await getXmlString(projectname, filename)
5556
const parser = new DOMParser()
5657
const xmlDoc = parser.parseFromString(xmlString, 'text/xml')
5758

@@ -65,8 +66,12 @@ export async function getAdapterFromConfiguration(filename: string, adapterName:
6566
return null
6667
}
6768

68-
export async function getAdapterListenerType(filename: string, adapterName: string): Promise<string | null> {
69-
const adapterElement = await getAdapterFromConfiguration(filename, adapterName)
69+
export async function getAdapterListenerType(
70+
projectName: string,
71+
filename: string,
72+
adapterName: string,
73+
): Promise<string | null> {
74+
const adapterElement = await getAdapterFromConfiguration(projectName, filename, adapterName)
7075
if (!adapterElement) return null
7176
// Look through all child elements inside the adapter
7277
const children = adapterElement.querySelectorAll('*')

src/main/frontend/app/routes/editor/editor-files.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default function EditorFiles() {
4848
setIsLoading: state.setIsLoading,
4949
})),
5050
)
51+
const project = useProjectStore.getState().project
5152
const [searchTerm, setSearchTerm] = useState('')
5253
const tree = useRef<TreeRef>(null)
5354
const dataProviderReference = useRef(new BuilderFilesDataProvider([]))
@@ -68,7 +69,8 @@ export default function EditorFiles() {
6869
try {
6970
const loaded: ConfigWithAdapters[] = await Promise.all(
7071
configurationNames.map(async (configName) => {
71-
const adapterNames = await getAdapterNamesFromConfiguration(configName)
72+
if (!project) return
73+
const adapterNames = await getAdapterNamesFromConfiguration(project.name, configName)
7274
return { configName, adapterNames }
7375
}),
7476
)

0 commit comments

Comments
 (0)