Logs: Deprecated showContextToggle in DataSourceWithLogsContextSupport (#77232)

* Logs: deprecate showContextToggle

* Logs: make row mandatory on showContextToggle prop

* DataSourceWithLogsContextSupport: make showContextToggle optional

* Loki: update test

* Update packages/grafana-data/src/types/logs.ts

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>

* Prettier

* showContextToggle: update deprecation

---------

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
This commit is contained in:
Matias Chomicki 2023-10-31 12:37:44 +01:00 committed by GitHub
parent 23c0054ecc
commit d7c50eb650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 11 additions and 32 deletions

View File

@ -140,9 +140,9 @@ export interface DataSourceWithLogsContextSupport<TQuery extends DataQuery = Dat
getLogRowContextQuery?: (row: LogRowModel, options?: LogRowContextOptions, query?: TQuery) => Promise<TQuery | null>;
/**
* This method can be used to show "context" button based on runtime conditions (for example row model data or plugin settings, etc.)
* @deprecated Deprecated since 10.3. To display the context option and support the feature implement DataSourceWithLogsContextSupport interface instead.
*/
showContextToggle(row?: LogRowModel): boolean;
showContextToggle?(row?: LogRowModel): boolean;
/**
* This method can be used to display a custom UI in the context view.
@ -157,7 +157,7 @@ export const hasLogsContextSupport = (datasource: unknown): datasource is DataSo
return false;
}
return 'getLogRowContext' in datasource && 'showContextToggle' in datasource;
return 'getLogRowContext' in datasource;
};
/**

View File

@ -84,7 +84,7 @@ interface Props extends Themeable2 {
logsVolumeData: DataQueryResponse | undefined;
onSetLogsVolumeEnabled: (enabled: boolean) => void;
loadLogsVolumeData: () => void;
showContextToggle?: (row?: LogRowModel) => boolean;
showContextToggle?: (row: LogRowModel) => boolean;
onChangeTime: (range: AbsoluteTimeRange) => void;
onClickFilterLabel?: (key: string, value: string, refId?: string) => void;
onClickFilterOutLabel?: (key: string, value: string, refId?: string) => void;

View File

@ -206,12 +206,11 @@ class LogsContainer extends PureComponent<LogsContainerProps, LogsContainerState
};
showContextToggle = (row?: LogRowModel): boolean => {
if (!row || !row.dataFrame.refId || !this.state.logContextSupport[row.dataFrame.refId]) {
if (!row?.dataFrame.refId || !this.state.logContextSupport[row.dataFrame.refId]) {
return false;
}
const ds = this.state.logContextSupport[row.dataFrame.refId];
return ds.showContextToggle(row);
return true;
};
getFieldLinks = (field: Field, rowIndex: number, dataFrame: DataFrame) => {

View File

@ -33,7 +33,7 @@ interface Props extends Themeable2 {
onClickFilterOutLabel?: (key: string, value: string, refId?: string) => void;
onContextClick?: () => void;
getFieldLinks?: (field: Field, rowIndex: number, dataFrame: DataFrame) => Array<LinkModel<Field>>;
showContextToggle?: (row?: LogRowModel) => boolean;
showContextToggle?: (row: LogRowModel) => boolean;
onClickShowField?: (key: string) => void;
onClickHideField?: (key: string) => void;
onLogRowHover?: (row?: LogRowModel) => void;

View File

@ -8,7 +8,7 @@ import { LogRowStyles } from './getLogRowStyles';
interface Props {
logText: string;
row: LogRowModel;
showContextToggle?: (row?: LogRowModel) => boolean;
showContextToggle?: (row: LogRowModel) => boolean;
onOpenContext: (row: LogRowModel) => void;
onPermalinkClick?: (row: LogRowModel) => Promise<void>;
onPinLine?: (row: LogRowModel) => void;

View File

@ -14,7 +14,7 @@ interface Props {
wrapLogMessage: boolean;
prettifyLogMessage: boolean;
app?: CoreApp;
showContextToggle?: (row?: LogRowModel) => boolean;
showContextToggle?: (row: LogRowModel) => boolean;
onOpenContext: (row: LogRowModel) => void;
onPermalinkClick?: (row: LogRowModel) => Promise<void>;
onPinLine?: (row: LogRowModel) => void;

View File

@ -13,7 +13,7 @@ export interface Props {
wrapLogMessage: boolean;
getFieldLinks?: (field: Field, rowIndex: number, dataFrame: DataFrame) => Array<LinkModel<Field>>;
styles: LogRowStyles;
showContextToggle?: (row?: LogRowModel) => boolean;
showContextToggle?: (row: LogRowModel) => boolean;
onOpenContext: (row: LogRowModel) => void;
onPermalinkClick?: (row: LogRowModel) => Promise<void>;
onPinLine?: (row: LogRowModel) => void;

View File

@ -38,7 +38,7 @@ export interface Props extends Themeable2 {
forceEscape?: boolean;
displayedFields?: string[];
app?: CoreApp;
showContextToggle?: (row?: LogRowModel) => boolean;
showContextToggle?: (row: LogRowModel) => boolean;
onClickFilterLabel?: (key: string, value: string, refId?: string) => void;
onClickFilterOutLabel?: (key: string, value: string, refId?: string) => void;
getFieldLinks?: (field: Field, rowIndex: number, dataFrame: DataFrame) => Array<LinkModel<Field>>;

View File

@ -156,10 +156,6 @@ export class CloudWatchDatasource
);
}
showContextToggle() {
return true;
}
getQueryDisplayText(query: CloudWatchQuery) {
if (isCloudWatchLogsQuery(query)) {
return query.expression ?? '';

View File

@ -501,10 +501,6 @@ export class ElasticDatasource
return text;
}
showContextToggle(): boolean {
return true;
}
getLogRowContext = async (row: LogRowModel, options?: LogRowContextOptions): Promise<{ data: DataFrame[] }> => {
const { enableElasticsearchBackendQuerying } = config.featureToggles;
if (enableElasticsearchBackendQuerying) {

View File

@ -1579,14 +1579,6 @@ describe('Variable support', () => {
});
});
describe('showContextToggle()', () => {
it('always displays logs context', () => {
const ds = createLokiDatasource(templateSrvStub);
expect(ds.showContextToggle()).toBe(true);
});
});
describe('queryHasFilter()', () => {
let ds: LokiDatasource;
beforeEach(() => {

View File

@ -868,10 +868,6 @@ export class LokiDatasource
return annotations;
}
showContextToggle(row?: LogRowModel): boolean {
return true;
}
addAdHocFilters(queryExpr: string) {
const adhocFilters = this.templateSrv.getAdhocFilters(this.name);
let expr = replaceVariables(queryExpr);