refactor(frontend): normalize naming conventions

This commit is contained in:
2026-06-13 13:07:16 +08:00
parent 6ff8886524
commit 0dea655f68
30 changed files with 87 additions and 33 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
import type { Metadata } from "next";
import { cookies } from "next/headers";
import React, { Suspense } from "react";
import { RefineContext } from "./_refine_context";
import { RefineContext } from "./RefineContext";
import { META_DATA } from "@config/config";
export const metadata: Metadata = META_DATA;
+1 -1
View File
@@ -23,7 +23,7 @@ import {
type ContentSegment,
} from "./chatMessageSections";
import type { Message, SpeechState } from "./GlobalChatbox.types";
import { stripMarkdown } from "./GlobalChatbox.utils";
import { stripMarkdown } from "./globalChatboxUtils";
import { AgentProgressTimeline } from "./AgentProgressTimeline";
import { ChartGenerationSkeleton, ChatInlineChart } from "./ChatInlineChart";
import { ChatToolCallBlock } from "./ChatToolCallBlock";
+3 -3
View File
@@ -17,10 +17,10 @@ import { AgentComposer, type AgentComposerHandle } from "./AgentComposer";
import { AgentHeader } from "./AgentHeader";
import { AgentHistoryPanel } from "./AgentHistoryPanel";
import { AgentWorkspace } from "./AgentWorkspace";
import { Blob } from "./GlobalChatbox.parts";
import { Blob } from "./GlobalChatboxParts";
import type { Props } from "./GlobalChatbox.types";
import { PRESET_PROMPTS } from "./GlobalChatbox.utils";
import { useSpeechRecognition, useSpeechSynthesis } from "./GlobalChatbox.voice";
import { PRESET_PROMPTS } from "./globalChatboxUtils";
import { useSpeechRecognition, useSpeechSynthesis } from "./globalChatboxVoice";
import { useAgentChatSession } from "./hooks/useAgentChatSession";
import { useAgentToolActions } from "./hooks/useAgentToolActions";
+1 -1
View File
@@ -6,7 +6,7 @@ import type {
LoadedChatState,
Message,
} from "./GlobalChatbox.types";
import { cloneMessages } from "./GlobalChatbox.utils";
import { cloneMessages } from "./globalChatboxUtils";
type BackendSessionPayload = {
id?: string;
@@ -1,4 +1,4 @@
import { cloneMessage } from "./GlobalChatbox.utils";
import { cloneMessage } from "./globalChatboxUtils";
import type { Message } from "./GlobalChatbox.types";
describe("cloneMessage", () => {
@@ -9,7 +9,7 @@ import type {
ChatProgress,
Message,
} from "../GlobalChatbox.types";
import { createId } from "../GlobalChatbox.utils";
import { createId } from "../globalChatboxUtils";
export const upsertProgress = (
progress: ChatProgress[] | undefined,
@@ -1,2 +0,0 @@
// Tests for useAgentChatSession are split by behavior boundary.
// See useAgentChatSession.lifecycle.test.tsx and useAgentChatSession.actions.test.tsx.
@@ -5,7 +5,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
import { abortAgentChat, forkAgentChat, rejectAgentQuestion, replyAgentPermission, replyAgentQuestion, resumeAgentChatStream, streamAgentChat } from "@/lib/chatStream";
import type { PermissionReply, StreamEvent } from "@/lib/chatStream";
import type { AgentArtifact, ChatSessionSummary, Message } from "../GlobalChatbox.types";
import { cloneMessages } from "../GlobalChatbox.utils";
import { cloneMessages } from "../globalChatboxUtils";
import { createEmptyChatState, deleteChatSession, listChatSessions, loadChatSessionById, updateChatSessionTitle } from "../chatStorage";
import { applyQuestionResponse, cancelRunningTodos, completeRunningProgress, createAssistantMessage, createTodoUpdateFromEvent, createUserMessage, dedupeQuestionsAcrossMessages, finalizeAssistantMessageAfterAbort, normalizeSessionTodos, toPermissionStatus, upsertPermission, upsertProgress, upsertQuestionAcrossMessages } from "./agentChatSessionState";
import type { PromptRunOptions, UseAgentChatSessionOptions } from "./useAgentChatSession.types";
@@ -73,7 +73,7 @@ const AnalysisParameters: React.FC<Props> = ({ onResult }) => {
setSchemeLoading(true);
try {
const response = await api.get(`${config.BACKEND_URL}/api/v1/getallschemes/`, {
const response = await api.get(`${config.BACKEND_URL}/api/v1/schemes`, {
params: { network: NETWORK_NAME },
});
const burstSchemes = (response.data as SchemeItem[]).filter(
@@ -80,7 +80,7 @@ const AnalysisParameters: React.FC<Props> = ({ onResult }) => {
setSchemeLoading(true);
try {
const response = await api.get(`${config.BACKEND_URL}/api/v1/getallschemes/`, {
const response = await api.get(`${config.BACKEND_URL}/api/v1/schemes`, {
params: { network: NETWORK_NAME },
});
const burstSchemes = (response.data as SchemeItem[]).filter(
@@ -280,7 +280,7 @@ const AnalysisParameters: React.FC = () => {
};
try {
await api.get(`${config.BACKEND_URL}/api/v1/burst_analysis/`, {
await api.get(`${config.BACKEND_URL}/api/v1/burst-analysis`, {
params,
paramsSerializer: {
indexes: null, // 移除数组索引,即由 burst_ID[] 变为 burst_ID
@@ -110,7 +110,7 @@ const SchemeQuery: React.FC<SchemeQueryProps> = ({
setLoading(true);
try {
const response = await api.get(
`${config.BACKEND_URL}/api/v1/getallschemes/?network=${network}`,
`${config.BACKEND_URL}/api/v1/schemes?network=${network}`,
);
let filteredResults = response.data;
@@ -271,7 +271,7 @@ const ValveIsolation: React.FC<ValveIsolationProps> = ({
params.disabled_valves = disabled;
}
const response = await api.get(
`${config.BACKEND_URL}/api/v1/valve_isolation_analysis/`,
`${config.BACKEND_URL}/api/v1/valve-isolation-analysis`,
{
params,
paramsSerializer: {
@@ -189,7 +189,7 @@ const AnalysisParameters: React.FC = () => {
scheme_name: schemeName,
};
await api.get(`${config.BACKEND_URL}/api/v1/contaminant_simulation/`, {
await api.get(`${config.BACKEND_URL}/api/v1/contaminant-simulation`, {
params,
});
@@ -181,7 +181,7 @@ const SchemeQuery: React.FC<SchemeQueryProps> = ({
setLoading(true);
try {
const response = await api.get(
`${config.BACKEND_URL}/api/v1/getallschemes/?network=${network}`,
`${config.BACKEND_URL}/api/v1/schemes?network=${network}`,
);
let filteredResults = response.data;
@@ -242,7 +242,7 @@ const AnalysisParameters: React.FC = () => {
// but axios usually handles array as valves[]=1&valves[]=2
// FastAPI default expects repeated query params.
const response = await api.get(`${config.BACKEND_URL}/api/v1/flushing_analysis/`, {
const response = await api.get(`${config.BACKEND_URL}/api/v1/flushing-analysis`, {
params,
// Ensure arrays are sent as repeated keys: valves=1&valves=2
paramsSerializer: {
@@ -222,7 +222,7 @@ const SchemeQuery: React.FC<SchemeQueryProps> = ({
setLoading(true);
try {
const response = await api.get(
`${config.BACKEND_URL}/api/v1/getallschemes/?network=${network}`,
`${config.BACKEND_URL}/api/v1/schemes?network=${network}`,
);
let filteredResults = response.data;
@@ -94,7 +94,7 @@ const OptimizationParameters: React.FC = () => {
try {
// 发送优化请求
const response = await api.post(
`${config.BACKEND_URL}/api/v1/sensorplacementscheme/create`,
`${config.BACKEND_URL}/api/v1/sensor-placement-schemes`,
null,
{
params: {
@@ -149,7 +149,7 @@ const SchemeQuery: React.FC<SchemeQueryProps> = ({
setLoading(true);
try {
const response = await api.get(
`${config.BACKEND_URL}/api/v1/getallsensorplacements/?network=${network}`,
`${config.BACKEND_URL}/api/v1/sensor-placement-schemes?network=${network}`,
);
let filteredResults = response.data;
@@ -643,7 +643,7 @@ const Timeline: React.FC<TimelineProps> = ({
};
const response = await apiFetch(
`${config.BACKEND_URL}/api/v1/runsimulationmanuallybydate/`,
`${config.BACKEND_URL}/api/v1/simulations/run-by-date`,
{
method: "POST",
headers: {
@@ -1,6 +1,6 @@
import { FlatStyleLike } from "ol/style/flat";
import { calculateClassification } from "@utils/breaks_classification";
import { calculateClassification } from "@utils/breaksClassification";
import { parseColor } from "@utils/parseColor";
import {
@@ -31,7 +31,7 @@ import {
StyleEditorStateProps,
} from "./styleEditorTypes";
import { LegendStyleConfig } from "./StyleLegend";
import { calculateClassification } from "@utils/breaks_classification";
import { calculateClassification } from "@utils/breaksClassification";
const UNIT_HEADLOSS_RANGE: [number, number] = [0, 5];
+2 -2
View File
@@ -53,7 +53,7 @@ export const ProjectProvider: React.FC<{ children: React.ReactNode }> = ({
try {
// Open project backend (simulation model)
const openResponse = await apiFetch(
`${config.BACKEND_URL}/api/v1/openproject/?network=${net}`,
`${config.BACKEND_URL}/api/v1/projects/open?network=${net}`,
{
method: "POST",
},
@@ -64,7 +64,7 @@ export const ProjectProvider: React.FC<{ children: React.ReactNode }> = ({
// Fetch project metadata
const infoResponse = await apiFetch(
`${config.BACKEND_URL}/api/v1/project_info/?network=${net}`,
`${config.BACKEND_URL}/api/v1/project-info?network=${net}`,
);
if (!infoResponse.ok) {
console.warn(
@@ -50,7 +50,7 @@ function variance(data: number[], start: number, end: number): number {
return data.slice(start, end + 1).reduce((sum, val) => sum + (val - mean) ** 2, 0);
}
export function jenks_breaks_jenkspy(data: number[], nClasses: number): number[] {
function jenksBreaksJenkspy(data: number[], nClasses: number): number[] {
if (data.length === 0) return [];
if (nClasses >= data.length) return data.slice().sort((a, b) => a - b);
@@ -92,13 +92,13 @@ export function jenks_breaks_jenkspy(data: number[], nClasses: number): number[]
return breaks;
}
export function jenks_with_stratified_sampling(
function jenksWithStratifiedSampling(
data: number[],
nClasses: number,
sampleSize = 10000
): number[] {
if (data.length <= sampleSize) {
return jenks_breaks_jenkspy(data, nClasses);
return jenksBreaksJenkspy(data, nClasses);
}
const sortedData = data.slice().sort((a, b) => a - b);
@@ -112,7 +112,7 @@ export function jenks_with_stratified_sampling(
}
}
return jenks_breaks_jenkspy(sampledData, nClasses);
return jenksBreaksJenkspy(sampledData, nClasses);
}
export function calculateClassification(
@@ -129,7 +129,7 @@ export function calculateClassification(
}
if (classificationMethod === "jenks_optimized") {
return jenks_with_stratified_sampling(data, segments);
return jenksWithStratifiedSampling(data, segments);
}
return [];