forked from finos/vuu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from ScottLogic/VUU-27-remote-layout-management
VUU-27 remotePersistenceManager implementation
- Loading branch information
Showing
15 changed files
with
651 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
layout-server/src/main/java/org/finos/vuu/layoutserver/CorsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.finos.vuu.layoutserver; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class CorsConfig implements WebMvcConfigurer { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOrigins("http://127.0.0.1:5173") | ||
.allowedMethods("GET", "POST", "PUT", "DELETE"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
vuu-ui/packages/vuu-layout/src/layout-persistence/RemoteLayoutPersistenceManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { LayoutMetadata, LayoutMetadataDto } from "@finos/vuu-shell"; | ||
import { LayoutPersistenceManager } from "./LayoutPersistenceManager"; | ||
import { LayoutJSON } from "../layout-reducer"; | ||
import { defaultLayout } from "./data"; | ||
|
||
const DEFAULT_SERVER_BASE_URL = "http://127.0.0.1:8081/api"; | ||
|
||
const baseURL = process.env.LAYOUT_BASE_URL ?? DEFAULT_SERVER_BASE_URL; | ||
const metadataSaveLocation = "layouts/metadata"; | ||
const layoutsSaveLocation = "layouts"; | ||
|
||
export type CreateLayoutResponseDto = { metadata: LayoutMetadata }; | ||
export type GetLayoutResponseDto = { definition: LayoutJSON }; | ||
|
||
export class RemoteLayoutPersistenceManager | ||
implements LayoutPersistenceManager | ||
{ | ||
createLayout( | ||
metadata: LayoutMetadataDto, | ||
layout: LayoutJSON | ||
): Promise<LayoutMetadata> { | ||
return new Promise((resolve, reject) => | ||
fetch(`${baseURL}/${layoutsSaveLocation}`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
method: "POST", | ||
body: JSON.stringify({ | ||
metadata, | ||
definition: JSON.stringify(layout), | ||
}), | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
reject(new Error(response.statusText)); | ||
} | ||
response.json().then(({ metadata }: CreateLayoutResponseDto) => { | ||
if (!metadata) { | ||
reject(new Error("Response did not contain valid metadata")); | ||
} | ||
resolve(metadata); | ||
}); | ||
}) | ||
.catch((error: Error) => { | ||
reject(error); | ||
}) | ||
); | ||
} | ||
|
||
updateLayout( | ||
id: string, | ||
metadata: LayoutMetadataDto, | ||
newLayoutJson: LayoutJSON | ||
): Promise<void> { | ||
return new Promise((resolve, reject) => | ||
fetch(`${baseURL}/${layoutsSaveLocation}/${id}`, { | ||
method: "PUT", | ||
body: JSON.stringify({ | ||
metadata, | ||
layout: newLayoutJson, | ||
}), | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
reject(new Error(response.statusText)); | ||
} | ||
resolve(); | ||
}) | ||
.catch((error: Error) => { | ||
reject(error); | ||
}) | ||
); | ||
} | ||
|
||
deleteLayout(id: string): Promise<void> { | ||
return new Promise((resolve, reject) => | ||
fetch(`${baseURL}/${layoutsSaveLocation}/${id}`, { | ||
method: "DELETE", | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
reject(new Error(response.statusText)); | ||
} | ||
resolve(); | ||
}) | ||
.catch((error: Error) => { | ||
reject(error); | ||
}) | ||
); | ||
} | ||
|
||
loadLayout(id: string): Promise<LayoutJSON> { | ||
return new Promise((resolve, reject) => { | ||
fetch(`${baseURL}/${layoutsSaveLocation}/${id}`, { | ||
method: "GET", | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
reject(new Error(response.statusText)); | ||
} | ||
response.json().then(({ definition }: GetLayoutResponseDto) => { | ||
if (!definition) { | ||
reject(new Error("Response did not contain a valid layout")); | ||
} | ||
resolve(definition); | ||
}); | ||
}) | ||
.catch((error: Error) => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
loadMetadata(): Promise<LayoutMetadata[]> { | ||
return new Promise((resolve, reject) => | ||
fetch(`${baseURL}/${metadataSaveLocation}`, { | ||
method: "GET", | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
reject(new Error(response.statusText)); | ||
} | ||
response.json().then((metadata: LayoutMetadata[]) => { | ||
if (!metadata) { | ||
reject(new Error("Response did not contain valid metadata")); | ||
} | ||
resolve(metadata); | ||
}); | ||
}) | ||
.catch((error: Error) => { | ||
reject(error); | ||
}) | ||
); | ||
} | ||
|
||
saveApplicationLayout(layout: LayoutJSON): Promise<void> { | ||
// TODO POST api/layouts/application #71 | ||
console.log(layout); | ||
return new Promise((resolve) => resolve()); | ||
} | ||
|
||
loadApplicationLayout(): Promise<LayoutJSON> { | ||
// TODO GET api/layouts/application #71 | ||
return new Promise((resolve) => resolve(defaultLayout)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from "./data"; | ||
export * from "./LayoutPersistenceManager"; | ||
export * from "./LocalLayoutPersistenceManager"; | ||
export * from './RemoteLayoutPersistenceManager'; | ||
export * from "./useLayoutContextMenuItems"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.