diff --git a/.changeset/twelve-mugs-pump.md b/.changeset/twelve-mugs-pump.md new file mode 100644 index 0000000000..98540f53da --- /dev/null +++ b/.changeset/twelve-mugs-pump.md @@ -0,0 +1,7 @@ +--- +"@scow/mis-web": patch +"@scow/config": patch +"@scow/lib-web": patch +--- + +修复系统初始化时作业价格表设置页面查询参数报错问题 diff --git a/apps/mis-web/src/pages/_app.tsx b/apps/mis-web/src/pages/_app.tsx index 985c964c29..14688db570 100644 --- a/apps/mis-web/src/pages/_app.tsx +++ b/apps/mis-web/src/pages/_app.tsx @@ -256,22 +256,20 @@ MyApp.getInitialProps = async (appContext: AppContext) => { } } - const clustersRuntimeInfo = token ? - await api.getClustersRuntimeInfo({ query: { token } }).then((x) => x, () => undefined) - : await api.getClustersRuntimeInfo({ query: { } }).then((x) => x, () => undefined); + const clustersRuntimeInfo = await api.getClustersRuntimeInfo({ query: { token } }).then((x) => x, () => undefined); // get deployed clusters' simple info (only clusterId, displayName and priority) const simpleClustersInfo = await api.getSimpleClustersInfoFromConfigFiles({}).then((x) => x, () => ({ clustersInfo: {} })); - extra.initialSimpleClustersInfo = simpleClustersInfo?.clustersInfo; + extra.initialSimpleClustersInfo = simpleClustersInfo?.clustersInfo ?? {}; - const publicConfigClusters = Object.keys(extra.clusterConfigs).length > 0 ? + const publicConfigClusters = extra.clusterConfigs && Object.keys(extra.clusterConfigs).length > 0 ? getPublicConfigClusters(extra.clusterConfigs) : getPublicConfigClusters(extra.initialSimpleClustersInfo) ?? {}; const activatedClusters = formatActivatedClusters({ - clustersRuntimeInfo: clustersRuntimeInfo?.results, + clustersRuntimeInfo: clustersRuntimeInfo?.results ?? [], misConfigClusters: publicConfigClusters }); extra.initialActivatedClusters = activatedClusters.misActivatedClusters ?? {}; diff --git a/apps/mis-web/src/pages/api/admin/getClustersRuntimeInfo.ts b/apps/mis-web/src/pages/api/admin/getClustersRuntimeInfo.ts index 91a4f3781b..0d20135c3d 100644 --- a/apps/mis-web/src/pages/api/admin/getClustersRuntimeInfo.ts +++ b/apps/mis-web/src/pages/api/admin/getClustersRuntimeInfo.ts @@ -36,6 +36,8 @@ export const GetClustersRuntimeInfoSchema = typeboxRouteSchema({ 200: Type.Object({ results: Type.Array(ClusterRuntimeInfoSchema), }), + + 403: Type.Null(), }, }); @@ -46,11 +48,12 @@ export default route(GetClustersRuntimeInfoSchema, // if not initialized, every one can get clustersRuntimeInfo if (await queryIfInitialized()) { + const { token } = req.query; // when firstly used in getInitialProps, check the token // when logged in, use auth() const info = token ? await validateToken(token) : await auth(req, res); - if (!info) { return; } + if (!info) { return { 403: null }; } } const client = getClient(ConfigServiceClient); diff --git a/apps/mis-web/src/pages/api/simpleClustersInfo.ts b/apps/mis-web/src/pages/api/simpleClustersInfo.ts index 1df3ad4023..799ed36384 100644 --- a/apps/mis-web/src/pages/api/simpleClustersInfo.ts +++ b/apps/mis-web/src/pages/api/simpleClustersInfo.ts @@ -37,6 +37,8 @@ export const GetSimpleClustersInfoFromConfigFilesSchema = typeboxRouteSchema({ 200: Type.Object({ clustersInfo: Type.Record(Type.String(), SimpleClusterSchema) }), + + 403: Type.Null(), }, }); @@ -47,7 +49,7 @@ export default route(GetSimpleClustersInfoFromConfigFilesSchema, // if not initialized, every one can getSimpleClusterInfo which includes clusterId, displayedName and priority if (await queryIfInitialized()) { const info = await auth(req, res); - if (!info) { return; } + if (!info) { return { 403: null }; } } const clustersFullInfo: Record = await getClusterConfigFiles(); diff --git a/apps/mis-web/src/stores/ClusterInfoStore.ts b/apps/mis-web/src/stores/ClusterInfoStore.ts index e4e102911f..f06d8b1f1d 100644 --- a/apps/mis-web/src/stores/ClusterInfoStore.ts +++ b/apps/mis-web/src/stores/ClusterInfoStore.ts @@ -22,10 +22,16 @@ export function ClusterInfoStore( initialSimpleClusters: Record, ) { - const publicConfigClusters = getPublicConfigClusters(clusterConfigs) - ?? getPublicConfigClusters(initialSimpleClusters) ?? {}; + let publicConfigClusters: Record = {}; + let clusterSortedIdList: string[] = []; - const clusterSortedIdList = getSortedClusterIds(clusterConfigs) ?? getSortedClusterIds(initialSimpleClusters) ?? []; + if (Object.keys(clusterConfigs).length > 0) { + clusterSortedIdList = getSortedClusterIds(clusterConfigs); + publicConfigClusters = getPublicConfigClusters(clusterConfigs); + } else { + clusterSortedIdList = getSortedClusterIds(initialSimpleClusters ?? {}); + publicConfigClusters = getPublicConfigClusters(initialSimpleClusters ?? {}); + } const [activatedClusters, setActivatedClusters] = useState>(initialActivatedClusters); diff --git a/libs/config/src/cluster.ts b/libs/config/src/cluster.ts index 7a02e646a2..05d4a6d173 100644 --- a/libs/config/src/cluster.ts +++ b/libs/config/src/cluster.ts @@ -21,7 +21,7 @@ const CLUSTER_CONFIG_BASE_PATH = "clusters"; export const SimpleClusterSchema = Type.Object({ clusterId: Type.String(), displayName: createI18nStringSchema({ description: "集群名称" }), - priority: Type.Number(), + priority: Type.Number({ description: "集群使用的优先级, 数字越小越先展示", default: Number.MAX_SAFE_INTEGER }), }); export type SimpleClusterSchema = Static; diff --git a/libs/web/src/utils/cluster.ts b/libs/web/src/utils/cluster.ts index 40373c0486..f9c36fddd4 100644 --- a/libs/web/src/utils/cluster.ts +++ b/libs/web/src/utils/cluster.ts @@ -16,8 +16,7 @@ export const getSortedClusterIds = (clusters: Record { - return (clusters[a].priority ?? Number.MAX_SAFE_INTEGER) - - (clusters[b].priority ?? Number.MIN_SAFE_INTEGER); + return clusters[a].priority! - clusters[b].priority!; }, ); };