create-pb-tririga-react-app 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +54 -0
- package/package.json +16 -0
- package/template/.env.example +14 -0
- package/template/README.md +59 -0
- package/template/_gitignore +26 -0
- package/template/index.html +13 -0
- package/template/package.json +41 -0
- package/template/public/tri-app-config.json +9 -0
- package/template/src/App.tsx +34 -0
- package/template/src/components/index.ts +1 -0
- package/template/src/index.css +20 -0
- package/template/src/main.tsx +69 -0
- package/template/src/model/AppModel.ts +14 -0
- package/template/src/pages/index.ts +1 -0
- package/template/src/services/AuthService.ts +58 -0
- package/template/src/services/tririgaService.ts +44 -0
- package/template/src/types/tririga-react-components.d.ts +107 -0
- package/template/tsconfig.json +21 -0
- package/template/vite.config.ts +9 -0
package/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
// 1. Get project name from command line
|
|
8
|
+
const projectName = process.argv[2] || 'my-tririga-app';
|
|
9
|
+
const currentDir = process.cwd();
|
|
10
|
+
const projectDir = path.join(currentDir, projectName);
|
|
11
|
+
|
|
12
|
+
// 2. Create Directory
|
|
13
|
+
if (fs.existsSync(projectDir)) {
|
|
14
|
+
console.error(`Directory ${projectName} already exists.`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
fs.mkdirSync(projectDir);
|
|
18
|
+
|
|
19
|
+
// 3. Copy Template Files
|
|
20
|
+
const templateDir = path.join(__dirname, 'template');
|
|
21
|
+
|
|
22
|
+
function copyRecursiveSync(src, dest) {
|
|
23
|
+
const exists = fs.existsSync(src);
|
|
24
|
+
const stats = exists && fs.statSync(src);
|
|
25
|
+
const isDirectory = exists && stats.isDirectory();
|
|
26
|
+
|
|
27
|
+
if (isDirectory) {
|
|
28
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
29
|
+
fs.readdirSync(src).forEach(childItemName => {
|
|
30
|
+
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
fs.copyFileSync(src, dest);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
copyRecursiveSync(templateDir, projectDir);
|
|
38
|
+
|
|
39
|
+
// Rename _gitignore to .gitignore
|
|
40
|
+
const gitignorePath = path.join(projectDir, '_gitignore');
|
|
41
|
+
if (fs.existsSync(gitignorePath)) {
|
|
42
|
+
fs.renameSync(gitignorePath, path.join(projectDir, '.gitignore'));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 4. Update package.json name
|
|
46
|
+
const pkgJsonPath = path.join(projectDir, 'package.json');
|
|
47
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
|
|
48
|
+
pkgJson.name = projectName;
|
|
49
|
+
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
50
|
+
|
|
51
|
+
console.log(`Success! Created ${projectName}.`);
|
|
52
|
+
console.log(`cd ${projectName}`);
|
|
53
|
+
console.log(`npm install`);
|
|
54
|
+
console.log(`npm run dev`);
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-pb-tririga-react-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Scaffold a TRIRIGA React app with Vite and TypeScript",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-pb-tririga-react-app": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"template"
|
|
12
|
+
],
|
|
13
|
+
"keywords": ["tririga", "react", "vite", "scaffold"],
|
|
14
|
+
"author": "Your Name",
|
|
15
|
+
"license": "ISC"
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Local Development Config
|
|
2
|
+
VITE_TRIRIGA_URL=http://localhost:8001
|
|
3
|
+
VITE_INSTANCE_ID=-1
|
|
4
|
+
VITE_CONTEXT_PATH=/app
|
|
5
|
+
VITE_MODEL_AND_VIEW=devView
|
|
6
|
+
VITE_BASE_PATH=/app/devView
|
|
7
|
+
VITE_EXPOSED_NAME=devView
|
|
8
|
+
VITE_SSO=false
|
|
9
|
+
VITE_AUTO_LOGIN=true
|
|
10
|
+
|
|
11
|
+
# Deployment Config (used by tri-deploy)
|
|
12
|
+
TRI_URL=https://your-tririga-server.com
|
|
13
|
+
TRI_USER=your-username
|
|
14
|
+
TRI_PASSWORD=your-password
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# TRIRIGA React App Template
|
|
2
|
+
|
|
3
|
+
This is a template for building IBM TRIRIGA UX applications using React, TypeScript, and Vite.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
1. **Install Dependencies**
|
|
8
|
+
```bash
|
|
9
|
+
npm install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
2. **Configure Environment**
|
|
13
|
+
Copy `.env.example` to `.env` and update the values for your local development and deployment settings.
|
|
14
|
+
```bash
|
|
15
|
+
cp .env.example .env
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
3. **Run Locally**
|
|
19
|
+
```bash
|
|
20
|
+
npm run dev
|
|
21
|
+
```
|
|
22
|
+
Open [http://localhost:5173](http://localhost:5173) (or the port shown in terminal).
|
|
23
|
+
|
|
24
|
+
## Deployment
|
|
25
|
+
|
|
26
|
+
To deploy to a TRIRIGA environment:
|
|
27
|
+
|
|
28
|
+
1. **Install Depoyment Tool** (If not already installed globally)
|
|
29
|
+
```bash
|
|
30
|
+
npm install -g @tririga/tri-deploy
|
|
31
|
+
```
|
|
32
|
+
*Note: If you prefer not to install globally, you can add `@tririga/tri-deploy` to your devDependencies.*
|
|
33
|
+
|
|
34
|
+
2. **Configure Credentials**
|
|
35
|
+
Ensure your `.env` file has the correct `TRI_URL`, `TRI_USER`, and `TRI_PASSWORD`.
|
|
36
|
+
|
|
37
|
+
3. **Run Deployment**
|
|
38
|
+
The view name will be taken from the `name` field in `package.json`.
|
|
39
|
+
```bash
|
|
40
|
+
npm run build:deploy
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Browser Support & Polyfills
|
|
44
|
+
|
|
45
|
+
## Project Structure
|
|
46
|
+
|
|
47
|
+
- `src/components`: Reusable UI components.
|
|
48
|
+
- `src/pages`: Top-level page definitions (routes).
|
|
49
|
+
- `src/model`: TRIRIGA AppModel (Datasources).
|
|
50
|
+
- `src/services`: API services (Auth, Config).
|
|
51
|
+
- `public/tri-app-config.json`: Local development configuration mocking the server response.
|
|
52
|
+
|
|
53
|
+
## Tech Stack
|
|
54
|
+
|
|
55
|
+
- [React](https://react.dev/)
|
|
56
|
+
- [TypeScript](https://www.typescriptlang.org/)
|
|
57
|
+
- [Vite](https://vitejs.dev/)
|
|
58
|
+
- [Carbon Design System](https://carbondesignsystem.com/)
|
|
59
|
+
- [@tririga/tririga-react-components](https://www.npmjs.com/package/@tririga/tririga-react-components)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
logs
|
|
3
|
+
*.log
|
|
4
|
+
npm-debug.log*
|
|
5
|
+
yarn-debug.log*
|
|
6
|
+
yarn-error.log*
|
|
7
|
+
pnpm-debug.log*
|
|
8
|
+
lerna-debug.log*
|
|
9
|
+
|
|
10
|
+
node_modules
|
|
11
|
+
dist
|
|
12
|
+
dist-ssr
|
|
13
|
+
*.local
|
|
14
|
+
.env
|
|
15
|
+
ux-work-task-form
|
|
16
|
+
|
|
17
|
+
# Editor directories and files
|
|
18
|
+
.vscode/*
|
|
19
|
+
!.vscode/extensions.json
|
|
20
|
+
.idea
|
|
21
|
+
.DS_Store
|
|
22
|
+
*.suo
|
|
23
|
+
*.ntvs*
|
|
24
|
+
*.njsproj
|
|
25
|
+
*.sln
|
|
26
|
+
*.sw?
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Tririga React App</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tririga-react-template",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"lint": "eslint .",
|
|
10
|
+
"preview": "vite preview",
|
|
11
|
+
"deploy": "dotenv -- cross-var tri-deploy -t %TRI_URL% -u %TRI_USER% -p %TRI_PASSWORD% -v \"$npm_package_name\" -d dist -w",
|
|
12
|
+
"build:deploy": "npm run build && npm run deploy"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@babel/runtime": "^7.26.0",
|
|
16
|
+
"@carbon/icons-react": "^11.55.0",
|
|
17
|
+
"@carbon/react": "^1.72.0",
|
|
18
|
+
"@carbon/styles": "^1.72.0",
|
|
19
|
+
"@tririga/tririga-react-components": "^2.0.6",
|
|
20
|
+
"lodash": "^4.17.21",
|
|
21
|
+
"lodash-es": "^4.17.21",
|
|
22
|
+
"react": "^18.3.1",
|
|
23
|
+
"react-dom": "^18.3.1",
|
|
24
|
+
"react-router-dom": "^6.28.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@eslint/js": "^9.17.0",
|
|
28
|
+
"@types/react": "^18.3.18",
|
|
29
|
+
"@types/react-dom": "^18.3.5",
|
|
30
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
31
|
+
"cross-var": "^1.1.0",
|
|
32
|
+
"dotenv-cli": "^8.0.0",
|
|
33
|
+
"eslint": "^9.17.0",
|
|
34
|
+
"eslint-plugin-react-hooks": "^5.0.0",
|
|
35
|
+
"eslint-plugin-react-refresh": "^0.4.16",
|
|
36
|
+
"globals": "^15.14.0",
|
|
37
|
+
"typescript": "~5.6.2",
|
|
38
|
+
"typescript-eslint": "^8.18.2",
|
|
39
|
+
"vite": "^6.0.5"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { getAppModel } from './model/AppModel';
|
|
3
|
+
import { Theme, Content, Grid, Column, Button } from '@carbon/react';
|
|
4
|
+
|
|
5
|
+
function App() {
|
|
6
|
+
const [loading, setLoading] = useState(true);
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
// Example: verify model is present
|
|
10
|
+
const model = getAppModel();
|
|
11
|
+
console.log('App loaded with model:', model);
|
|
12
|
+
setLoading(false);
|
|
13
|
+
}, []);
|
|
14
|
+
|
|
15
|
+
if (loading) return <div>Loading TRIRIGA App...</div>;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Theme theme="g100">
|
|
19
|
+
<Content>
|
|
20
|
+
<Grid>
|
|
21
|
+
<Column lg={16} md={8} sm={4}>
|
|
22
|
+
<h1 style={{ marginBottom: '1rem' }}>Welcome to your new TRIRIGA React App</h1>
|
|
23
|
+
<p style={{ marginBottom: '2rem' }}>
|
|
24
|
+
This is a template application using React, Vite, TypeScript, and Carbon Design System.
|
|
25
|
+
</p>
|
|
26
|
+
<Button>Example Button</Button>
|
|
27
|
+
</Column>
|
|
28
|
+
</Grid>
|
|
29
|
+
</Content>
|
|
30
|
+
</Theme>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default App
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}; // Placeholder to ensure folder is tracked
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
line-height: 1.5;
|
|
4
|
+
font-weight: 400;
|
|
5
|
+
|
|
6
|
+
color-scheme: light dark;
|
|
7
|
+
color: rgba(255, 255, 255, 0.87);
|
|
8
|
+
background-color: #242424;
|
|
9
|
+
|
|
10
|
+
font-synthesis: none;
|
|
11
|
+
text-rendering: optimizeLegibility;
|
|
12
|
+
-webkit-font-smoothing: antialiased;
|
|
13
|
+
-moz-osx-font-smoothing: grayscale;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
body {
|
|
17
|
+
margin: 0;
|
|
18
|
+
min-width: 320px;
|
|
19
|
+
min-height: 100vh;
|
|
20
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { StrictMode } from 'react'
|
|
2
|
+
import { createRoot } from 'react-dom/client'
|
|
3
|
+
import { HashRouter } from 'react-router-dom'
|
|
4
|
+
import './index.css'
|
|
5
|
+
import App from './App'
|
|
6
|
+
import { initTriAppConfig } from './services/tririgaService'
|
|
7
|
+
import { createAppModel } from './model/AppModel'
|
|
8
|
+
import { standardTririgaLogin, getAuthCheckerForCurrentApp, TriCallback } from '@tririga/tririga-react-components'
|
|
9
|
+
import '@carbon/styles/css/styles.css'
|
|
10
|
+
|
|
11
|
+
// Determine base path when deployed under TRIRIGA like /app/viewName/
|
|
12
|
+
const computeBasePath = () => {
|
|
13
|
+
const segments = window.location.pathname.split('/').filter(Boolean)
|
|
14
|
+
// Expect pattern: [ 'app', '<viewId>', ...]
|
|
15
|
+
if (segments[0] === 'app' && segments[1]) {
|
|
16
|
+
return `/app/${segments[1]}`
|
|
17
|
+
}
|
|
18
|
+
return '' // fallback for local dev (served at root)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const basename = computeBasePath()
|
|
22
|
+
|
|
23
|
+
async function bootstrap() {
|
|
24
|
+
let shouldRenderApp = true;
|
|
25
|
+
try {
|
|
26
|
+
// Ensure app config is available
|
|
27
|
+
await initTriAppConfig()
|
|
28
|
+
|
|
29
|
+
// Auto-login logic
|
|
30
|
+
const autoLogin = !import.meta.env.DEV || String(import.meta.env.VITE_AUTO_LOGIN ?? 'false') === 'true'
|
|
31
|
+
if (autoLogin) {
|
|
32
|
+
const currentUser = await standardTririgaLogin();
|
|
33
|
+
if (!currentUser) {
|
|
34
|
+
shouldRenderApp = false;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
// Optional auth check
|
|
40
|
+
const authChecker = await getAuthCheckerForCurrentApp()
|
|
41
|
+
if (authChecker && !authChecker.hasPermission('read')) {
|
|
42
|
+
alert("Unauthorized access");
|
|
43
|
+
shouldRenderApp = false;
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.warn('Auth check skipped or failed', e)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (shouldRenderApp) {
|
|
51
|
+
// Initialize Model
|
|
52
|
+
createAppModel((err: any) => console.error("Model Error:", err));
|
|
53
|
+
|
|
54
|
+
const root = createRoot(document.getElementById('root')!)
|
|
55
|
+
root.render(
|
|
56
|
+
<StrictMode>
|
|
57
|
+
<HashRouter>
|
|
58
|
+
<App />
|
|
59
|
+
</HashRouter>
|
|
60
|
+
</StrictMode>,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.error('Bootstrap failed', e)
|
|
65
|
+
document.body.innerHTML = `<div style="padding: 20px; color: red;"><h3>Application Error</h3><p>Failed to initialize application configuration.</p></div>`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
bootstrap()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TriModel, getTriAppConfig } from '@tririga/tririga-react-components';
|
|
2
|
+
|
|
3
|
+
let appModel: TriModel | null = null;
|
|
4
|
+
|
|
5
|
+
export function createAppModel(onError?: (err: any) => void): TriModel {
|
|
6
|
+
const { modelAndView, instanceId } = getTriAppConfig();
|
|
7
|
+
// @ts-expect-error - TriModel types might differ slightly in strict mode vs JS
|
|
8
|
+
appModel = new TriModel(modelAndView, instanceId, onError);
|
|
9
|
+
return appModel!;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getAppModel(): TriModel | null {
|
|
13
|
+
return appModel;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}; // Placeholder to ensure folder is tracked
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// AuthService.ts
|
|
2
|
+
import { getTriAppConfig, standardTririgaLogin, TriLoginApi } from '@tririga/tririga-react-components';
|
|
3
|
+
|
|
4
|
+
export class AuthService {
|
|
5
|
+
/**
|
|
6
|
+
* Helper to construct a URL for manual login redirection if needed
|
|
7
|
+
*/
|
|
8
|
+
static buildLoginUrl(): string {
|
|
9
|
+
const cfg = getTriAppConfig();
|
|
10
|
+
const base = `${cfg.tririgaUrl}${cfg.contextPath}`;
|
|
11
|
+
const redirect = window.location.href;
|
|
12
|
+
return `${base}/?initialUri=${encodeURIComponent(redirect)}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Forces a login check. Use this if you suspect the session is dead.
|
|
17
|
+
*/
|
|
18
|
+
static async login(): Promise<void> {
|
|
19
|
+
const cfg = getTriAppConfig();
|
|
20
|
+
try {
|
|
21
|
+
// standardTririgaLogin handles the redirect logic internally
|
|
22
|
+
const user = await standardTririgaLogin();
|
|
23
|
+
if (!user) {
|
|
24
|
+
// If it returns null/false, it means a redirect is likely happening
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.warn("Login helper failed, falling back to manual redirect", e);
|
|
29
|
+
}
|
|
30
|
+
// Fallback
|
|
31
|
+
window.location.assign(this.buildLoginUrl());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Logs the user out of TRIRIGA and reloads the page.
|
|
36
|
+
*/
|
|
37
|
+
static async logout(): Promise<void> {
|
|
38
|
+
const cfg = getTriAppConfig();
|
|
39
|
+
try {
|
|
40
|
+
// Try using the SDK's API first
|
|
41
|
+
if (TriLoginApi && typeof TriLoginApi.logout === 'function') {
|
|
42
|
+
await TriLoginApi.logout();
|
|
43
|
+
} else {
|
|
44
|
+
throw new Error('TriLoginApi.logout not available');
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {
|
|
47
|
+
// Fallback: Manual fetch to the logout endpoint
|
|
48
|
+
try {
|
|
49
|
+
await fetch(`${cfg.tririgaUrl}${cfg.contextPath}/logout`, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
credentials: 'include'
|
|
52
|
+
});
|
|
53
|
+
} catch (_) { /* ignore fetch errors */ }
|
|
54
|
+
}
|
|
55
|
+
// Reloading will trigger the bootstrap logic in main.tsx, which sends them to the login screen
|
|
56
|
+
window.location.reload();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Custom type for import.meta.env to satisfy TS if not fully typed
|
|
2
|
+
/// <reference types="vite/client" />
|
|
3
|
+
|
|
4
|
+
import { setTriAppConfig, getTriAppConfig, TriAppConfig } from '@tririga/tririga-react-components';
|
|
5
|
+
|
|
6
|
+
export async function initTriAppConfig(): Promise<TriAppConfig> {
|
|
7
|
+
// In Vite, use import.meta.env.* for dev; in production, create config from current environment
|
|
8
|
+
if (import.meta.env.DEV) {
|
|
9
|
+
const config: TriAppConfig = {
|
|
10
|
+
instanceId: import.meta.env.VITE_INSTANCE_ID || '-1',
|
|
11
|
+
tririgaUrl: import.meta.env.VITE_TRIRIGA_URL || 'http://localhost:8001',
|
|
12
|
+
contextPath: import.meta.env.VITE_CONTEXT_PATH || '/dev',
|
|
13
|
+
modelAndView: import.meta.env.VITE_MODEL_AND_VIEW || 'unknown',
|
|
14
|
+
appPath: import.meta.env.VITE_BASE_PATH,
|
|
15
|
+
appExposedName: import.meta.env.VITE_EXPOSED_NAME,
|
|
16
|
+
sso: String(import.meta.env.VITE_SSO).toLowerCase() === 'true',
|
|
17
|
+
};
|
|
18
|
+
setTriAppConfig(config);
|
|
19
|
+
return getTriAppConfig();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Production: create config based on current location
|
|
23
|
+
// Extract the app path from current URL like tri-dsp does
|
|
24
|
+
const segments = window.location.pathname.split('/').filter(Boolean);
|
|
25
|
+
let appPath = '/';
|
|
26
|
+
if (segments[0] === 'app' && segments[1]) {
|
|
27
|
+
appPath = `/app/${segments[1]}/`;
|
|
28
|
+
}
|
|
29
|
+
// Assume view name matches exposed name valid for standard deployments
|
|
30
|
+
const viewName = segments[1] || 'unknownView';
|
|
31
|
+
|
|
32
|
+
const config: TriAppConfig = {
|
|
33
|
+
instanceId: "-1",
|
|
34
|
+
tririgaUrl: window.location.origin,
|
|
35
|
+
contextPath: "/app",
|
|
36
|
+
modelAndView: viewName,
|
|
37
|
+
appPath: appPath,
|
|
38
|
+
appExposedName: viewName,
|
|
39
|
+
sso: false
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
setTriAppConfig(config);
|
|
43
|
+
return getTriAppConfig();
|
|
44
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Temporary ambient module declarations for @tririga/tririga-react-components
|
|
2
|
+
// Extend / refine as needed once official types are available.
|
|
3
|
+
|
|
4
|
+
declare module '@tririga/tririga-react-components' {
|
|
5
|
+
import { ComponentType, ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
export interface TriAppConfig {
|
|
8
|
+
instanceId: string;
|
|
9
|
+
tririgaUrl: string;
|
|
10
|
+
contextPath: string;
|
|
11
|
+
modelAndView: string;
|
|
12
|
+
appPath?: string;
|
|
13
|
+
appExposedName?: string;
|
|
14
|
+
sso?: boolean;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type TriCallback = (err: any) => void;
|
|
19
|
+
|
|
20
|
+
export class TriModel {
|
|
21
|
+
constructor(modelAndView: string, instanceId: string, onError?: TriCallback);
|
|
22
|
+
getRecord(dsName: string, query?: Record<string, any>): Promise<any>;
|
|
23
|
+
// Add any other methods you use later
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function fetchTriAppConfig(): Promise<TriAppConfig>;
|
|
27
|
+
export function setTriAppConfig(config: TriAppConfig): void;
|
|
28
|
+
export function getTriAppConfig(): TriAppConfig;
|
|
29
|
+
export function standardTririgaLogin(): Promise<any>;
|
|
30
|
+
export function getAuthCheckerForCurrentApp(): Promise<any>;
|
|
31
|
+
|
|
32
|
+
// TriImage Component
|
|
33
|
+
export interface TriImageProps {
|
|
34
|
+
value?: string | object;
|
|
35
|
+
sizing?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
36
|
+
className?: string;
|
|
37
|
+
width?: string | number;
|
|
38
|
+
height?: string | number;
|
|
39
|
+
alt?: string;
|
|
40
|
+
}
|
|
41
|
+
export const TriImage: ComponentType<TriImageProps>;
|
|
42
|
+
|
|
43
|
+
// TriFloorPlan Component
|
|
44
|
+
export interface TriFloorPlanPlugin {
|
|
45
|
+
type: string;
|
|
46
|
+
id: string;
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface TriFloorPlanProps {
|
|
51
|
+
floorPlanId: number | null;
|
|
52
|
+
plugins?: TriFloorPlanPlugin[];
|
|
53
|
+
svgAriaLabel?: string;
|
|
54
|
+
spaceLayer?: string;
|
|
55
|
+
onFloorPlanLoadError?: (error: any) => void;
|
|
56
|
+
onViewportChange?: (viewport: any) => void;
|
|
57
|
+
}
|
|
58
|
+
export const TriFloorPlan: ComponentType<TriFloorPlanProps>;
|
|
59
|
+
export const TriFloorPlanSkeleton: ComponentType<{}>;
|
|
60
|
+
|
|
61
|
+
// TriFloorPlan Plugins
|
|
62
|
+
export class TriZoomPlugin {
|
|
63
|
+
static type: string;
|
|
64
|
+
}
|
|
65
|
+
export class TriPanPlugin {
|
|
66
|
+
static type: string;
|
|
67
|
+
}
|
|
68
|
+
export class TriHighlightPlugin {
|
|
69
|
+
static type: string;
|
|
70
|
+
}
|
|
71
|
+
export class TriSelectablePlugin {
|
|
72
|
+
static type: string;
|
|
73
|
+
}
|
|
74
|
+
export class TriLabelsPlugin {
|
|
75
|
+
static type: string;
|
|
76
|
+
}
|
|
77
|
+
export class TriNavPlugin {
|
|
78
|
+
static type: string;
|
|
79
|
+
}
|
|
80
|
+
export class TriPinPlugin {
|
|
81
|
+
static type: string;
|
|
82
|
+
}
|
|
83
|
+
export class TriDropablePlugin {
|
|
84
|
+
static type: string;
|
|
85
|
+
}
|
|
86
|
+
export class TriLastPositionPlugin {
|
|
87
|
+
static type: string;
|
|
88
|
+
}
|
|
89
|
+
export class TriLayersPlugin {
|
|
90
|
+
static type: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// TriFloorPlanAPI
|
|
94
|
+
export const TriFloorPlanAPI: {
|
|
95
|
+
getFloorplanId(floorId: string | number): Promise<number | null>;
|
|
96
|
+
getFloorplan(floorplanId: number): Promise<string | null>;
|
|
97
|
+
cacheFloorplan(floorplanId: number, floorplan: string): void;
|
|
98
|
+
[key: string]: any;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// TriLoginApi
|
|
102
|
+
export const TriLoginApi: {
|
|
103
|
+
login(): Promise<void>;
|
|
104
|
+
logout(): Promise<void>;
|
|
105
|
+
[key: string]: any;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["DOM", "DOM.Iterable", "ES2022"],
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"allowSyntheticDefaultImports": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"module": "ESNext",
|
|
13
|
+
"moduleResolution": "Bundler",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
"jsx": "react-jsx"
|
|
18
|
+
},
|
|
19
|
+
"include": ["src"],
|
|
20
|
+
"references": []
|
|
21
|
+
}
|