Restore dashboards: Filter out v0 dashboards from v2 response (#111165)
This commit is contained in:
@@ -128,9 +128,7 @@ export function RecentlyDeletedActions() {
|
|||||||
|
|
||||||
results.forEach((result, index) => {
|
results.forEach((result, index) => {
|
||||||
const dashboardUid = selectedDashboards[index];
|
const dashboardUid = selectedDashboards[index];
|
||||||
if (result.status === 'rejected') {
|
if (result.status === 'rejected' || result.value.error) {
|
||||||
failed.push(dashboardUid);
|
|
||||||
} else if (result.value.error) {
|
|
||||||
failed.push(dashboardUid);
|
failed.push(dashboardUid);
|
||||||
} else if ('data' in result.value && result.value.data?.name) {
|
} else if ('data' in result.value && result.value.data?.name) {
|
||||||
successful.push(result.value.data.name);
|
successful.push(result.value.data.name);
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import { SaveDashboardCommand } from '../components/SaveDashboard/types';
|
|||||||
|
|
||||||
import { DashboardAPI, DashboardVersionError, DashboardWithAccessInfo, ListDeletedDashboardsOptions } from './types';
|
import { DashboardAPI, DashboardVersionError, DashboardWithAccessInfo, ListDeletedDashboardsOptions } from './types';
|
||||||
import {
|
import {
|
||||||
|
failedFromVersion,
|
||||||
isDashboardV2Spec,
|
isDashboardV2Spec,
|
||||||
isV1DashboardCommand,
|
isV1DashboardCommand,
|
||||||
isV2DashboardCommand,
|
isV2DashboardCommand,
|
||||||
failedFromVersion,
|
|
||||||
isV2StoredVersion,
|
isV2StoredVersion,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { K8sDashboardAPI } from './v1';
|
import { K8sDashboardAPI } from './v1';
|
||||||
@@ -69,14 +69,14 @@ export class UnifiedDashboardAPI
|
|||||||
options: ListDeletedDashboardsOptions
|
options: ListDeletedDashboardsOptions
|
||||||
): Promise<ResourceList<Dashboard | DashboardV2Spec>> {
|
): Promise<ResourceList<Dashboard | DashboardV2Spec>> {
|
||||||
const v1Response = await this.v1Client.listDeletedDashboards(options);
|
const v1Response = await this.v1Client.listDeletedDashboards(options);
|
||||||
const filteredV1Items = v1Response.items.filter((item) => !failedFromVersion(item, 'v2'));
|
const filteredV1Items = v1Response.items.filter((item) => !failedFromVersion(item, ['v2']));
|
||||||
|
|
||||||
if (filteredV1Items.length === v1Response.items.length) {
|
if (filteredV1Items.length === v1Response.items.length) {
|
||||||
return v1Response;
|
return v1Response;
|
||||||
}
|
}
|
||||||
|
|
||||||
const v2Response = await this.v2Client.listDeletedDashboards(options);
|
const v2Response = await this.v2Client.listDeletedDashboards(options);
|
||||||
const filteredV2Items = v2Response.items.filter((item) => !failedFromVersion(item, 'v1'));
|
const filteredV2Items = v2Response.items.filter((item) => !failedFromVersion(item, ['v0', 'v1']));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...v2Response,
|
...v2Response,
|
||||||
|
|||||||
@@ -100,15 +100,15 @@ export function getFailedVersion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to check if a dashboard resource has a failed conversion from a specific version family
|
* Helper function to check if a dashboard resource has a failed conversion from specific versions
|
||||||
* @param item - Dashboard resource item
|
* @param item - Dashboard resource item
|
||||||
* @param versionPrefix - Version prefix to check (e.g., 'v1', 'v2')
|
* @param versionPrefixes - Array of version prefixes to check (e.g., ['v1', 'v2'])
|
||||||
* @returns True if conversion failed and stored version starts with the specified prefix
|
* @returns True if conversion failed and stored version starts with any of the specified prefixes
|
||||||
*/
|
*/
|
||||||
export function failedFromVersion(
|
export function failedFromVersion(
|
||||||
item: Resource<Dashboard | DashboardV2Spec | DashboardDataDTO, Status>,
|
item: Resource<Dashboard | DashboardV2Spec | DashboardDataDTO, Status>,
|
||||||
versionPrefix: string
|
versionPrefixes: string[]
|
||||||
): boolean {
|
): boolean {
|
||||||
const storedVersion = getFailedVersion(item);
|
const storedVersion = getFailedVersion(item);
|
||||||
return !!storedVersion && storedVersion.startsWith(versionPrefix);
|
return !!storedVersion && versionPrefixes.some((prefix) => storedVersion.startsWith(prefix));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user