Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(log-viewer-webui-client): Switch from Webpack to Vite for bundling; Convert the codebase to TypeScript. #645

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bb3f508
Convert log-viewer-webui/client codebase to TypeScript; Update its de…
junhaoliao Dec 26, 2024
ad34028
Add newline to EOF.
junhaoliao Dec 26, 2024
3444981
Rename `define-process-env-node-env` -> `config-node-env` in webpack…
junhaoliao Dec 26, 2024
8b03576
Switch from Webpack to Vite for client bundling.
junhaoliao Dec 29, 2024
4976d95
Update ESLint dependencies and configurations; lint code.
junhaoliao Dec 29, 2024
ff5da99
Fix indent in Taskfile.yml
junhaoliao Dec 29, 2024
7ac39ee
Refactor LOCAL_STORAGE_KEY to use TypeScript enum.
junhaoliao Dec 29, 2024
d0c1443
Enhance TypeScript strictness in tsconfig files.
junhaoliao Dec 29, 2024
a7998e1
Update dependencies in log-viewer-webui client
junhaoliao Jan 11, 2025
d6a224b
Refactor build commands with loop for modularity.
junhaoliao Jan 11, 2025
2c6e393
Add `--emptyOutDir` flag to the vite build command to get rid of the …
junhaoliao Jan 11, 2025
b222fc6
Correct typo in `QUERY_LOADING_STATE_VALUES` docstring - Apply sugges…
junhaoliao Jan 11, 2025
c3b26e2
Add comment to clarify the proxy target address.
junhaoliao Jan 11, 2025
0a3de9e
Update TypeScript configs with stricter linting.
junhaoliao Jan 12, 2025
a85679c
Move `EXTRACT_JOB_TYPE` to `typings/query.ts`. Add docs for `QUERY_JO…
junhaoliao Jan 12, 2025
ca86be9
Ensure root element exists before initializing React app.
junhaoliao Jan 12, 2025
2767de1
Rename and refactor LOCAL_STORAGE_KEY module.
junhaoliao Jan 12, 2025
c345e00
Refactor query parsing with type-safe validation by `@sinclair/typebox`.
junhaoliao Jan 12, 2025
8a29872
Clean up query parameter parsing.
junhaoliao Jan 12, 2025
e434b64
Install eslint-config-yscope @ v1.0.0 and fix linting violations.
junhaoliao Jan 13, 2025
1116797
Enforce "new-cap" ESLint rule and update code accordingly.
junhaoliao Jan 13, 2025
05a51e4
Update package.json to use npm ci for deterministic installs.
junhaoliao Jan 13, 2025
580b215
Update ESLint config to adjust capIsNewExceptions list.
junhaoliao Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,618 changes: 2,009 additions & 1,609 deletions components/log-viewer-webui/client/package-lock.json
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated once y-scope/eslint-config-yscope#3 is merged and a new version is published.

Large diffs are not rendered by default.

85 changes: 64 additions & 21 deletions components/log-viewer-webui/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "log-viewer-webui-client",
"version": "0.1.0",
"description": "",
"main": "src/index.jsx",
"main": "src/index.tsx",
"scripts": {
"build": "webpack --define-process-env-node-env production",
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
"lint:check": "npx eslint --no-eslintrc --config package.json src webpack.config.js",
Expand All @@ -13,33 +13,76 @@
"license": "Apache-2.0",
"type": "module",
"devDependencies": {
"@babel/core": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.26.3",
"@babel/preset-typescript": "^7.26.0",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@typescript-eslint/eslint-plugin": "^8.18.2",
"@typescript-eslint/parser": "^8.18.2",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"babel-loader": "^9.1.3",
"babel-loader": "^9.2.1",
"css-loader": "^7.1.2",
"eslint-config-yscope": "latest",
"html-webpack-plugin": "^5.6.0",
"mini-css-extract-plugin": "^2.9.0",
"react-refresh": "^0.14.2",
"eslint-import-resolver-typescript": "^3.7.0",
"html-webpack-plugin": "^5.6.3",
"mini-css-extract-plugin": "^2.9.2",
"react-refresh": "^0.16.0",
"style-loader": "^4.0.0",
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.1.0"
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1",
"webpack-dev-server": "^5.2.0"
},
"dependencies": {
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@mui/joy": "^5.0.0-beta.51",
"axios": "^1.7.9",
"react": "^19.0.0",
"react-dom": "^19.0.0"
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix React version to use the latest stable release

The specified React version ^19.0.0 doesn't exist yet (current latest is 18.2.0). This will cause installation failures.

Apply this diff to fix the versions:

-    "react": "^19.0.0",
-    "react-dom": "^19.0.0"
+    "react": "^18.2.0",
+    "react-dom": "^18.2.0"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"react": "^19.0.0",
"react-dom": "^19.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"

},
"eslintConfig": {
"root": true,
"extends": [
"yscope/react"
]
},
"dependencies": {
"@emotion/react": "^11.13.0",
"@emotion/styled": "^11.13.0",
"@mui/joy": "^5.0.0-beta.48",
"@types/react": "^18.3.3",
"axios": "^1.7.2",
"react": "^18.3.1",
"react-dom": "^18.3.1"
],
"ignorePatterns": [
"dist/",
"node_modules/"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx"
],
"extends": [
"yscope/typescript"
]
}
],
"rules": {
"no-restricted-imports": [
"error",
{
"paths": [
{
"message": "Please use path imports and name your imports with postfix \"Icon\" to avoid confusions.",
"name": "@mui/icons-material"
}
],
"patterns": [
{
"group": [
"@mui/joy/*",
"!@mui/joy/styles"
],
"message": "Please use the default import from \"@mui/joy\" instead."
}
]
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {CssVarsProvider} from "@mui/joy/styles/CssVarsProvider";
import {CssVarsProvider} from "@mui/joy";

import LOCAL_STORAGE_KEY from "./typings/LOCAL_STORAGE_KEY.js";
import QueryStatus from "./ui/QueryStatus.jsx";
import LOCAL_STORAGE_KEY from "./typings/LOCAL_STORAGE_KEY";
import QueryStatus from "./ui/QueryStatus";


/**
* Renders the main application.
*
* @return {JSX.Element}
* @return
*/
const App = () => {
return (
Expand Down
32 changes: 0 additions & 32 deletions components/log-viewer-webui/client/src/api/query.js

This file was deleted.

46 changes: 46 additions & 0 deletions components/log-viewer-webui/client/src/api/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import axios, {
AxiosProgressEvent,
AxiosResponse,
} from "axios";

import {QUERY_JOB_TYPE} from "../typings/query";


interface ExtractStreamResp {
_id: string,
begin_msg_ix: number,
end_msg_ix: number,
is_last_chunk: boolean,
path: string,
stream_id: string,
}


/**
* Submits a job to extract the stream that contains a given log event. The stream is extracted
* either as a CLP IR or a JSON Lines file.
*
* @param extractJobType
* @param streamId
* @param logEventIdx
* @param onUploadProgress Callback to handle upload progress events.
* @return The API response.
*/
const submitExtractStreamJob = async (
extractJobType: QUERY_JOB_TYPE,
streamId: string,
logEventIdx: number,
onUploadProgress: (progressEvent: AxiosProgressEvent) => void,
): Promise<AxiosResponse<ExtractStreamResp>> => {
return await axios.post(
"/query/extract-stream",
{
extractJobType,
streamId,
logEventIdx,
},
{onUploadProgress}
);
};

export {submitExtractStreamJob};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import App from "./App";
import "./index.css";


const root = createRoot(document.getElementById("root"));
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const root = createRoot(document.getElementById("root")!);
root.render(
<StrictMode>
<App/>
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this file config.ts like log viewer. The caps are a bit out of place.

File renamed without changes.
3 changes: 3 additions & 0 deletions components/log-viewer-webui/client/src/typings/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type Nullable<T> = T | null;

export type {Nullable};
37 changes: 0 additions & 37 deletions components/log-viewer-webui/client/src/typings/query.js

This file was deleted.

50 changes: 50 additions & 0 deletions components/log-viewer-webui/client/src/typings/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
enum QUERY_LOADING_STATE {
SUBMITTING = 0,
WAITING,
LOADING,
}

/**
* Key names in enum `QUERY_LOADING_STATE`.
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved
*/
const QUERY_LOADING_STATE_VALUES = Object.freeze(
Object.values(QUERY_LOADING_STATE).filter((value) => "number" === typeof value)
);

enum QUERY_JOB_TYPE {
SEARCH_OR_AGGREGATION = 0,
EXTRACT_IR,
EXTRACT_JSON,
}

interface QueryLoadingStateDescription {
label: string,
description: string,
}

/**
* Descriptions for query loading states.
*/
const QUERY_LOADING_STATE_DESCRIPTIONS
: Record<QUERY_LOADING_STATE, QueryLoadingStateDescription> =
Object.freeze({
[QUERY_LOADING_STATE.SUBMITTING]: {
label: "Submitting query Job",
description: "Parsing arguments and submitting job to the server.",
},
[QUERY_LOADING_STATE.WAITING]: {
label: "Waiting for job to finish",
description: "The job is running. Waiting for the job to finish.",
},
[QUERY_LOADING_STATE.LOADING]: {
label: "Loading Log Viewer",
description: "The query has been completed and the results are being loaded.",
},
});

export {
QUERY_JOB_TYPE,
QUERY_LOADING_STATE,
QUERY_LOADING_STATE_DESCRIPTIONS,
QUERY_LOADING_STATE_VALUES,
};
Loading
Loading