diff --git a/modules/web/.editorconfig b/modules/web/.editorconfig new file mode 100644 index 0000000..47c5c7c --- /dev/null +++ b/modules/web/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +tab_width = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab diff --git a/modules/web/.eslintignore b/modules/web/.eslintignore new file mode 100644 index 0000000..8d7d7c7 --- /dev/null +++ b/modules/web/.eslintignore @@ -0,0 +1,10 @@ +dist/ +build/ +cypress/ +jest/ +scripts/ +node_modules/ +jest.config.js +babel.config.js +.eslintrc.js +locales/ diff --git a/modules/web/.eslintrc.js b/modules/web/.eslintrc.js new file mode 100644 index 0000000..16f6e0e --- /dev/null +++ b/modules/web/.eslintrc.js @@ -0,0 +1,20 @@ +// http://eslint.org/docs/user-guide/configuring + +const path = require('path'); + +const resolve = dir => path.resolve(__dirname, dir); + +module.exports = { + root: true, + parserOptions: { + project: ['./tsconfig.json'], + }, + extends: ['kubesphere'], + settings: { + 'import/resolver': { + webpack: { + config: resolve('node_modules/@ks-console/bootstrap/webpack/webpack.base.conf.js'), + }, + }, + }, +}; diff --git a/modules/web/.gitignore b/modules/web/.gitignore new file mode 100644 index 0000000..3f57711 --- /dev/null +++ b/modules/web/.gitignore @@ -0,0 +1,50 @@ +# macOS +.DS_Store + +# JetBrains +.idea/ + +# Visual Studio Code +.vscode/* +## Local History for Visual Studio Code +.history/ + +# Node.js +**/node_modules/ +.yalc/ +yalc.lock + +# Yarn +.yarn/* +!.yarn/releases +!.yarn/patches +!.yarn/plugins +!.yarn/sdks +!.yarn/versions + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Config +configs/local_config.yaml + +# TypeScript +*.tsbuildinfo + +# Testing +coverage/ + +# Production +**/dist/ +**/cjs/ +**/esm/ + +# Cache +*.rdb +.cache-loader diff --git a/modules/web/.nvmrc b/modules/web/.nvmrc new file mode 100644 index 0000000..b6a7d89 --- /dev/null +++ b/modules/web/.nvmrc @@ -0,0 +1 @@ +16 diff --git a/modules/web/.prettierignore b/modules/web/.prettierignore new file mode 100644 index 0000000..b0acd8d --- /dev/null +++ b/modules/web/.prettierignore @@ -0,0 +1,8 @@ +.git/ +.history/ +**/node_modules/ +**/dist/ +**/v3dist/ +**/*.tsbuildinfo +yarn.lock +package-lock.json diff --git a/modules/web/README.md b/modules/web/README.md new file mode 100644 index 0000000..e69de29 diff --git a/modules/web/babel.config.js b/modules/web/babel.config.js new file mode 100644 index 0000000..66e1153 --- /dev/null +++ b/modules/web/babel.config.js @@ -0,0 +1,69 @@ +module.exports = { + sourceType: 'unambiguous', + presets: [ + [ + '@babel/preset-env', + { + modules: false, + }, + ], + '@babel/preset-react', + ], + plugins: [ + '@babel/plugin-transform-runtime', + // 'lodash', + '@babel/plugin-syntax-dynamic-import', + '@babel/plugin-syntax-import-meta', + ['@babel/plugin-proposal-decorators', { legacy: true }], + ['@babel/plugin-proposal-class-properties', { loose: true }], + ['@babel/plugin-proposal-private-methods', { loose: true }], + ['@babel/plugin-proposal-private-property-in-object', { loose: true }], + '@babel/plugin-proposal-json-strings', + '@babel/plugin-proposal-function-sent', + '@babel/plugin-proposal-export-namespace-from', + '@babel/plugin-proposal-numeric-separator', + '@babel/plugin-proposal-throw-expressions', + '@babel/plugin-proposal-export-default-from', + '@babel/plugin-proposal-logical-assignment-operators', + '@babel/plugin-proposal-optional-chaining', + [ + '@babel/plugin-proposal-pipeline-operator', + { + proposal: 'minimal', + }, + ], + '@babel/plugin-proposal-nullish-coalescing-operator', + '@babel/plugin-proposal-do-expressions', + 'babel-plugin-styled-components', + ], + env: { + production: { + plugins: [ + [ + 'transform-react-remove-prop-types', + { + removeImport: true, + ignoreFilenames: ['node_modules'], + }, + ], + ], + }, + publish: { + presets: [ + [ + '@babel/preset-env', + { + targets: { + browsers: ['> 1%', 'last 2 versions', 'not ie <= 8'], + }, + }, + ], + '@babel/preset-react', + ], + plugins: ['@babel/plugin-proposal-object-rest-spread'], + }, + test: { + presets: ['@babel/preset-env', '@babel/preset-react'], + }, + }, +}; diff --git a/modules/web/configs/config.yaml b/modules/web/configs/config.yaml new file mode 100644 index 0000000..e69de29 diff --git a/modules/web/configs/webpack.config.js b/modules/web/configs/webpack.config.js new file mode 100644 index 0000000..e69de29 diff --git a/modules/web/configs/webpack.extensions.config.js b/modules/web/configs/webpack.extensions.config.js new file mode 100644 index 0000000..e69de29 diff --git a/modules/web/extensions/karmada-dashboard-ui/Dockerfile b/modules/web/extensions/karmada-dashboard-ui/Dockerfile new file mode 100644 index 0000000..50b393f --- /dev/null +++ b/modules/web/extensions/karmada-dashboard-ui/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx:alpine + +COPY dist /usr/share/nginx/html/dist/karmada-dashboard-ui-frontend diff --git a/modules/web/extensions/karmada-dashboard-ui/README.md b/modules/web/extensions/karmada-dashboard-ui/README.md new file mode 100644 index 0000000..02e2f91 --- /dev/null +++ b/modules/web/extensions/karmada-dashboard-ui/README.md @@ -0,0 +1,5 @@ +# karmada-dashboard-ui + +Hello karmada-dashboard-ui + +> TODO: README diff --git a/modules/web/extensions/karmada-dashboard-ui/package.json b/modules/web/extensions/karmada-dashboard-ui/package.json new file mode 100644 index 0000000..7bafcd5 --- /dev/null +++ b/modules/web/extensions/karmada-dashboard-ui/package.json @@ -0,0 +1,12 @@ +{ + "name": "karmada-dashboard-ui", + "version": "1.0.0", + "private": true, + "description": "Hello karmada-dashboard-ui", + "homepage": "", + "author": "", + "main": "dist/index.js", + "files": [ + "dist" + ] +} diff --git a/modules/web/extensions/karmada-dashboard-ui/src/App.tsx b/modules/web/extensions/karmada-dashboard-ui/src/App.tsx new file mode 100644 index 0000000..c1a01f1 --- /dev/null +++ b/modules/web/extensions/karmada-dashboard-ui/src/App.tsx @@ -0,0 +1,86 @@ +import React, { useRef, useEffect, useState } from 'react'; +// import styled from 'styled-components'; +import { Loading } from '@kubed/components'; +import { useCheckWindows, CustomEventData } from './utils/iframe'; +import { karmadaServiceUrl } from './utils/constants'; +import { useFetchToken } from './utils/request'; +import { tokenUrl } from './utils/constants'; +import { notify } from '@kubed/components'; +// import { useWinState } from './utils/winState'; + +export default function App() { + const iframeRef = useRef(null); + // const [newWindow, setNewWindow] = useState(null); + // const [newWindow] = useWinState(); + + const [loading, setLoading] = useState(true); + const { isIframeReady, postMessageToIframe } = useCheckWindows(iframeRef); + const { token, fetchLoading, error } = useFetchToken(tokenUrl, ''); + + // const openNewWindow = () => { + // const win = window.open(karmadaServiceUrl, '_blank'); + // if (win) { + // setNewWindow(win); + // setTimeout(() => { + // }, 300); + // } else { + // notify.error("Failed to open new window"); + // } + // }; + + // useEffect(() => { + // openNewWindow(); + // }, []) + + const onIframeLoad = () => { + setLoading(false); + }; + + useEffect(() => { + if (!isIframeReady || fetchLoading || loading) return; + if (error || !token) { + notify.error('fetch token failed for iframe'); + return; + } + const tokenMessage: CustomEventData = { + action: 'token', + payload: { + token, + }, + }; + postMessageToIframe(tokenMessage); + }, [isIframeReady, loading, token, fetchLoading, error]); + + // useEffect(() => { + // if (!isWindowReady || fetchLoading || !newWindow) return; + // if (error || !token) { + // notify.error('fetch token failed for new window'); + // return; + // } + // const tokenMessage: CustomEventData = { + // action: 'token', + // payload: { + // token, + // }, + // }; + // newWindow.postMessage(tokenMessage, karmadaServiceUrl); + // }, [isWindowReady, token, fetchLoading, error, newWindow]); + + return ( + <> + {loading && } +