-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created minimal dashboard app with relay provider and keycloak
- Loading branch information
Showing
17 changed files
with
865 additions
and
549 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ dist-ssr | |
*.local | ||
|
||
*storybook.log | ||
|
||
*.tsbuildinfo |
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,3 @@ | ||
VITE_KEYCLOAK_URL = "https://workflows.diamond.ac.uk/graphql" | ||
VITE_KEYCLOAK_REALM = "master" | ||
VITE_KEYCLOAK_CLIENT = "workflows-cluster" |
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,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Workflows Dashboard</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
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,42 @@ | ||
{ | ||
"name": "dashboard", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "relay-compiler --validate && tsc -b && vite build", | ||
"lint": "eslint .", | ||
"preview": "vite preview", | ||
"relay": "relay-compiler" | ||
}, | ||
"dependencies": { | ||
"@jsonforms/material-renderers": "^3.4.1", | ||
"@jsonforms/react": "^3.4.1", | ||
"keycloak-js": "^26.0.5", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"react-relay": "18.1.0", | ||
"workflows-lib": "*", | ||
"relay-workflows-lib": "*" | ||
|
||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.13.0", | ||
"@jsonforms/core": "^3.4.1", | ||
"@types/react": "^18.3.12", | ||
"@types/react-dom": "^18.3.1", | ||
"@types/react-relay": "16.0.6", | ||
"@types/relay-runtime": "18.1.1", | ||
"babel-plugin-relay": "18.1.0", | ||
"eslint": "^9.13.0", | ||
"eslint-plugin-react-hooks": "^5.0.0", | ||
"eslint-plugin-react-refresh": "^0.4.14", | ||
"globals": "^15.11.0", | ||
"relay-compiler": "18.1.0", | ||
"typescript": "~5.6.2", | ||
"typescript-eslint": "^8.11.0", | ||
"vite": "^5.4.10", | ||
"vite-plugin-relay": "2.1.0" | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"src": "./src", | ||
"language": "typescript", | ||
"schema": "./src/workflows.graphql", | ||
"exclude": [ | ||
"**/node_modules/**", | ||
"**/__mocks__/**", | ||
"**/__generated__/**" | ||
], | ||
"eagerEsModules": true | ||
} |
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,9 @@ | ||
function App() { | ||
return ( | ||
<> | ||
<h1>Hello Workflow Dashboard!</h1> | ||
</> | ||
) | ||
} | ||
|
||
export default App |
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,63 @@ | ||
import { | ||
Environment, | ||
Network, | ||
RecordSource, | ||
Store, | ||
FetchFunction, | ||
} from "relay-runtime"; | ||
import keycloak from "./keycloak"; | ||
|
||
const HTTP_ENDPOINT = "https://workflows.diamond.ac.uk/graphql"; | ||
|
||
const kcinit = keycloak.init({ | ||
onLoad: "login-required" | ||
}) | ||
.then( | ||
auth => { | ||
console.info("Authenticated"); | ||
console.log("auth", auth); | ||
keycloak.onTokenExpired = () => { | ||
console.log("token expired"); | ||
}; | ||
}, | ||
() => { | ||
console.error("Authentication failed"); | ||
} | ||
); | ||
|
||
const fetchFn: FetchFunction = async (request, variables) => { | ||
if (!keycloak.authenticated) { | ||
await kcinit; | ||
} | ||
|
||
if (keycloak.token) { | ||
const resp = await fetch(HTTP_ENDPOINT, { | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${keycloak.token}`, | ||
Accept: | ||
"application/graphql-response+json; charset=utf-8, application/json; charset=utf-8", | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
query: request.text, // <-- The GraphQL document composed by Relay | ||
variables, | ||
}), | ||
}); | ||
|
||
return await resp.json(); // eslint-disable-line @typescript-eslint/no-unsafe-return | ||
} else { | ||
console.log("Not authenticated yet"); | ||
return {}; | ||
} | ||
}; | ||
|
||
|
||
function createRelayEnvironment() { | ||
return new Environment({ | ||
network: Network.create(fetchFn), | ||
store: new Store(new RecordSource()), | ||
}); | ||
} | ||
|
||
export const RelayEnvironment = createRelayEnvironment(); |
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,12 @@ | ||
import Keycloak from "keycloak-js"; | ||
|
||
//Keycloak init options | ||
const initOptions = { | ||
url: import.meta.env.VITE_KEYCLOAK_URL, | ||
realm: import.meta.env.VITE_KEYCLOAK_REALM, | ||
clientId: import.meta.env.VITE_KEYCLOAK_CLIENT, | ||
}; | ||
|
||
const keycloak = new Keycloak(initOptions); | ||
|
||
export default keycloak; |
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,13 @@ | ||
import { RelayEnvironmentProvider } from "react-relay"; | ||
import { RelayEnvironment } from "./RelayEnvironment"; | ||
import { StrictMode } from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import App from "./App.tsx"; | ||
|
||
createRoot(document.getElementById("root") as Element).render( | ||
<RelayEnvironmentProvider environment={RelayEnvironment}> | ||
<StrictMode> | ||
<App/> | ||
</StrictMode> | ||
</RelayEnvironmentProvider> | ||
); |
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 @@ | ||
/// <reference types="vite/client" /> |
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,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "Bundler", | ||
"allowImportingTsExtensions": true, | ||
"isolatedModules": true, | ||
"moduleDetection": "force", | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUncheckedSideEffectImports": true | ||
}, | ||
"include": ["src"] | ||
} |
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,7 @@ | ||
{ | ||
"files": [], | ||
"references": [ | ||
{ "path": "./tsconfig.app.json" }, | ||
{ "path": "./tsconfig.node.json" } | ||
] | ||
} |
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,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"lib": ["ES2023"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "Bundler", | ||
"allowImportingTsExtensions": true, | ||
"isolatedModules": true, | ||
"moduleDetection": "force", | ||
"noEmit": true, | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUncheckedSideEffectImports": true | ||
}, | ||
"include": ["vite.config.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,8 @@ | ||
import relay from "vite-plugin-relay"; | ||
import { defineConfig } from "vite"; | ||
import react from "@vitejs/plugin-react"; | ||
|
||
// https://vite.dev/config/ | ||
export default defineConfig({ | ||
plugins: [relay, react()], | ||
}); |
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
Oops, something went wrong.