Skip to content

Commit

Permalink
Created minimal dashboard app with relay provider and keycloak
Browse files Browse the repository at this point in the history
  • Loading branch information
daurer committed Nov 14, 2024
1 parent 831db98 commit 7f8a617
Show file tree
Hide file tree
Showing 17 changed files with 865 additions and 549 deletions.
2 changes: 2 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ dist-ssr
*.local

*storybook.log

*.tsbuildinfo
3 changes: 3 additions & 0 deletions frontend/dashboard/.env.production
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"
12 changes: 12 additions & 0 deletions frontend/dashboard/index.html
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>
42 changes: 42 additions & 0 deletions frontend/dashboard/package.json
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"
}
}
11 changes: 11 additions & 0 deletions frontend/dashboard/relay.config.json
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
}
9 changes: 9 additions & 0 deletions frontend/dashboard/src/App.tsx
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
63 changes: 63 additions & 0 deletions frontend/dashboard/src/RelayEnvironment.ts
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();
12 changes: 12 additions & 0 deletions frontend/dashboard/src/keycloak.ts
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,

Check failure on line 5 in frontend/dashboard/src/keycloak.ts

View workflow job for this annotation

GitHub Actions / frontend_code / lint

Unsafe assignment of an `any` value
realm: import.meta.env.VITE_KEYCLOAK_REALM,

Check failure on line 6 in frontend/dashboard/src/keycloak.ts

View workflow job for this annotation

GitHub Actions / frontend_code / lint

Unsafe assignment of an `any` value
clientId: import.meta.env.VITE_KEYCLOAK_CLIENT,

Check failure on line 7 in frontend/dashboard/src/keycloak.ts

View workflow job for this annotation

GitHub Actions / frontend_code / lint

Unsafe assignment of an `any` value
};

const keycloak = new Keycloak(initOptions);

export default keycloak;
13 changes: 13 additions & 0 deletions frontend/dashboard/src/main.tsx
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>
);
1 change: 1 addition & 0 deletions frontend/dashboard/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
25 changes: 25 additions & 0 deletions frontend/dashboard/tsconfig.app.json
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"]
}
7 changes: 7 additions & 0 deletions frontend/dashboard/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}
23 changes: 23 additions & 0 deletions frontend/dashboard/tsconfig.node.json
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"]
}
8 changes: 8 additions & 0 deletions frontend/dashboard/vite.config.ts
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()],
});
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"type": "module",
"workspaces": [
"workflows-lib",
"relay-workflows-lib"
"relay-workflows-lib",
"dashboard"
],
"scripts": {
"lint": "eslint",
Expand Down
3 changes: 2 additions & 1 deletion frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"files": [],
"references": [
{ "path": "./workflows-lib" },
{ "path": "./relay-workflows-lib" }
{ "path": "./relay-workflows-lib" },
{ "path": "./dashboard" }
]
}
Loading

0 comments on commit 7f8a617

Please sign in to comment.