-
Notifications
You must be signed in to change notification settings - Fork 82
refactor(webui): Move shared types to common workspace. #1289
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
Changes from 6 commits
f3ab2df
7103233
90e72fe
85d27df
0f1b4af
9a60015
f18df92
c09333d
66193a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,22 @@ | ||
import { | ||
type PrestoQueryJob, | ||
type PrestoQueryJobCreation, | ||
} from "@webui/common/schemas/presto-search"; | ||
import axios, {AxiosResponse} from "axios"; | ||
|
||
|
||
// eslint-disable-next-line no-warning-comments | ||
// TODO: Replace with shared type from the `@common` directory once refactoring is completed. | ||
// Currently, server schema types require typebox dependency so they cannot be moved to the | ||
// `@common` directory with current implementation. | ||
type PrestoQueryJobCreationSchema = { | ||
queryString: string; | ||
}; | ||
|
||
type PrestoQueryJobSchema = { | ||
searchJobId: string; | ||
}; | ||
|
||
|
||
/** | ||
* Sends post request to server to submit presto query. | ||
* | ||
* @param payload | ||
* @return | ||
*/ | ||
const submitQuery = async ( | ||
payload: PrestoQueryJobCreationSchema | ||
): Promise<AxiosResponse<PrestoQueryJobSchema>> => { | ||
payload: PrestoQueryJobCreation | ||
): Promise<AxiosResponse<PrestoQueryJob>> => { | ||
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Make submitQuery non-async for consistency and type the axios call. submitQuery is marked async but doesn’t await; other functions here aren’t async. Also, keep the axios generic explicit. Apply: -const submitQuery = async (
- payload: PrestoQueryJobCreation
-): Promise<AxiosResponse<PrestoQueryJob>> => {
+const submitQuery = (
+ payload: PrestoQueryJobCreation
+): Promise<AxiosResponse<PrestoQueryJob>> => {
console.log("Submitting query:", JSON.stringify(payload));
-
- return axios.post<PrestoQueryJob>("/api/presto-search/query", payload);
+ return axios.post<PrestoQueryJob>("/api/presto-search/query", payload);
} Also applies to: 19-19 🤖 Prompt for AI Agents
|
||
console.log("Submitting query:", JSON.stringify(payload)); | ||
|
||
return axios.post<PrestoQueryJobSchema>("/api/presto-search/query", payload); | ||
return axios.post<PrestoQueryJob>("/api/presto-search/query", payload); | ||
}; | ||
|
||
|
||
|
@@ -36,7 +27,7 @@ const submitQuery = async ( | |
* @return | ||
*/ | ||
const cancelQuery = async ( | ||
payload: PrestoQueryJobSchema | ||
payload: PrestoQueryJob | ||
): Promise<AxiosResponse<null>> => { | ||
Comment on lines
+30
to
31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Type the void responses and consider making logging conditional. Add axios generics for null responses; optionally guard logs behind a dev flag to avoid noisy consoles in prod. const cancelQuery = async (
payload: PrestoQueryJob
): Promise<AxiosResponse<null>> => {
console.log("Cancelling query:", JSON.stringify(payload));
- return axios.post("/api/presto-search/cancel", payload);
+ return axios.post<null>("/api/presto-search/cancel", payload);
};
-const clearQueryResults = (payload: PrestoQueryJob): Promise<AxiosResponse<null>> => {
+const clearQueryResults = (payload: PrestoQueryJob): Promise<AxiosResponse<null>> => {
console.log("Clearing query:", JSON.stringify(payload));
- return axios.delete("/api/presto-search/results", {data: payload});
+ return axios.delete<null>("/api/presto-search/results", { data: payload });
}; Also applies to: 34-35, 44-48 🤖 Prompt for AI Agents
|
||
console.log("Cancelling query:", JSON.stringify(payload)); | ||
|
||
|
@@ -50,16 +41,12 @@ const cancelQuery = async ( | |
* @param payload | ||
* @return | ||
*/ | ||
const clearQueryResults = (payload: PrestoQueryJobSchema): Promise<AxiosResponse<null>> => { | ||
const clearQueryResults = (payload: PrestoQueryJob): Promise<AxiosResponse<null>> => { | ||
console.log("Clearing query:", JSON.stringify(payload)); | ||
|
||
return axios.delete("/api/presto-search/results", {data: payload}); | ||
}; | ||
|
||
export type { | ||
PrestoQueryJobCreationSchema, | ||
PrestoQueryJobSchema, | ||
}; | ||
|
||
export { | ||
cancelQuery, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,20 @@ | ||
import { | ||
type QueryJob, | ||
type QueryJobCreation, | ||
} from "@webui/common/schemas/search"; | ||
import axios, {AxiosResponse} from "axios"; | ||
|
||
import {Nullable} from "../../typings/common"; | ||
|
||
|
||
// eslint-disable-next-line no-warning-comments | ||
// TODO: Replace with shared type from the `@common` directory once refactoring is completed. | ||
// Currently, server schema types require typebox dependency so they cannot be moved to the | ||
// `@common` directory with current implementation. | ||
type QueryJobSchema = { | ||
searchJobId: string; | ||
aggregationJobId: string; | ||
}; | ||
|
||
// eslint-disable-next-line no-warning-comments | ||
// TODO: Replace with shared type from the `@common` directory once refactoring is completed. | ||
// Currently, server schema types require typebox dependency so they cannot be moved to the | ||
// `@common` directory with current implementation. | ||
type QueryJobCreationSchema = { | ||
dataset: Nullable<string>; | ||
ignoreCase: boolean; | ||
queryString: string; | ||
timeRangeBucketSizeMillis: number; | ||
timestampBegin: number; | ||
timestampEnd: number; | ||
}; | ||
|
||
/** | ||
* Sends post request to server to submit query. | ||
* | ||
* @param payload | ||
* @return | ||
*/ | ||
const submitQuery = (payload: QueryJobCreationSchema): Promise<AxiosResponse<QueryJobSchema>> => { | ||
const submitQuery = (payload: QueryJobCreation): Promise<AxiosResponse<QueryJob>> => { | ||
console.log("Submitting query:", JSON.stringify(payload)); | ||
|
||
return axios.post<QueryJobSchema>("/api/search/query", payload); | ||
return axios.post<QueryJob>("/api/search/query", payload); | ||
}; | ||
Comment on lines
+14
to
18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Type axios responses for null-returning endpoints. Keep response types explicit to strengthen inference and catch regressions. -const submitQuery = (payload: QueryJobCreation): Promise<AxiosResponse<QueryJob>> => {
+const submitQuery = (payload: QueryJobCreation): Promise<AxiosResponse<QueryJob>> => {
console.log("Submitting query:", JSON.stringify(payload));
- return axios.post<QueryJob>("/api/search/query", payload);
+ return axios.post<QueryJob>("/api/search/query", payload);
};
-const cancelQuery = (payload: QueryJob): Promise<AxiosResponse<null>> => {
+const cancelQuery = (payload: QueryJob): Promise<AxiosResponse<null>> => {
console.log("Cancelling query:", JSON.stringify(payload));
- return axios.post("/api/search/cancel", payload);
+ return axios.post<null>("/api/search/cancel", payload);
};
-const clearQueryResults = (payload: QueryJob): Promise<AxiosResponse<null>> => {
+const clearQueryResults = (payload: QueryJob): Promise<AxiosResponse<null>> => {
console.log("Clearing query:", JSON.stringify(payload));
- return axios.delete("/api/search/results", {data: payload});
+ return axios.delete<null>("/api/search/results", { data: payload });
}; Also applies to: 26-30, 38-42 🤖 Prompt for AI Agents
|
||
|
||
/** | ||
|
@@ -43,7 +23,7 @@ const submitQuery = (payload: QueryJobCreationSchema): Promise<AxiosResponse<Que | |
* @param payload | ||
* @return | ||
*/ | ||
const cancelQuery = (payload: QueryJobSchema): Promise<AxiosResponse<null>> => { | ||
const cancelQuery = (payload: QueryJob): Promise<AxiosResponse<null>> => { | ||
console.log("Cancelling query:", JSON.stringify(payload)); | ||
|
||
return axios.post("/api/search/cancel", payload); | ||
|
@@ -55,15 +35,12 @@ const cancelQuery = (payload: QueryJobSchema): Promise<AxiosResponse<null>> => { | |
* @param payload | ||
* @return | ||
*/ | ||
const clearQueryResults = (payload: QueryJobSchema): Promise<AxiosResponse<null>> => { | ||
const clearQueryResults = (payload: QueryJob): Promise<AxiosResponse<null>> => { | ||
console.log("Clearing query:", JSON.stringify(payload)); | ||
|
||
return axios.delete("/api/search/results", {data: payload}); | ||
}; | ||
export type { | ||
QueryJobCreationSchema, | ||
QueryJobSchema, | ||
}; | ||
|
||
export { | ||
cancelQuery, | ||
clearQueryResults, | ||
|
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {Nullable} from "src/typings/common"; | ||
import {Nullable} from "@webui/common/utility-types"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConfirm Nullable semantics and path resolution Good move to centralize. Please confirm the new Run: 🏁 Script executed: #!/bin/bash
# Find all Nullable definitions
rg -nP --type=ts --type=tsx '\btype\s+Nullable\s*<'
# Find any remaining non-common Nullable imports
rg -nP --type=ts --type=tsx 'import\s*{\s*Nullable\s*}.*from\s*["'\''](?!@webui/common/utility-types)["'\''][^"'\'';]+["'\'']'
# Show configured path mappings
fd -a tsconfig.json | xargs -I{} sh -c 'echo "== {} =="; jq -r ".compilerOptions.paths?[@\"@webui/*\"]? // \"(no mapping)\"" "{}" 2>/dev/null' Length of output: 300 🏁 Script executed: #!/bin/bash
grep -R "type Nullable" -n components/webui
grep -R "import.*Nullable.*from" -n components/webui --include=*.ts --include=*.tsx | grep -v "@webui/common/utility-types"
file=$(find components/webui/common -type f -name 'utility-types.ts' | head -n1)
echo "=== $file ==="
sed -n '1,200p' "$file"
echo "=== client tsconfig ==="
sed -n '1,200p' components/webui/client/tsconfig.json Length of output: 588 🏁 Script executed: #!/bin/bash
sed -n '1,200p' components/webui/client/tsconfig/tsconfig.app.json
sed -n '1,200p' components/webui/client/tsconfig/tsconfig.node.json Length of output: 1019 🏁 Script executed: #!/bin/bash
sed -n '1,200p' components/webui/client/tsconfig/tsconfig.base.json Length of output: 586 Confirm centralized Nullable semantics and add tsconfig path mapping
🤖 Prompt for AI Agents
|
||
|
||
import {settings} from "../../../settings"; | ||
import {COMPRESSION_JOBS_TABLE_COLUMN_NAMES} from "../sqlConfig"; | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,7 +32,7 @@ const handleSubmit = (ev: React.FormEvent<HTMLFormElement>) => { | |||||
const SearchControls = () => { | ||||||
/* eslint-disable-next-line no-warning-comments */ | ||||||
// TODO: Remove flag and related logic when the new guide UI is fully implemented. | ||||||
const isGuidedEnabled = "true" === import.meta.env[`VITE_GUIDED_DEV`]; | ||||||
const isGuidedEnabled = "true" === import.meta.env["VITE_GUIDED_DEV"]; | ||||||
|
const isGuidedEnabled = "true" === import.meta.env["VITE_GUIDED_DEV"]; | |
const isGuidedEnabled = import.meta.env.VITE_GUIDED_DEV === "true"; |
🤖 Prompt for AI Agents
In components/webui/client/src/pages/SearchPage/SearchControls/index.tsx around
line 35, replace the bracket env access with typed dot access and perform an
explicit boolean coercion; specifically, change the current
import.meta.env["VITE_GUIDED_DEV"] usage to import.meta.env.VITE_GUIDED_DEV and
compare it strictly to the string "true" (e.g. import.meta.env.VITE_GUIDED_DEV
=== "true") so the value is typed by Vite and converted to a boolean reliably.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,10 +1,12 @@ | ||||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||||
type QueryJob, | ||||||||||||||||||||||||||||||||||||||||
type QueryJobCreation, | ||||||||||||||||||||||||||||||||||||||||
} from "@webui/common/schemas/search"; | ||||||||||||||||||||||||||||||||||||||||
import {message} from "antd"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||||
cancelQuery, | ||||||||||||||||||||||||||||||||||||||||
clearQueryResults, | ||||||||||||||||||||||||||||||||||||||||
QueryJobCreationSchema, | ||||||||||||||||||||||||||||||||||||||||
QueryJobSchema, | ||||||||||||||||||||||||||||||||||||||||
submitQuery, | ||||||||||||||||||||||||||||||||||||||||
} from "../../../api/search"; | ||||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||||
|
@@ -40,7 +42,10 @@ const handleClearResults = () => { | |||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
clearQueryResults( | ||||||||||||||||||||||||||||||||||||||||
{searchJobId, aggregationJobId} | ||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||
searchJobId: Number(searchJobId), | ||||||||||||||||||||||||||||||||||||||||
aggregationJobId: Number(aggregationJobId), | ||||||||||||||||||||||||||||||||||||||||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
).catch((err: unknown) => { | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
44
to
49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate numeric ID conversions to avoid NaN payloads. - clearQueryResults(
- {
- searchJobId: Number(searchJobId),
- aggregationJobId: Number(aggregationJobId),
- }
- ).catch((err: unknown) => {
+ const sj = Number(searchJobId);
+ const aj = Number(aggregationJobId);
+ if (false == Number.isFinite(sj) || false == Number.isFinite(aj)) {
+ console.error("Cannot clear results: job IDs are not valid numbers.", {
+ searchJobId,
+ aggregationJobId,
+ });
+ return;
+ }
+ clearQueryResults({searchJobId: sj, aggregationJobId: aj}).catch((err: unknown) => {
console.error("Failed to clear query results:", err);
}); 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||
console.error("Failed to clear query results:", err); | ||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||
|
@@ -51,7 +56,7 @@ const handleClearResults = () => { | |||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||
* @param payload | ||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||
const handleQuerySubmit = (payload: QueryJobCreationSchema) => { | ||||||||||||||||||||||||||||||||||||||||
const handleQuerySubmit = (payload: QueryJobCreation) => { | ||||||||||||||||||||||||||||||||||||||||
const store = useSearchStore.getState(); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
// User should NOT be able to submit a new query while an existing query is in progress. | ||||||||||||||||||||||||||||||||||||||||
|
@@ -95,8 +100,8 @@ const handleQuerySubmit = (payload: QueryJobCreationSchema) => { | |||||||||||||||||||||||||||||||||||||||
submitQuery(payload) | ||||||||||||||||||||||||||||||||||||||||
.then((result) => { | ||||||||||||||||||||||||||||||||||||||||
const {searchJobId, aggregationJobId} = result.data; | ||||||||||||||||||||||||||||||||||||||||
store.updateSearchJobId(searchJobId); | ||||||||||||||||||||||||||||||||||||||||
store.updateAggregationJobId(aggregationJobId); | ||||||||||||||||||||||||||||||||||||||||
store.updateSearchJobId(searchJobId.toString()); | ||||||||||||||||||||||||||||||||||||||||
store.updateAggregationJobId(aggregationJobId.toString()); | ||||||||||||||||||||||||||||||||||||||||
store.updateSearchUiState(SEARCH_UI_STATE.QUERYING); | ||||||||||||||||||||||||||||||||||||||||
console.debug( | ||||||||||||||||||||||||||||||||||||||||
"Search job created - ", | ||||||||||||||||||||||||||||||||||||||||
|
@@ -116,7 +121,7 @@ const handleQuerySubmit = (payload: QueryJobCreationSchema) => { | |||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||
* @param payload | ||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||
const handleQueryCancel = (payload: QueryJobSchema) => { | ||||||||||||||||||||||||||||||||||||||||
const handleQueryCancel = (payload: QueryJob) => { | ||||||||||||||||||||||||||||||||||||||||
const store = useSearchStore.getState(); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if (store.searchUiState !== SEARCH_UI_STATE.QUERYING) { | ||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Nit: restrict the exemption to PascalCase members
Prevents accidentally exempting non-factory members.
📝 Committable suggestion
🤖 Prompt for AI Agents