Skip to content

Commit 1dce481

Browse files
committed
Merge branch 'release/0.0.1'
2 parents 835a04c + 7547b96 commit 1dce481

File tree

398 files changed

+8276
-10868
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

398 files changed

+8276
-10868
lines changed

illa-design

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
"codemirror": "^5.65.5",
3535
"framer-motion": "^6.3.0",
3636
"i18next": "^21.6.16",
37+
"i18next-browser-languagedetector": "^6.1.4",
3738
"immer": "^9.0.14",
3839
"jshint": "^2.13.4",
3940
"lodash": "^4.17.21",
41+
"qs": "^6.11.0",
4042
"react": "^17.0.2",
4143
"react-custom-scrollbars": "^4.2.1",
4244
"react-dnd": "^16.0.1",
@@ -55,8 +57,7 @@
5557
"tern": "^0.24.3",
5658
"toposort": "^2.0.2",
5759
"use-bus": "^2.5.1",
58-
"uuid": "^8.3.2",
59-
"ws": "^8.7.0"
60+
"uuid": "^8.3.2"
6061
},
6162
"devDependencies": {
6263
"@changesets/changelog-github": "^0.4.2",
@@ -73,6 +74,7 @@
7374
"@testing-library/user-event": "^13.5.0",
7475
"@types/codemirror": "^5.60.5",
7576
"@types/jest": "^27.4.1",
77+
"@types/qs": "^6.9.7",
7678
"@types/react": "^17.0.2",
7779
"@types/react-custom-scrollbars": "^4.0.10",
7880
"@types/react-dom": "^17.0.2",
@@ -86,24 +88,24 @@
8688
"@uiw/react-color-saturation": "^1.0.10",
8789
"@uiw/react-color-swatch": "^1.0.10",
8890
"@vitejs/plugin-react": "^1.3.2",
91+
"chart.js": "^3.7.1",
92+
"chartjs-adapter-moment": "^1.0.0",
93+
"chartjs-plugin-datalabels": "^2.0.0",
8994
"cypress": "^9.5.1",
9095
"husky": "^7.0.4",
9196
"jest": "^27.4.1",
9297
"jest-environment-jsdom": "^27.4.1",
98+
"moment": "^2.29.3",
9399
"prettier": "^2.5.1",
100+
"react-chartjs-2": "^4.1.0",
94101
"sinon": "^13.0.1",
95102
"ts-jest": "^27.1.5",
96103
"turbo": "^1.1.1",
97104
"typescript": "^4.6.3",
98105
"vite": "^2.9.9",
99106
"vite-plugin-chunk-split": "^0.2.2",
100107
"vite-plugin-istanbul": "^2.7.3",
101-
"vite-plugin-svgr": "^2.1.0",
102-
"chart.js": "^3.7.1",
103-
"chartjs-adapter-moment": "^1.0.0",
104-
"chartjs-plugin-datalabels": "^2.0.0",
105-
"react-chartjs-2": "^4.1.0",
106-
"moment": "^2.29.3"
108+
"vite-plugin-svgr": "^2.1.0"
107109
},
108110
"workspaces": [
109111
"src/*",

src/App.tsx

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,39 @@
11
import { css, Global } from "@emotion/react"
2-
import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom"
2+
import { BrowserRouter } from "react-router-dom"
33
import { globalStyle } from "./style"
4-
import { DashboardApps } from "@/page/Dashboard/DashboardApps"
5-
import { DashboardResources } from "@/page/Dashboard/DashboardResources"
6-
import { IllaApp } from "@/page/Dashboard"
7-
import { Editor } from "@/page/App"
8-
import { UserLogin } from "@/page/User"
9-
import { Register } from "@/page/User/Register"
10-
import { Login } from "@/page/User/Login"
11-
import { ResetPassword } from "@/page/User/ResetPassword"
12-
import { Setting } from "@/page/Setting"
13-
import { Page404 } from "@/page/status/404"
14-
import { Page403 } from "@/page/status/403"
15-
import { Page500 } from "@/page/status/500"
16-
import { SettingAccount } from "@/page/Setting/SettingAccount"
17-
import { SettingPassword } from "@/page/Setting/SettingPassword"
18-
import { SettingOthers } from "@/page/Setting/SettingOthers"
194
import { ConfigProvider } from "@illa-design/config-provider"
20-
import "@/i18n/config"
215
import "@/api/base"
22-
import { AxiosInterceptor } from "@/api/AxiosInterceptor"
23-
24-
import { Deploy } from "@/page/Deploy"
256
import { HTML5Backend } from "react-dnd-html5-backend"
267
import { GlobalDataProvider } from "@/page/App/context/globalDataProvider"
278
import { DndProvider } from "react-dnd"
28-
29-
import AuthInit from "./authInit"
309
import { useSelector } from "react-redux"
3110
import {
3211
getCurrentConfigLanguage,
3312
getCurrentTranslateLanguage,
3413
} from "@/redux/currentUser/currentUserSelector"
35-
import i18n from "./i18n/config"
3614
import { useEffect } from "react"
15+
import { ILLARoute } from "@/router"
16+
import { useTranslation } from "react-i18next"
3717

3818
function App() {
3919
const configLanguage = useSelector(getCurrentConfigLanguage)
4020
const currentUserLanguage = useSelector(getCurrentTranslateLanguage)
21+
const { i18n } = useTranslation()
4122

4223
useEffect(() => {
43-
i18n.changeLanguage(currentUserLanguage).then()
24+
if (!!currentUserLanguage) {
25+
i18n.changeLanguage(currentUserLanguage).then()
26+
}
4427
}, [currentUserLanguage])
4528

4629
return (
4730
<BrowserRouter>
4831
<DndProvider backend={HTML5Backend}>
4932
<GlobalDataProvider>
50-
<AxiosInterceptor>
51-
<AuthInit>
52-
<ConfigProvider locale={configLanguage}>
53-
<Global styles={css(globalStyle)} />
54-
<Routes>
55-
<Route path="dashboard" element={<IllaApp />}>
56-
<Route index element={<Navigate to="./apps" />} />
57-
<Route path="apps" element={<DashboardApps />} />
58-
<Route path="resources" element={<DashboardResources />} />
59-
</Route>
60-
<Route path="user" element={<UserLogin />}>
61-
<Route index element={<Navigate to="./login" />} />
62-
<Route path="login" element={<Login />} />
63-
<Route path="register" element={<Register />} />
64-
<Route path="forgotPassword" element={<ResetPassword />} />
65-
</Route>
66-
<Route index element={<Navigate to="/dashboard" />} />
67-
<Route
68-
path="app/:appId/version/:versionId"
69-
element={<Editor />}
70-
/>
71-
<Route path="setting" element={<Setting />}>
72-
<Route index element={<Navigate to="./account" />} />
73-
<Route path="account" element={<SettingAccount />} />
74-
<Route path="password" element={<SettingPassword />} />
75-
<Route path="others" element={<SettingOthers />} />
76-
</Route>
77-
<Route
78-
path="deploy/app/:appId/version/:versionId"
79-
element={<Deploy />}
80-
/>
81-
<Route path="403" element={<Page403 />} />
82-
<Route path="500" element={<Page500 />} />
83-
<Route path="*" element={<Page404 />} />
84-
</Routes>
85-
</ConfigProvider>
86-
</AuthInit>
87-
</AxiosInterceptor>
33+
<ConfigProvider locale={configLanguage}>
34+
<Global styles={css(globalStyle)} />
35+
<ILLARoute />
36+
</ConfigProvider>
8837
</GlobalDataProvider>
8938
</DndProvider>
9039
</BrowserRouter>

src/api/AxiosInterceptor.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/api/base.ts

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,70 @@
11
import Axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios"
2-
import { getLocalStorage } from "@/utils/storage"
2+
import { clearLocalStorage, getLocalStorage } from "@/utils/storage"
3+
import {
4+
addRequestPendingPool,
5+
removeRequestPendingPool,
6+
} from "@/api/helpers/axiosPendingPool"
37

48
export interface Success {
59
status: string // always ok
610
}
711

812
export interface ApiError {
9-
errorCode: string
13+
errorCode: string | number
1014
errorMessage: string
1115
}
12-
16+
// TODO: @aruseito use OOP to create request
1317
const axios = Axios.create({
1418
baseURL: import.meta.env.VITE_API_BASE_URL,
19+
timeout: 10000,
1520
headers: {
1621
"Content-Encoding": "gzip",
1722
"Content-Type": "application/json",
1823
},
1924
})
2025

21-
axios.interceptors.request.use((config) => {
22-
const token = getLocalStorage("token")
23-
if (token) {
24-
config.headers = {
25-
...(config.headers ?? {}),
26-
Authorization: token,
26+
axios.interceptors.request.use(
27+
(config) => {
28+
addRequestPendingPool(config)
29+
const token = getLocalStorage("token")
30+
if (token) {
31+
config.headers = {
32+
...(config.headers ?? {}),
33+
Authorization: token,
34+
}
2735
}
28-
}
29-
return config
30-
})
36+
return config
37+
},
38+
(err) => {
39+
return Promise.reject(err)
40+
},
41+
)
42+
43+
axios.interceptors.response.use(
44+
(response) => {
45+
const { config } = response
46+
removeRequestPendingPool(config)
47+
return response
48+
},
49+
(error: AxiosError) => {
50+
const { response } = error
51+
if (response) {
52+
const { data } = response
53+
// TODO: @aruseito maybe need custom error status,because of we'll have plugin to request other's api
54+
if (data.errorCode === 401) {
55+
clearLocalStorage()
56+
const { pathname } = location
57+
location.href = "/user/login?from=" + pathname || "/"
58+
}
59+
// else if (data.errorCode === 403) {
60+
// location.href = "/403"
61+
// } else if (data.errorCode >= 500) {
62+
// location.href = "/500"
63+
// }
64+
}
65+
return Promise.reject(error)
66+
},
67+
)
3168

3269
export class Api {
3370
static request<RespData, RequestBody = any, ErrorResp = ApiError>(
@@ -58,17 +95,4 @@ export class Api {
5895
}
5996
})
6097
}
61-
62-
static addResponseInterceptor<RespData, RespConfig>(
63-
resInterceptor?: (
64-
value: AxiosResponse<RespData, RespConfig>,
65-
) => RespData | Promise<RespData>,
66-
errInterceptor?: (error: any) => any,
67-
) {
68-
return axios.interceptors.response.use(resInterceptor, errInterceptor)
69-
}
70-
71-
static removeResponseInterceptor(interceptor: number) {
72-
axios.interceptors.response.eject(interceptor)
73-
}
7498
}

src/api/helpers/axiosPendingPool.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { AxiosRequestConfig } from "axios"
2+
import qs from "qs"
3+
4+
let pendingPollMap = new Map<string, (reason?: any) => void>()
5+
6+
export const generateUniqueKey = (config: AxiosRequestConfig) =>
7+
[
8+
config.method,
9+
config.url,
10+
qs.stringify(config.params),
11+
qs.stringify(config.data),
12+
].join("/")
13+
14+
export const clearRequestPendingPool = () => {
15+
pendingPollMap.forEach((cancel) => {
16+
cancel?.()
17+
})
18+
pendingPollMap.clear()
19+
}
20+
21+
export const removeRequestPendingPool = (config: AxiosRequestConfig) => {
22+
const key = generateUniqueKey(config)
23+
if (pendingPollMap.has(key)) {
24+
const cancel = pendingPollMap.get(key)
25+
cancel?.()
26+
pendingPollMap.delete(key)
27+
}
28+
}
29+
30+
export const addRequestPendingPool = (config: AxiosRequestConfig) => {
31+
removeRequestPendingPool(config)
32+
const key = generateUniqueKey(config)
33+
const controller = new AbortController()
34+
config.signal = controller.signal
35+
if (!pendingPollMap.has(key)) {
36+
pendingPollMap.set(key, controller.abort.bind(controller))
37+
}
38+
}

0 commit comments

Comments
 (0)