Skip to content

Commit

Permalink
[frontend] Refactor left menu and align linting with OpenCTI
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine committed Dec 6, 2023
1 parent 759f3ae commit 4c8020d
Show file tree
Hide file tree
Showing 196 changed files with 74,631 additions and 6,673 deletions.
3 changes: 1 addition & 2 deletions openex-front/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/node_modules
/coverage
/packages
/build
/public
/builder/dev/build
/builder/prod/build
/src/static/ext/*
__generated__
75 changes: 75 additions & 0 deletions openex-front/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
module.exports = {
extends: [
'airbnb-base',
'airbnb-typescript/base',
'plugin:import/typescript',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
],
parserOptions: {
ecmaVersion: 2020,
project: './tsconfig.json',
tsconfigRootDir: __dirname,
parser: '@typescript-eslint/parser'
},
env: {
browser: true,
jest: true
},
overrides: [
{
"files": ["*.jsx", "*.js","*.ts", "*.tsx"]
}
],
ignorePatterns: [
'**/builder/**',
'**/coverage/**',
'**/node_module/**',
'**/packages/**',
'**/src/generated/**',
'**/__generated__/**',
'**/src/static/ext/**',
'jest.config.js',
'jest.setup.js',
'jest.file.transform.js',
'jest.relay.transform.js'
],
plugins: ["custom-rules"],
rules: {
'custom-rules/classes-rule': 1,
'no-restricted-syntax': 0,
'react/no-unused-prop-types': 0,
'react/prop-types': 0,
'max-classes-per-file': ['error', 2],
'object-curly-newline': 'off',
'arrow-body-style': 'off',
'max-len': [
'error', 180, 2, {
'ignoreUrls': true,
'ignoreComments': false,
'ignoreRegExpLiterals': true,
'ignoreStrings': true,
'ignoreTemplateLiterals': true
}
],
'@typescript-eslint/naming-convention': ['error', {
'selector': 'variable',
'format': ['camelCase', 'UPPER_CASE'],
'leadingUnderscore': 'allow',
'trailingUnderscore': 'allow',
'filter': {
'regex': '/([^_]*)/',
'match': true
}
}],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
'argsIgnorePattern': '^_',
'varsIgnorePattern': '^_',
'caughtErrorsIgnorePattern': '^_'
}
]
}
}
182 changes: 81 additions & 101 deletions openex-front/builder/dev/dev.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import express, { static as expressStatic } from 'express';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { context } from 'esbuild';
import { watch } from 'chokidar';
import compression from 'compression';

import path from 'path';
import { fileURLToPath } from 'url';
import express from "express";
import { createProxyMiddleware } from "http-proxy-middleware";
import { readFileSync } from "node:fs";
import fsExtra from "fs-extra/esm";
import path from "node:path";
import { fileURLToPath } from "url";
import esbuild from "esbuild";
import chokidar from "chokidar";
import compression from "compression";

// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const basePath = '';
const basePath = "";
const clients = [];
const buildPath = "./builder/dev/build/";
const debounce = (func, timeout = 500) => {
let timer;
return (...args) => {
Expand All @@ -24,41 +24,54 @@ const debounce = (func, timeout = 500) => {
}, timeout);
};
};
const middleware = (target, ws = true) =>
createProxyMiddleware(basePath + target, {
target: "http://localhost:8080",
changeOrigin: true,
ws,
});

// Start with an initial build
context({
logLevel: 'info',
entryPoints: ['src/index.tsx'],
bundle: true,
banner: {
js: ' (() => new EventSource("http://localhost:3000/dev").onmessage = () => location.reload())();',
},
loader: {
'.js': 'jsx',
'.svg': 'file',
'.png': 'file',
'.woff': 'dataurl',
'.woff2': 'dataurl',
'.ttf': 'dataurl',
'.eot': 'dataurl',
},
assetNames: 'media/[name]-[hash]',
target: ['chrome58'],
minify: false,
keepNames: true,
sourcemap: true,
sourceRoot: 'src',
outdir: 'builder/dev/build',
})
esbuild
.context({
logLevel: "info",
entryPoints: ["src/index.tsx"],
bundle: true,
banner: {
js: ' (() => new EventSource("http://localhost:3000/dev").onmessage = () => location.reload())();',
},
loader: {
".js": "jsx",
".svg": "file",
".png": "file",
".woff": "dataurl",
".woff2": "dataurl",
".ttf": "dataurl",
".eot": "dataurl",
},
assetNames: "[dir]/[name]-[hash]",
target: ["chrome58"],
minify: false,
keepNames: true,
sourcemap: true,
sourceRoot: "src",
outdir: "builder/dev/build",
})
.then(async (builder) => {
await builder.rebuild();
// region Copy public files to build
fsExtra.copySync("./src/static/ext", buildPath + "/static/ext", {
recursive: true,
overwrite: true,
});
// Listen change for hot recompile
watch('src/**/*.{js,jsx,ts,tsx}', {
awaitWriteFinish: true,
ignoreInitial: true,
})
chokidar
.watch("src/**/*.{js,jsx,ts,tsx}", {
awaitWriteFinish: true,
ignoreInitial: true,
})
.on(
'all',
"all",
debounce(() => {
const start = new Date().getTime();
console.log(`[HOT RELOAD] Update of front detected`);
Expand All @@ -69,7 +82,7 @@ context({
console.log(
`[HOT RELOAD] Rebuild done in ${time} ms, updating frontend`,
);
clients.forEach((res) => res.write('data: update\n\n'));
clients.forEach((res) => res.write("data: update\n\n"));
clients.length = 0;
})
.catch((error) => {
Expand All @@ -79,76 +92,43 @@ context({
);
// Start a dev web server
const app = express();
app.set('trust proxy', 1);
app.get('/dev', (req, res) => {
app.get("/dev", (req, res) => {
return clients.push(
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Access-Control-Allow-Origin': '*',
Connection: 'keep-alive',
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
"Access-Control-Allow-Origin": "*",
Connection: "keep-alive",
}),
);
});
app.use(
createProxyMiddleware('/api', {
target: 'http://localhost:8080',
changeOrigin: true,
ws: true,
}),
);
app.use(
createProxyMiddleware('/login', {
target: 'http://localhost:8080',
changeOrigin: true,
ws: true,
}),
);
app.use(
createProxyMiddleware('/login', {
target: 'http://localhost:8080',
changeOrigin: true,
ws: true,
}),
);
app.use(
createProxyMiddleware('/logout', {
target: 'http://localhost:8080',
changeOrigin: true,
ws: true,
}),
);
app.use(
createProxyMiddleware('/oauth2', {
target: 'http://localhost:8080',
changeOrigin: true,
ws: true,
}),
);
app.use(
createProxyMiddleware('/saml2', {
target: 'http://localhost:8080',
changeOrigin: true,
ws: true,
}),
);
app.set("trust proxy", 1);
app.use(compression({}));
app.use(`/css`, expressStatic(join(__dirname, './build')));
app.use(`/js`, expressStatic(join(__dirname, './build')));
app.use(`/media`, expressStatic(join(__dirname, './build/media')));
app.use(middleware("/api"));
app.use(middleware("/login"));
app.use(middleware("/logout"));
app.use(middleware("/oauth2"));
app.use(middleware("/saml2"));
app.use(
`/static`,
expressStatic(join(__dirname, '../public/static')),
basePath + `/static`,
express.static(path.join(__dirname, "./build/static")),
);
app.get('*', (req, res) => {
const data = readFileSync(`${__dirname}/index.html`, 'utf8');
const withOptionValued = data.replace(/%BASE_PATH%/g, basePath);
app.use(`/css`, express.static(path.join(__dirname, "./build")));
app.use(`/js`, express.static(path.join(__dirname, "./build")));
app.get("*", (req, res) => {
const data = readFileSync(`${__dirname}/index.html`, "utf8");
const withOptionValued = data
.replace(/%BASE_PATH%/g, basePath)
.replace(/%APP_TITLE%/g, "OpenEx Dev")
.replace(/%APP_DESCRIPTION%/g, "OpenEx Development platform")
.replace(/%APP_FAVICON%/g, `${basePath}/static/ext/favicon.png`)
.replace(/%APP_MANIFEST%/g, `${basePath}/static/ext/manifest.json`);
res.header(
'Cache-Control',
'admin, no-cache, no-store, must-revalidate',
"Cache-Control",
"private, no-cache, no-store, must-revalidate",
);
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
res.header("Expires", "-1");
res.header("Pragma", "no-cache");
return res.send(withOptionValued);
});
app.listen(3000);
Expand Down
12 changes: 7 additions & 5 deletions openex-front/builder/dev/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<script>window.BASE_PATH = "%BASE_PATH%"</script>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="shortcut icon" href="/static/favicon.png">
<title>OpenEx - Crisis Drills Planning Platform</title>
<script defer="defer" src="/js/index.js"></script>
<title>%APP_TITLE%</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="dеѕсrірtіоn" content="%APP_DESCRIPTION%">
<link id="favicon" rel="shortcut icon" href="%APP_FAVICON%">
<link id="manifest" rel="manifest" href="%APP_MANIFEST%">
<link href="/css/index.css" rel="stylesheet">
</head>
<body>
Expand Down
Loading

0 comments on commit 4c8020d

Please sign in to comment.