Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

chore: merge important refactor from origin main

haitao(lj)6e0942cc16ce
diff --cc i18n/en_US.yaml
index 78f438b1,f3fe2602..f09bdb40
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@@ -893,8 -906,12 +906,12 @@@ ui
installed_description: >-
You appear to have already installed. To reinstall please clear your old
database tables first.
+ db_failed: Database connection failed
+ db_failed_description: >-
+ This either means that the database information in your <1>config.yaml</1> file is incorrect or that contact with the database server could not be established. This could mean your host’s database server is down.
+
page_404:
- description: 'Unfortunately, this page doesn''t exist.'
+ description: "Unfortunately, this page doesn't exist."
back_home: Back to homepage
page_50X:
description: The server encountered an error and could not complete your request.
diff --cc ui/config-overrides.js
index f1bec311,0a5deeff..3d70e9e4
--- a/ui/config-overrides.js
+++ b/ui/config-overrides.js
@@@ -1,46 -1,49 +1,45 @@@
- const path = require('path');
- const i18nLocaleTool = require('./scripts/i18n-locale-tool');
+ const {
+ addWebpackModuleRule,
+ addWebpackAlias
+ } = require("customize-cra");
+
+ const path = require("path");
+ const i18nPath = path.resolve(__dirname, "../i18n");
module.exports = {
- webpack: function (config, env) {
- if (env === 'production') {
- i18nLocaleTool.resolvePresetLocales();
- }
+ webpack: function(config, env) {
- if (env === "production") {
- config.output.publicPath = process.env.REACT_APP_PUBLIC_PATH;
- }
-
+ addWebpackAlias({
- ["@"]: path.resolve(__dirname, "src"),
++ "@": path.resolve(__dirname, "src"),
+ "@i18n": i18nPath
+ })(config);
- for (let _rule of config.module.rules) {
- if (_rule.oneOf) {
- _rule.oneOf.unshift({
- test: /\.ya?ml$/,
- use: 'yaml-loader'
- });
- break;
- }
- }
+ addWebpackModuleRule({
+ test: /\.ya?ml$/,
+ use: "yaml-loader"
+ })(config);
- config.resolve.alias = {
- ...config.resolve.alias,
- '@': path.resolve(__dirname, 'src'),
- };
+ // add i18n dir to ModuleScopePlugin allowedPaths
+ const moduleScopePlugin = config.resolve.plugins.find(_ => _.constructor.name === "ModuleScopePlugin");
+ if (moduleScopePlugin) {
+ moduleScopePlugin.allowedPaths.push(i18nPath);
+ }
return config;
},
-
- devServer: function (configFunction) {
- i18nLocaleTool.autoSync();
-
- return function (proxy, allowedHost) {
+ devServer: function(configFunction) {
+ return function(proxy, allowedHost) {
const config = configFunction(proxy, allowedHost);
config.proxy = {
- "/answer": {
- target: "http://10.0.10.98:2060",
+ '/answer': {
+ target: process.env.REACT_APP_API_URL,
changeOrigin: true,
- secure: false
+ secure: false,
},
- "/installation": {
- target: "http://10.0.10.98:2060",
+ '/installation': {
+ target: process.env.REACT_APP_API_URL,
changeOrigin: true,
- secure: false
- }
+ secure: false,
+ },
};
return config;
};
diff --cc ui/package.json
index e7dfbe13,c09fac27..51baaa06
--- a/ui/package.json
+++ b/ui/package.json
@@@ -5,12 -5,26 +5,13 @@@
"homepage": "/",
"scripts": {
"start": "react-app-rewired start",
- "build:dev": "env-cmd -f .env.development react-app-rewired build",
- "build:test": "env-cmd -f .env.test react-app-rewired build",
- "build:prod": "env-cmd -f .env.production react-app-rewired build",
- "build": "env-cmd -f .env react-app-rewired build",
- "test": "react-app-rewired test",
+ "build": "react-app-rewired build",
"lint": "eslint . --cache --fix --ext .ts,.tsx",
- "prepare": "cd .. && husky install",
- "cz": "cz",
- "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
+ "prettier": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
+ "prepare": "cd .. && husky install",
- "prettier": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\""
+ "preinstall": "node ./scripts/preinstall.js"
},
- "config": {
- "commitizen": {
- "path": "ui/node_modules/cz-conventional-changelog"
- }
- },
"dependencies": {
- "@testing-library/jest-dom": "^4.2.4",
- "ahooks": "^3.7.0",
"axios": "^0.27.2",
"bootstrap": "^5.2.0",
"bootstrap-icons": "^1.9.1",
@@@ -53,8 -74,11 +54,7 @@@
"@types/react-helmet": "^6.1.5",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.33.0",
- "chokidar": "^3.5.3",
- "commitizen": "^4.2.5",
- "conventional-changelog-cli": "^2.2.2",
"customize-cra": "^1.0.0",
- "cz-conventional-changelog": "^3.3.0",
- "env-cmd": "^10.1.0",
"eslint": "^8.0.1",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
diff --cc ui/pnpm-lock.yaml
index 0f86f268,98ebd589..c0bad184
--- a/ui/pnpm-lock.yaml
+++ b/ui/pnpm-lock.yaml
@@@ -20,12 -25,16 +20,11 @@@ specifiers
axios: ^0.27.2
bootstrap: ^5.2.0
bootstrap-icons: ^1.9.1
- chokidar: ^3.5.3
classnames: ^2.3.1
codemirror: 5.65.0
- commitizen: ^4.2.5
- conventional-changelog-cli: ^2.2.2
copy-to-clipboard: ^3.3.2
customize-cra: ^1.0.0
- cz-conventional-changelog: ^3.3.0
dayjs: ^1.11.5
- env-cmd: ^10.1.0
eslint: ^8.0.1
eslint-config-airbnb: ^19.0.4
eslint-config-airbnb-typescript: ^17.0.0
@@@ -107,8 -132,11 +106,7 @@@ devDependencies
'@types/react-helmet': 6.1.5
'@typescript-eslint/eslint-plugin': 5.38.0_wsb62dxj2oqwgas4kadjymcmry
'@typescript-eslint/parser': 5.38.0_irgkl5vooow2ydyo6aokmferha
- chokidar: 3.5.3
- commitizen: 4.2.5
- conventional-changelog-cli: 2.2.2
customize-cra: 1.0.0
- cz-conventional-changelog: 3.3.0
- env-cmd: 10.1.0
eslint: 8.23.1
eslint-config-airbnb: 19.0.4_4zstfqq5uopk5xuvotejlnl36y
eslint-config-airbnb-typescript: 17.0.0_j57hrpt2hfp47otngkwtnuyxpa
diff --cc ui/scripts/preinstall.js
index 00000000,076ad606..2faddacf
mode 000000,100644..100644
--- a/ui/scripts/preinstall.js
+++ b/ui/scripts/preinstall.js
@@@ -1,0 -1,5 +1,7 @@@
+ // There is a bug when using npm to install: the execution of preinstall is after install, so when this prompt is displayed, the dependent packages have already been installed.
+ if (!/pnpm/.test(process.env.npm_execpath)) {
- console.warn(`\u001b[33mThis repository requires using pnpm as the package manager for scripts to work properly.\u001b[39m\n`)
- process.exit(1)
-}
++ console.warn(
++ `\u001b[33mThis repository requires using pnpm as the package manager for scripts to work properly.\u001b[39m\n`,
++ );
++ process.exit(1);
++}
diff --cc ui/src/i18n/init.ts
index 0ee63bf5,ec4bf378..ad88c161
--- a/ui/src/i18n/init.ts
+++ b/ui/src/i18n/init.ts
@@@ -1,12 -1,15 +1,12 @@@
import { initReactI18next } from 'react-i18next';
import i18next from 'i18next';
-import Backend from 'i18next-http-backend';
+ import en_US from '@i18n/en_US.yaml';
+ import zh_CN from '@i18n/zh_CN.yaml';
import { DEFAULT_LANG } from '@/common/constants';
- import en_US from '@/i18n/locales/en_US.yaml';
- import zh_CN from '@/i18n/locales/zh_CN.yaml';
i18next
- // load translation using http
- .use(Backend)
// pass the i18n instance to react-i18next.
.use(initReactI18next)
.init({
diff --cc ui/src/utils/common.ts
index 16650e0c,2f846382..248c4bed
--- a/ui/src/utils/common.ts
+++ b/ui/src/utils/common.ts
@@@ -79,7 -86,24 +79,23 @@@ function formatUptime(value)
return `< 1 ${t('dates.hour')}`;
}
+ function escapeRemove(str) {
+ if (!str || typeof str !== 'string') return str;
+ const arrEntities = {
+ lt: '<',
+ gt: '>',
+ nbsp: ' ',
+ amp: '&',
+ quot: '"',
+ '#39': "'",
+ };
+
+ return str.replace(/&(lt|gt|nbsp|amp|quot|#39);/gi, function (all, t) {
+ return arrEntities[t];
+ });
+ }
+
export {
- getQueryString,
thousandthDivision,
formatCount,
scrollTop,
diff --cc ui/tsconfig.json
index 3cfbea32,afe1b5b9..c6e49931
--- a/ui/tsconfig.json
+++ b/ui/tsconfig.json
@@@ -19,8 -20,9 +19,9 @@@
"jsx": "react-jsx",
"baseUrl": "./",
"paths": {
- "@/*": ["src/*"]
+ "@/*": ["src/*"],
+ "@i18n/*": ["../i18n/*"]
}
},
- "include": ["src", "node_modules/@testing-library/jest-dom", "scripts"]
- "include": ["src", "node_modules/@testing-library/jest-dom" ]
++ "include": ["src", "node_modules/@testing-library/jest-dom", "scripts" ]
}