diff --git a/public/app/features/correlations/CorrelationsPage.tsx b/public/app/features/correlations/CorrelationsPage.tsx index 4862f942b2c..a8847b5ac78 100644 --- a/public/app/features/correlations/CorrelationsPage.tsx +++ b/public/app/features/correlations/CorrelationsPage.tsx @@ -107,9 +107,7 @@ export default function CorrelationsPage(props: CorrelationsPageProps) { !provisioned && ( - handleDelete({ sourceUID, uid }, page.current > 1 && index === 0 && data?.correlations.length === 1) - } + onConfirm={() => handleDelete({ sourceUID, uid }, page.current > 1 && index === 0 && corrData.length === 1)} closeOnConfirm /> ) @@ -150,9 +148,9 @@ export default function CorrelationsPage(props: CorrelationsPageProps) { [RowActions, canWriteCorrelations] ); - const data = useMemo(() => correlations, [correlations]); - const showEmptyListCTA = data?.correlations.length === 0 && !isAdding && !error; - const addButton = canWriteCorrelations && data?.correlations?.length !== 0 && data !== undefined && !isAdding && ( + const corrData = correlations?.correlations ?? []; + const showEmptyListCTA = corrData.length === 0 && !isAdding && !error; + const addButton = canWriteCorrelations && corrData.length !== 0 && !isAdding && ( @@ -175,7 +173,7 @@ export default function CorrelationsPage(props: CorrelationsPageProps) { >
- {!data && isLoading && ( + {isLoading && (
@@ -204,7 +202,7 @@ export default function CorrelationsPage(props: CorrelationsPageProps) { {isAdding && setIsAdding(false)} onCreated={handleAdded} />} - {data && data.correlations.length >= 1 && ( + {correlations && corrData.length >= 1 && ( <> ( @@ -215,12 +213,12 @@ export default function CorrelationsPage(props: CorrelationsPageProps) { /> )} columns={columns} - data={data.correlations} + data={corrData} getRowId={(correlation) => `${correlation.source.uid}-${correlation.uid}`} /> { fetchCorrelations({ page: (page.current = toPage) }); }} diff --git a/public/app/features/correlations/CorrelationsPageWrapper.tsx b/public/app/features/correlations/CorrelationsPageWrapper.tsx index 60095110f58..ee9b7e68062 100644 --- a/public/app/features/correlations/CorrelationsPageWrapper.tsx +++ b/public/app/features/correlations/CorrelationsPageWrapper.tsx @@ -1,10 +1,9 @@ -import { CorrelationList, useListCorrelationQuery } from '@grafana/api-clients/rtkq/correlations/v0alpha1'; import { config, CorrelationsData } from '@grafana/runtime'; import CorrelationsPage from './CorrelationsPage'; import { GetCorrelationsParams } from './types'; import { useCorrelations } from './useCorrelations'; -import { toEnrichedCorrelationDataK8s } from './useCorrelationsK8s'; +import { useCorrelationsK8s } from './useCorrelationsK8s'; function CorrelationsPageLegacy() { const { remove, get } = useCorrelations(); @@ -21,26 +20,28 @@ function CorrelationsPageLegacy() { function CorrelationsPageAppPlatform() { // todo remove fake limit - const { currentData, isLoading, error } = useListCorrelationQuery({ limit: 10 }); + /* const { currentData, isLoading, error } = useListCorrelationQuery({ limit: 10 }); const enrichedCorrelations = (correlations?: CorrelationList) => { return correlations !== undefined ? correlations.items.map((item) => toEnrichedCorrelationDataK8s(item)).filter((i) => i !== undefined) : []; - }; + }; */ + + const { currentData, isLoading, error } = useCorrelationsK8s({ limit: 10 }); // we cant do a straight refetch, we have to pass in new pages if necessary const enhRefetch = (params: GetCorrelationsParams): Promise => { - return new Promise(() => enrichedCorrelations(currentData)); + return new Promise(() => currentData); }; return ( { - //const { data, isLoading, error } = correlationAPIv0alpha1.endpoints.listCorrelation.useQuery({ limit: 10 }); - const { data, isLoading, error } = useListCorrelationQuery({ limit: 10 }); +export const useCorrelationsK8s = (props: { limit: number }) => { + const { currentData, isLoading, error } = useListCorrelationQuery({ limit: props.limit }); const enrichedCorrelations = - data !== undefined - ? data.items.map((item) => toEnrichedCorrelationDataK8s(item)).filter((i) => i !== undefined) + currentData !== undefined + ? currentData.items.map((item) => toEnrichedCorrelationDataK8s(item)).filter((i) => i !== undefined) : []; - // todo returning bad response data, how to fix? return { - get: { - execute: () => {}, - value: { correlations: enrichedCorrelations, page: 0, limit: 1000, totalCount: enrichedCorrelations.length }, - loading: isLoading, - error, - }, + currentData: enrichedCorrelations, + isLoading, + error, }; }; - -/* - if (config.featureToggles.kubernetesCorrelations) { - const result = await dispatch( - correlationAPIv0alpha1.endpoints.createCorrelation.initiate({ - correlation: { - apiVersion: 'correlations.grafana.app/v0alpha1', - kind: 'Correlations', - metadata: {}, - spec: { - ...correlation, - label: correlation.label ?? '', - source: { name: sourceUID, group: '' }, - config: { ...correlation.config, transformations: [] }, - }, - }, - }) - ); - return result; - } else { -*/