types: optimize data types (#254)

This commit is contained in:
Fine0830
2023-04-06 21:50:57 +08:00
committed by GitHub
parent 8bb45bb453
commit 49a5481fb0
50 changed files with 263 additions and 213 deletions

View File

@@ -66,7 +66,7 @@ screenMap.set(sizeEnum.LG, screenEnum.LG);
screenMap.set(sizeEnum.XL, screenEnum.XL);
screenMap.set(sizeEnum.XXL, screenEnum.XXL);
export const RespFields: { [key: string]: string } = {
export const RespFields: Indexable = {
readMetricsValues: `{
label
values {

View File

@@ -19,7 +19,7 @@ import dateFormatStep from "@/utils/dateFormat";
import getLocalTime from "@/utils/localtime";
import type { EventParams } from "@/types/app";
export default function associateProcessor(props: any) {
export default function associateProcessor(props: Indexable) {
function eventAssociate() {
if (!props.filters) {
return;
@@ -85,7 +85,7 @@ export default function associateProcessor(props: any) {
const queryOrder = relatedTrace.queryOrder;
const latency = relatedTrace.latency;
const series = props.option.series || [];
const item: any = {
const item: Indexable = {
duration,
queryOrder,
status,

View File

@@ -32,7 +32,7 @@ export interface CreateCallbackParams {
sizeEnum: typeof sizeEnum;
}
export function useBreakpoint(): any {
export function useBreakpoint(): Indexable {
return {
screenRef: computed(() => unref(globalScreenRef)),
widthRef: globalWidthRef,
@@ -41,7 +41,7 @@ export function useBreakpoint(): any {
};
}
export function createBreakpointListen(fn?: (opt: CreateCallbackParams) => void): any {
export function createBreakpointListen(fn?: (opt: CreateCallbackParams) => void): Indexable {
const screenRef = ref<sizeEnum>(sizeEnum.XL || "");
const realWidthRef = ref(window.innerWidth);

View File

@@ -59,7 +59,7 @@ export default function getDashboard(param?: { name: string; layer: string; enti
if (targetTabIndex[1] === undefined) {
container = document.querySelector(".ds-main");
} else {
const w = widgets.find((d: any) => d.id === targetTabIndex[0]);
const w = widgets.find((d: Indexable) => d.id === targetTabIndex[0]);
container = document.querySelector(".tab-layout");
const layout: Nullable<Element> = document.querySelector(".ds-main");
if (w && layout) {

View File

@@ -43,7 +43,7 @@ export type ECOption = echarts.ComposeOption<
| SankeySeriesOption
>;
export function useECharts(elRef: Ref<HTMLDivElement>, theme: "light" | "dark" | "default" = "default"): any {
export function useECharts(elRef: Ref<HTMLDivElement>, theme: "light" | "dark" | "default" = "default"): Indexable {
const getDarkMode = computed(() => {
return theme === "default" ? "light" : theme;
});

View File

@@ -20,7 +20,7 @@ import { useThrottleFn, useDebounceFn } from "@vueuse/core";
export type RemoveEventFn = () => void;
export interface UseEventParams {
el?: Element | Ref<Element | undefined> | Window | any;
el?: Element | Ref<Element | undefined> | Window | Recordable;
name: string;
listener: EventListener;
options?: boolean | AddEventListenerOptions;

View File

@@ -39,7 +39,7 @@ export default function useLegendProcess(legend?: LegendOptions) {
}
function aggregations(data: { [key: string]: number[] }, intervalTime: string[]) {
const source: { [key: string]: unknown }[] = [];
const keys = Object.keys(data || {}).filter((i: any) => Array.isArray(data[i]) && data[i].length);
const keys = Object.keys(data || {}).filter((i: string) => Array.isArray(data[i]) && data[i].length);
const headers = [];
for (const [key, value] of keys.entries()) {

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { MetricQueryTypes, Calculations } from "./data";
export function useListConfig(config: any, index: string) {
export function useListConfig(config: Indexable, index: string) {
const i = Number(index);
const types = [Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg];
const calculation = config.metricConfig && config.metricConfig[i] && config.metricConfig[i].calculation;

View File

@@ -24,7 +24,7 @@ import type { Instance, Endpoint, Service } from "@/types/selector";
import type { MetricConfigOpt } from "@/types/dashboard";
import { MetricCatalog } from "@/views/dashboard/data";
export function useQueryProcessor(config: any) {
export function useQueryProcessor(config: Indexable) {
if (!(config.metrics && config.metrics[0])) {
return;
}
@@ -38,7 +38,7 @@ export function useQueryProcessor(config: any) {
if (!selectorStore.currentService && dashboardStore.entity !== "All") {
return;
}
const conditions: { [key: string]: unknown } = {
const conditions: Recordable = {
duration: appStore.durationTime,
};
const variables: string[] = [`$duration: Duration!`];
@@ -126,7 +126,7 @@ export function useQueryProcessor(config: any) {
};
}
export function useSourceProcessor(
resp: { errors: string; data: { [key: string]: any } },
resp: { errors: string; data: Indexable },
config: {
metrics: string[];
metricTypes: string[];
@@ -181,7 +181,7 @@ export function useSourceProcessor(
}
if (type === MetricQueryTypes.READHEATMAP) {
const resVal = Object.values(resp.data)[0] || {};
const nodes = [] as any;
const nodes = [] as Indexable[];
if (!(resVal && resVal.values)) {
source[m] = { nodes: [] };
return;
@@ -191,7 +191,7 @@ export function useSourceProcessor(
nodes.push(...grids);
});
let buckets = [] as any;
let buckets = [] as Indexable[];
if (resVal.buckets.length) {
buckets = [resVal.buckets[0].min, ...resVal.buckets.map((item: { min: string; max: string }) => item.max)];
}
@@ -204,7 +204,7 @@ export function useSourceProcessor(
}
export function useQueryPodsMetrics(
pods: Array<Instance | Endpoint | Service | any>,
pods: Array<(Instance | Endpoint | Service) & Indexable>,
config: {
metrics: string[];
metricTypes: string[];
@@ -227,7 +227,7 @@ export function useQueryPodsMetrics(
};
const variables: string[] = [`$duration: Duration!`];
const currentService = selectorStore.currentService || {};
const fragmentList = pods.map((d: (Instance | Endpoint | Service) & { normal: boolean }, index: number) => {
const fragmentList = pods.map((d: (Instance | Endpoint | Service) & Indexable, index: number) => {
const param = {
scope,
serviceName: scope === "Service" ? d.label : currentService.label,
@@ -262,13 +262,13 @@ export function useQueryPodsMetrics(
export function usePodsSource(
pods: Array<Instance | Endpoint>,
resp: { errors: string; data: { [key: string]: any } },
resp: { errors: string; data: Indexable },
config: {
metrics: string[];
metricTypes: string[];
metricConfig: MetricConfigOpt[];
},
): any {
): Indexable {
if (resp.errors) {
ElMessage.error(resp.errors);
return {};
@@ -276,7 +276,7 @@ export function usePodsSource(
const names: string[] = [];
const metricConfigArr: MetricConfigOpt[] = [];
const metricTypesArr: string[] = [];
const data = pods.map((d: Instance | any, idx: number) => {
const data = pods.map((d: Instance & Indexable, idx: number) => {
config.metrics.map((name: string, index: number) => {
const c: any = (config.metricConfig && config.metricConfig[index]) || {};
const key = name + idx + index;
@@ -424,14 +424,14 @@ export function aggregation(val: number, config: { calculation?: string }): numb
return data;
}
export async function useGetMetricEntity(metric: string, metricType: any) {
export async function useGetMetricEntity(metric: string, metricType: string) {
if (!metric || !metricType) {
return;
}
let catalog = "";
const dashboardStore = useDashboardStore();
if (
[MetricQueryTypes.ReadSampledRecords, MetricQueryTypes.SortMetrics, MetricQueryTypes.ReadRecords].includes(
([MetricQueryTypes.ReadSampledRecords, MetricQueryTypes.SortMetrics, MetricQueryTypes.ReadRecords] as any).includes(
metricType,
)
) {
@@ -441,7 +441,7 @@ export async function useGetMetricEntity(metric: string, metricType: any) {
return;
}
const c: string = res.data.metrics[0].catalog;
catalog = (MetricCatalog as any)[c];
catalog = (MetricCatalog as Indexable)[c];
}
return catalog;

View File

@@ -38,7 +38,7 @@ export function useTimeoutFn(handle: Fn<any>, wait: number, native = false): any
return { readyRef, stop, start };
}
export function useTimeoutRef(wait: number): any {
export function useTimeoutRef(wait: number) {
const readyRef = ref(false);
let timer: TimeoutHandle;