mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Correlations: Account for restricted datasource (#70717)
* Account for restricted datasource
* Allow for fetching datasource to return undefined and beef up filtering after to remove invalid datasources
* Revert "Account for restricted datasource"
This reverts commit 1087159b93.
* Empty-Commit
This commit is contained in:
@@ -20,13 +20,28 @@ export interface CorrelationData extends Omit<Correlation, 'sourceUID' | 'target
|
|||||||
target: DataSourceInstanceSettings;
|
target: DataSourceInstanceSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
const toEnrichedCorrelationData = ({ sourceUID, targetUID, ...correlation }: Correlation): CorrelationData => ({
|
const toEnrichedCorrelationData = ({
|
||||||
...correlation,
|
sourceUID,
|
||||||
source: getDataSourceSrv().getInstanceSettings(sourceUID)!,
|
targetUID,
|
||||||
target: getDataSourceSrv().getInstanceSettings(targetUID)!,
|
...correlation
|
||||||
});
|
}: Correlation): CorrelationData | undefined => {
|
||||||
|
const sourceDatasource = getDataSourceSrv().getInstanceSettings(sourceUID);
|
||||||
|
if (sourceDatasource) {
|
||||||
|
return {
|
||||||
|
...correlation,
|
||||||
|
source: sourceDatasource,
|
||||||
|
target: getDataSourceSrv().getInstanceSettings(targetUID)!,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const toEnrichedCorrelationsData = (correlations: Correlation[]) => correlations.map(toEnrichedCorrelationData);
|
const validSourceFilter = (correlation: CorrelationData | undefined): correlation is CorrelationData => !!correlation;
|
||||||
|
|
||||||
|
const toEnrichedCorrelationsData = (correlations: Correlation[]): CorrelationData[] => {
|
||||||
|
return correlations.map(toEnrichedCorrelationData).filter(validSourceFilter);
|
||||||
|
};
|
||||||
function getData<T>(response: FetchResponse<T>) {
|
function getData<T>(response: FetchResponse<T>) {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
@@ -55,7 +70,12 @@ export const useCorrelations = () => {
|
|||||||
backend
|
backend
|
||||||
.post<CreateCorrelationResponse>(`/api/datasources/uid/${sourceUID}/correlations`, correlation)
|
.post<CreateCorrelationResponse>(`/api/datasources/uid/${sourceUID}/correlations`, correlation)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return toEnrichedCorrelationData(response.result);
|
const enrichedCorrelation = toEnrichedCorrelationData(response.result);
|
||||||
|
if (enrichedCorrelation !== undefined) {
|
||||||
|
return enrichedCorrelation;
|
||||||
|
} else {
|
||||||
|
throw new Error('invalid sourceUID');
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
[backend]
|
[backend]
|
||||||
);
|
);
|
||||||
@@ -70,7 +90,14 @@ export const useCorrelations = () => {
|
|||||||
({ sourceUID, uid, ...correlation }) =>
|
({ sourceUID, uid, ...correlation }) =>
|
||||||
backend
|
backend
|
||||||
.patch<UpdateCorrelationResponse>(`/api/datasources/uid/${sourceUID}/correlations/${uid}`, correlation)
|
.patch<UpdateCorrelationResponse>(`/api/datasources/uid/${sourceUID}/correlations/${uid}`, correlation)
|
||||||
.then((response) => toEnrichedCorrelationData(response.result)),
|
.then((response) => {
|
||||||
|
const enrichedCorrelation = toEnrichedCorrelationData(response.result);
|
||||||
|
if (enrichedCorrelation !== undefined) {
|
||||||
|
return enrichedCorrelation;
|
||||||
|
} else {
|
||||||
|
throw new Error('invalid sourceUID');
|
||||||
|
}
|
||||||
|
}),
|
||||||
[backend]
|
[backend]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user