mirror of https://github.com/grafana/grafana.git
Chore: Use `PermissionLevel` instead of `PermissionLevelString` enum (#111399)
This commit is contained in:
parent
a64af68955
commit
f5f34cd587
|
@ -37,7 +37,7 @@ const listFoldersHandler = () =>
|
||||||
const limit = parseInt(url.searchParams.get('limit') ?? '1000', 10);
|
const limit = parseInt(url.searchParams.get('limit') ?? '1000', 10);
|
||||||
const page = parseInt(url.searchParams.get('page') ?? '1', 10);
|
const page = parseInt(url.searchParams.get('page') ?? '1', 10);
|
||||||
|
|
||||||
const tree = permission === 'Edit' ? mockTreeThatViewersCanEdit : mockTree;
|
const tree = permission?.toLowerCase() === 'edit' ? mockTreeThatViewersCanEdit : mockTree;
|
||||||
|
|
||||||
// reconstruct a folder API response from the flat tree fixture
|
// reconstruct a folder API response from the flat tree fixture
|
||||||
const folders = tree
|
const folders = tree
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { config } from 'app/core/config';
|
||||||
import { getBackendSrv } from 'app/core/services/backend_srv';
|
import { getBackendSrv } from 'app/core/services/backend_srv';
|
||||||
import { getGrafanaSearcher } from 'app/features/search/service/searcher';
|
import { getGrafanaSearcher } from 'app/features/search/service/searcher';
|
||||||
import { DashboardSearchItemType } from 'app/features/search/types';
|
import { DashboardSearchItemType } from 'app/features/search/types';
|
||||||
import { PermissionLevelString } from 'app/types/acl';
|
|
||||||
import { FolderInfo } from 'app/types/folders';
|
import { FolderInfo } from 'app/types/folders';
|
||||||
|
|
||||||
export interface FolderFilterProps {
|
export interface FolderFilterProps {
|
||||||
|
@ -69,7 +68,7 @@ async function getFoldersAsOptions(
|
||||||
query: searchString,
|
query: searchString,
|
||||||
kind: ['folder'],
|
kind: ['folder'],
|
||||||
limit: 100,
|
limit: 100,
|
||||||
permission: PermissionLevelString.View,
|
permission: 'view',
|
||||||
});
|
});
|
||||||
|
|
||||||
const options = queryResponse.view.map((item) => ({
|
const options = queryResponse.view.map((item) => ({
|
||||||
|
@ -89,7 +88,7 @@ async function getFoldersAsOptions(
|
||||||
const params = {
|
const params = {
|
||||||
query: searchString,
|
query: searchString,
|
||||||
type: DashboardSearchItemType.DashFolder,
|
type: DashboardSearchItemType.DashFolder,
|
||||||
permission: PermissionLevelString.View,
|
permission: 'view',
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchHits = await getBackendSrv().search(params);
|
const searchHits = await getBackendSrv().search(params);
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { getGrafanaSearcher } from 'app/features/search/service/searcher';
|
||||||
import { QueryResponse } from 'app/features/search/service/types';
|
import { QueryResponse } from 'app/features/search/service/types';
|
||||||
import { queryResultToViewItem } from 'app/features/search/service/utils';
|
import { queryResultToViewItem } from 'app/features/search/service/utils';
|
||||||
import { DashboardViewItem } from 'app/features/search/types';
|
import { DashboardViewItem } from 'app/features/search/types';
|
||||||
import { PermissionLevelString } from 'app/types/acl';
|
import { PermissionLevel } from 'app/types/acl';
|
||||||
|
|
||||||
import { FolderRepo } from './FolderRepo';
|
import { FolderRepo } from './FolderRepo';
|
||||||
import { getDOMId, NestedFolderList } from './NestedFolderList';
|
import { getDOMId, NestedFolderList } from './NestedFolderList';
|
||||||
|
@ -57,7 +57,7 @@ export interface NestedFolderPickerProps {
|
||||||
|
|
||||||
const debouncedSearch = debounce(getSearchResults, 300);
|
const debouncedSearch = debounce(getSearchResults, 300);
|
||||||
|
|
||||||
async function getSearchResults(searchQuery: string, permission?: PermissionLevelString) {
|
async function getSearchResults(searchQuery: string, permission?: PermissionLevel) {
|
||||||
const queryResponse = await getGrafanaSearcher().search({
|
const queryResponse = await getGrafanaSearcher().search({
|
||||||
query: searchQuery,
|
query: searchQuery,
|
||||||
kind: ['folder'],
|
kind: ['folder'],
|
||||||
|
@ -98,17 +98,6 @@ export function NestedFolderPicker({
|
||||||
const [error] = useState<Error | undefined>(undefined); // TODO: error not populated anymore
|
const [error] = useState<Error | undefined>(undefined); // TODO: error not populated anymore
|
||||||
const lastSearchTimestamp = useRef<number>(0);
|
const lastSearchTimestamp = useRef<number>(0);
|
||||||
|
|
||||||
// Map the permission string union to enum value for compatibility
|
|
||||||
const permissionLevel = useMemo(() => {
|
|
||||||
if (permission === 'view') {
|
|
||||||
return PermissionLevelString.View;
|
|
||||||
} else if (permission === 'edit') {
|
|
||||||
return PermissionLevelString.Edit;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('Invalid permission');
|
|
||||||
}, [permission]);
|
|
||||||
|
|
||||||
const isBrowsing = Boolean(overlayOpen && !(search && searchResults));
|
const isBrowsing = Boolean(overlayOpen && !(search && searchResults));
|
||||||
const {
|
const {
|
||||||
emptyFolders,
|
emptyFolders,
|
||||||
|
@ -118,7 +107,7 @@ export function NestedFolderPicker({
|
||||||
} = useFoldersQuery({
|
} = useFoldersQuery({
|
||||||
isBrowsing,
|
isBrowsing,
|
||||||
openFolders: foldersOpenState,
|
openFolders: foldersOpenState,
|
||||||
permission: permissionLevel,
|
permission,
|
||||||
rootFolderUID,
|
rootFolderUID,
|
||||||
rootFolderItem,
|
rootFolderItem,
|
||||||
});
|
});
|
||||||
|
@ -132,7 +121,7 @@ export function NestedFolderPicker({
|
||||||
const timestamp = Date.now();
|
const timestamp = Date.now();
|
||||||
setIsFetchingSearchResults(true);
|
setIsFetchingSearchResults(true);
|
||||||
|
|
||||||
debouncedSearch(search, permissionLevel).then((queryResponse) => {
|
debouncedSearch(search, permission).then((queryResponse) => {
|
||||||
// Only keep the results if it's was issued after the most recently resolved search.
|
// Only keep the results if it's was issued after the most recently resolved search.
|
||||||
// This prevents results showing out of order if first request is slower than later ones.
|
// This prevents results showing out of order if first request is slower than later ones.
|
||||||
// We don't need to worry about clearing the isFetching state either - if there's a later
|
// We don't need to worry about clearing the isFetching state either - if there's a later
|
||||||
|
@ -144,7 +133,7 @@ export function NestedFolderPicker({
|
||||||
lastSearchTimestamp.current = timestamp;
|
lastSearchTimestamp.current = timestamp;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [search, permissionLevel]);
|
}, [search, permission]);
|
||||||
|
|
||||||
// the order of middleware is important!
|
// the order of middleware is important!
|
||||||
const middleware = [
|
const middleware = [
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
import { DashboardsTreeItem } from 'app/features/browse-dashboards/types';
|
import { DashboardsTreeItem } from 'app/features/browse-dashboards/types';
|
||||||
import { PermissionLevelString } from 'app/types/acl';
|
import { PermissionLevel } from 'app/types/acl';
|
||||||
|
|
||||||
import { useFoldersQueryAppPlatform } from './useFoldersQueryAppPlatform';
|
import { useFoldersQueryAppPlatform } from './useFoldersQueryAppPlatform';
|
||||||
import { useFoldersQueryLegacy } from './useFoldersQueryLegacy';
|
import { useFoldersQueryLegacy } from './useFoldersQueryLegacy';
|
||||||
|
@ -8,7 +8,7 @@ import { useFoldersQueryLegacy } from './useFoldersQueryLegacy';
|
||||||
export interface UseFoldersQueryProps {
|
export interface UseFoldersQueryProps {
|
||||||
isBrowsing: boolean;
|
isBrowsing: boolean;
|
||||||
openFolders: Record<string, boolean>;
|
openFolders: Record<string, boolean>;
|
||||||
permission?: PermissionLevelString;
|
permission?: PermissionLevel;
|
||||||
rootFolderUID?: string;
|
rootFolderUID?: string;
|
||||||
rootFolderItem?: DashboardsTreeItem;
|
rootFolderItem?: DashboardsTreeItem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { isDashboardV2Resource, isV1DashboardCommand, isV2DashboardCommand } fro
|
||||||
import { SaveDashboardCommand } from 'app/features/dashboard/components/SaveDashboard/types';
|
import { SaveDashboardCommand } from 'app/features/dashboard/components/SaveDashboard/types';
|
||||||
import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
|
import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
|
||||||
import { dispatch } from 'app/store/store';
|
import { dispatch } from 'app/store/store';
|
||||||
import { PermissionLevelString } from 'app/types/acl';
|
import { PermissionLevel } from 'app/types/acl';
|
||||||
import { SaveDashboardResponseDTO, ImportDashboardResponseDTO } from 'app/types/dashboard';
|
import { SaveDashboardResponseDTO, ImportDashboardResponseDTO } from 'app/types/dashboard';
|
||||||
import { FolderListItemDTO, FolderDTO, DescendantCount, DescendantCountDTO } from 'app/types/folders';
|
import { FolderListItemDTO, FolderDTO, DescendantCount, DescendantCountDTO } from 'app/types/folders';
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ export interface ListFolderQueryArgs {
|
||||||
page: number;
|
page: number;
|
||||||
parentUid: string | undefined;
|
parentUid: string | undefined;
|
||||||
limit: number;
|
limit: number;
|
||||||
permission?: PermissionLevelString;
|
permission?: PermissionLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const browseDashboardsAPI = createApi({
|
export const browseDashboardsAPI = createApi({
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { DataFrame, DataFrameView, FieldType, getDisplayProcessor, SelectableVal
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
import { TermCount } from 'app/core/components/TagFilter/TagFilter';
|
import { TermCount } from 'app/core/components/TagFilter/TagFilter';
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
import { backendSrv } from 'app/core/services/backend_srv';
|
||||||
import { PermissionLevelString } from 'app/types/acl';
|
import { PermissionLevel } from 'app/types/acl';
|
||||||
|
|
||||||
import { DEFAULT_MAX_VALUES, GENERAL_FOLDER_UID, TYPE_KIND_MAP } from '../constants';
|
import { DEFAULT_MAX_VALUES, GENERAL_FOLDER_UID, TYPE_KIND_MAP } from '../constants';
|
||||||
import { DashboardSearchHit, DashboardSearchItemType } from '../types';
|
import { DashboardSearchHit, DashboardSearchItemType } from '../types';
|
||||||
|
@ -21,7 +21,7 @@ interface APIQuery {
|
||||||
folderUIDs?: string[];
|
folderUIDs?: string[];
|
||||||
sort?: string;
|
sort?: string;
|
||||||
starred?: boolean;
|
starred?: boolean;
|
||||||
permission?: PermissionLevelString;
|
permission?: PermissionLevel;
|
||||||
deleted?: boolean;
|
deleted?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { DataFrameView, SelectableValue } from '@grafana/data';
|
import { DataFrameView, SelectableValue } from '@grafana/data';
|
||||||
import { TermCount } from 'app/core/components/TagFilter/TagFilter';
|
import { TermCount } from 'app/core/components/TagFilter/TagFilter';
|
||||||
import { PermissionLevelString } from 'app/types/acl';
|
import { PermissionLevel } from 'app/types/acl';
|
||||||
|
|
||||||
import { ManagerKind } from '../../apiserver/types';
|
import { ManagerKind } from '../../apiserver/types';
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ export interface SearchQuery {
|
||||||
limit?: number;
|
limit?: number;
|
||||||
from?: number;
|
from?: number;
|
||||||
starred?: boolean;
|
starred?: boolean;
|
||||||
permission?: PermissionLevelString;
|
permission?: PermissionLevel;
|
||||||
deleted?: boolean;
|
deleted?: boolean;
|
||||||
offset?: number;
|
offset?: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,6 @@ export enum TeamPermissionLevel {
|
||||||
|
|
||||||
export type PermissionLevel = 'view' | 'edit' | 'admin';
|
export type PermissionLevel = 'view' | 'edit' | 'admin';
|
||||||
|
|
||||||
/** @deprecated Use PermissionLevel instead */
|
|
||||||
export enum PermissionLevelString {
|
|
||||||
View = 'View',
|
|
||||||
Edit = 'Edit',
|
|
||||||
Admin = 'Admin',
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum SearchQueryType {
|
export enum SearchQueryType {
|
||||||
Folder = 'dash-folder',
|
Folder = 'dash-folder',
|
||||||
Dashboard = 'dash-db',
|
Dashboard = 'dash-db',
|
||||||
|
|
Loading…
Reference in New Issue