Fix based on PR feedback
This commit is contained in:
@@ -65,7 +65,7 @@ func (s *legacyStorage) List(ctx context.Context, options *internalversion.ListO
|
||||
if options.FieldSelector != nil {
|
||||
for _, r := range options.FieldSelector.Requirements() {
|
||||
switch r.Field {
|
||||
case "metadata.name":
|
||||
case "spec.datasource.name":
|
||||
switch r.Operator {
|
||||
case selection.Equals, selection.DoubleEquals:
|
||||
uids = []string{r.Value}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Status } from '@grafana/api-clients/rtkq/correlations/v0alpha1';
|
||||
import { DataSourceInstanceSettings, GrafanaTheme2 } from '@grafana/data';
|
||||
import { Trans, t } from '@grafana/i18n';
|
||||
import { CorrelationData, CorrelationsData, isFetchError, reportInteraction } from '@grafana/runtime';
|
||||
import { CorrelationData, CorrelationsData, FetchError, isFetchError, reportInteraction } from '@grafana/runtime';
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
@@ -31,7 +31,7 @@ import { EmptyCorrelationsCTA } from './components/EmptyCorrelationsCTA';
|
||||
import type { Correlation, GetCorrelationsParams, RemoveCorrelationParams } from './types';
|
||||
|
||||
type CorrelationsPageProps = {
|
||||
fetchCorrelations: (params: GetCorrelationsParams) => Promise<CorrelationsData>;
|
||||
fetchCorrelations: (params: GetCorrelationsParams) => Promise<CorrelationsData> | CorrelationsData;
|
||||
correlations?: CorrelationsData;
|
||||
isLoading: boolean;
|
||||
changePageFn?: (page: number) => void;
|
||||
@@ -41,7 +41,7 @@ type CorrelationsPageProps = {
|
||||
}
|
||||
| Status
|
||||
>;
|
||||
error?: Error;
|
||||
error?: Error | FetchError;
|
||||
hasNextPage?: boolean;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { useRef, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { handleRequestError } from '@grafana/api-clients';
|
||||
import { useDeleteCorrelationMutation } from '@grafana/api-clients/rtkq/correlations/v0alpha1';
|
||||
import { config, CorrelationsData } from '@grafana/runtime';
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
import CorrelationsPage from './CorrelationsPage';
|
||||
import { RemoveCorrelationParams } from './types';
|
||||
import { GetCorrelationsParams, RemoveCorrelationParams } from './types';
|
||||
import { useCorrelations } from './useCorrelations';
|
||||
import { useCorrelationsK8s } from './useCorrelationsK8s';
|
||||
|
||||
@@ -23,19 +24,17 @@ export function CorrelationsPageLegacy() {
|
||||
|
||||
function CorrelationsPageAppPlatform() {
|
||||
const [page, setPage] = useState(1);
|
||||
let totalItems = useRef(0);
|
||||
const limit = 100;
|
||||
const { currentData, isLoading, error, remainingItems, doesContinue } = useCorrelationsK8s(limit, page);
|
||||
const { currentData, isLoading, error, doesContinue } = useCorrelationsK8s(limit, page);
|
||||
const [deleteCorrelation] = useDeleteCorrelationMutation();
|
||||
if (page === 1) {
|
||||
totalItems.current = remainingItems;
|
||||
}
|
||||
|
||||
// we cant do a straight refetch, we have to pass in new pages if necessary
|
||||
const enhRefetch = (): Promise<CorrelationsData> => {
|
||||
return new Promise(() => currentData);
|
||||
const enhRefetch = (params: GetCorrelationsParams) => {
|
||||
return { correlations: currentData, page: params.page, limit, totalCount: 0 };
|
||||
};
|
||||
|
||||
const fmtedError = error ? handleRequestError(error) : undefined;
|
||||
|
||||
return (
|
||||
<CorrelationsPage
|
||||
fetchCorrelations={enhRefetch}
|
||||
@@ -46,10 +45,10 @@ function CorrelationsPageAppPlatform() {
|
||||
correlations: currentData,
|
||||
page: 0,
|
||||
limit: limit,
|
||||
totalCount: totalItems.current,
|
||||
totalCount: 0,
|
||||
}}
|
||||
isLoading={isLoading}
|
||||
error={error}
|
||||
error={fmtedError?.error}
|
||||
removeFn={(params: RemoveCorrelationParams) => {
|
||||
const deleteData = deleteCorrelation({ name: params.uid });
|
||||
return deleteData.unwrap();
|
||||
|
||||
@@ -1,49 +1,54 @@
|
||||
import { handleRequestError } from '@grafana/api-clients';
|
||||
import {
|
||||
Correlation as CorrelationK8s,
|
||||
useListCorrelationQuery,
|
||||
} from '@grafana/api-clients/rtkq/correlations/v0alpha1';
|
||||
import { SupportedTransformationType } from '@grafana/data';
|
||||
import { CorrelationData, CorrelationExternal, CorrelationQuery } from '@grafana/runtime';
|
||||
|
||||
import { toEnrichedCorrelationData } from './useCorrelations';
|
||||
|
||||
export const toEnrichedCorrelationDataK8s = (item: CorrelationK8s): CorrelationData | undefined => {
|
||||
if (item.metadata.name !== undefined) {
|
||||
const baseCor = {
|
||||
uid: item.metadata.name,
|
||||
sourceUID: item.spec.source.name, //todo
|
||||
label: item.spec.label,
|
||||
description: item.spec.description,
|
||||
provisioned: false, // todo,
|
||||
};
|
||||
const baseCor = {
|
||||
uid: item.metadata.name!,
|
||||
sourceUID: item.spec.source.name, //todo
|
||||
label: item.spec.label,
|
||||
description: item.spec.description,
|
||||
provisioned: false, // todo
|
||||
};
|
||||
|
||||
if (item.spec.type === 'external') {
|
||||
const extCorr: CorrelationExternal = {
|
||||
...baseCor,
|
||||
type: 'external',
|
||||
config: {
|
||||
field: item.spec.config.field,
|
||||
target: {
|
||||
url: item.spec.config?.target?.url || '',
|
||||
},
|
||||
transformations: [], // todo fix
|
||||
const transformationsFmt = item.spec.config.transformations?.map((trans) => {
|
||||
return {
|
||||
...trans,
|
||||
type: trans.type === 'regex' ? SupportedTransformationType.Regex : SupportedTransformationType.Logfmt,
|
||||
};
|
||||
});
|
||||
|
||||
if (item.spec.type === 'external') {
|
||||
const extCorr: CorrelationExternal = {
|
||||
...baseCor,
|
||||
type: 'external',
|
||||
config: {
|
||||
field: item.spec.config.field,
|
||||
target: {
|
||||
url: item.spec.config?.target?.url || '',
|
||||
},
|
||||
};
|
||||
return toEnrichedCorrelationData(extCorr);
|
||||
} else {
|
||||
const queryCorr: CorrelationQuery = {
|
||||
...baseCor,
|
||||
type: 'query',
|
||||
targetUID: item.spec.target?.name || '', // todo
|
||||
config: {
|
||||
field: item.spec.config.field,
|
||||
target: item.spec.config.target,
|
||||
transformations: [], // todo fix
|
||||
},
|
||||
};
|
||||
return toEnrichedCorrelationData(queryCorr);
|
||||
}
|
||||
transformations: transformationsFmt,
|
||||
},
|
||||
};
|
||||
return toEnrichedCorrelationData(extCorr);
|
||||
} else {
|
||||
return undefined;
|
||||
const queryCorr: CorrelationQuery = {
|
||||
...baseCor,
|
||||
type: 'query',
|
||||
targetUID: item.spec.target?.name || '', // todo
|
||||
config: {
|
||||
field: item.spec.config.field,
|
||||
target: item.spec.config.target,
|
||||
transformations: transformationsFmt,
|
||||
},
|
||||
};
|
||||
return toEnrichedCorrelationData(queryCorr);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -60,13 +65,13 @@ export const useCorrelationsK8s = (limit = 100, page: number) => {
|
||||
|
||||
const enrichedCorrelations =
|
||||
currentData !== undefined
|
||||
? pagedData.map((item) => toEnrichedCorrelationDataK8s(item)).filter((i) => i !== undefined)
|
||||
? pagedData
|
||||
.filter((i) => i.metadata.name !== undefined)
|
||||
.map((item) => toEnrichedCorrelationDataK8s(item))
|
||||
.filter((i) => i !== undefined)
|
||||
: [];
|
||||
let fmtedError = undefined;
|
||||
|
||||
if (error !== undefined) {
|
||||
fmtedError = new Error(error?.toString() ?? 'useListCorrelationQuery error');
|
||||
}
|
||||
const fmtedError = error ? handleRequestError(error) : undefined;
|
||||
|
||||
return {
|
||||
currentData: enrichedCorrelations,
|
||||
|
||||
Reference in New Issue
Block a user