Actions: Infinity authentication (#109493)

This commit is contained in:
Adela Almasan
2025-09-03 20:56:30 -05:00
committed by GitHub
parent 936406bfe9
commit 4f70b93ca6
31 changed files with 922 additions and 193 deletions
+2
View File
@@ -849,6 +849,8 @@ export {
defaultActionConfig,
contentTypeOptions,
httpMethodOptions,
type FetchOptions,
type InfinityOptions,
} from './types/action';
export { DataFrameType } from './types/dataFrameTypes';
export {
+11 -8
View File
@@ -4,6 +4,7 @@ import { SelectableValue } from './select';
export enum ActionType {
Fetch = 'fetch',
Infinity = 'infinity',
}
type ActionButtonCssProperties = Pick<CSSProperties, 'backgroundColor'>;
@@ -11,11 +12,8 @@ type ActionButtonCssProperties = Pick<CSSProperties, 'backgroundColor'>;
export interface Action {
type: ActionType;
title: string;
// Options for the selected type
// Currently this is required because there is only one valid type (fetch)
// once multiple types are valid, usage of this will need to be optional
[ActionType.Fetch]: FetchOptions;
[ActionType.Fetch]?: FetchOptions;
[ActionType.Infinity]?: InfinityOptions;
confirmation?: string;
oneClick?: boolean;
variables?: ActionVariable[];
@@ -44,7 +42,7 @@ export enum ActionVariableType {
String = 'string',
}
interface FetchOptions {
export interface FetchOptions {
method: HttpRequestMethod;
url: string;
body?: string;
@@ -52,15 +50,20 @@ interface FetchOptions {
headers?: Array<[string, string]>;
}
export interface InfinityOptions extends FetchOptions {
datasourceUid: string;
}
export enum HttpRequestMethod {
POST = 'POST',
PUT = 'PUT',
GET = 'GET',
DELETE = 'DELETE',
PATCH = 'PATCH',
}
export const httpMethodOptions: SelectableValue[] = [
{ label: HttpRequestMethod.POST, value: HttpRequestMethod.POST },
{ label: HttpRequestMethod.PUT, value: HttpRequestMethod.PUT },
{ label: HttpRequestMethod.GET, value: HttpRequestMethod.GET },
];
@@ -74,7 +77,7 @@ export const contentTypeOptions: SelectableValue[] = [
export const defaultActionConfig: Action = {
type: ActionType.Fetch,
title: '',
fetch: {
[ActionType.Fetch]: {
url: '',
method: HttpRequestMethod.POST,
body: '{}',
@@ -617,6 +617,10 @@ export interface FeatureToggles {
*/
newFiltersUI?: boolean;
/**
* Allows authenticated API calls in actions
*/
vizActionsAuth?: boolean;
/**
* Uses Prometheus rules as the primary source of truth for ruler-enabled data sources
*/
alertingPrometheusRulesPrimary?: boolean;
@@ -31,9 +31,7 @@ export function DataLinksListItemBase<T extends DataLink | Action>({
const styles = useStyles2(getDataLinkListItemStyles);
const { title = '', oneClick = false } = item;
// @ts-ignore - https://github.com/microsoft/TypeScript/issues/27808
const url = item.url ?? item.fetch?.url ?? '';
const url = ('type' in item ? item[item.type]?.url : item.url) ?? '';
const hasTitle = title.trim() !== '';
const hasUrl = url.trim() !== '';
@@ -39,6 +39,7 @@ export interface PanelContext {
canAddAnnotations?: () => boolean;
canEditAnnotations?: (dashboardUID?: string) => boolean;
canDeleteAnnotations?: (dashboardUID?: string) => boolean;
canExecuteActions?: () => boolean;
onAnnotationCreate?: (annotation: AnnotationEventUIModel) => void;
onAnnotationUpdate?: (annotation: AnnotationEventUIModel) => void;
onAnnotationDelete?: (id: string) => void;
@@ -133,10 +133,16 @@ export function TableNG(props: TableNGProps) {
const theme = useTheme2();
const styles = useStyles2(getGridStyles, enablePagination, transparent);
const panelContext = usePanelContext();
const userCanExecuteActions = useMemo(() => panelContext.canExecuteActions?.() ?? false, [panelContext]);
const getCellActions = useCallback(
(field: Field, rowIdx: number) => getActions(data, field, rowIdx),
[getActions, data]
(field: Field, rowIdx: number) => {
if (!userCanExecuteActions) {
return [];
}
return getActions(data, field, rowIdx);
},
[getActions, data, userCanExecuteActions]
);
const hasHeader = !noHeader;