Skip to content

Commit

Permalink
Refactor supplementaryQueries into a mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelemeny committed Feb 22, 2024
1 parent 0e67cfb commit 03b6beb
Show file tree
Hide file tree
Showing 12 changed files with 780 additions and 748 deletions.
6 changes: 3 additions & 3 deletions src/LanguageProvider.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { AbstractLabelOperator, AbstractLabelMatcher, LanguageProvider, AbstractQuery } from '@grafana/data';

import { ElasticDatasource } from './datasource';
import { BaseQuickwitDataSource } from '@/datasource/base';
import { ElasticsearchQuery } from './types';

export default class ElasticsearchLanguageProvider extends LanguageProvider {
declare request: (url: string, params?: any) => Promise<any>;
declare start: () => Promise<any[]>;
datasource: ElasticDatasource;
datasource: BaseQuickwitDataSource;

constructor(datasource: ElasticDatasource, initialValues?: any) {
constructor(datasource: BaseQuickwitDataSource, initialValues?: any) {
super();
this.datasource = datasource;

Expand Down
10 changes: 5 additions & 5 deletions src/LogContext/LogContextProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode } from 'react';
import { lastValueFrom } from 'rxjs';
import { QuickwitDataSource } from 'datasource';
import { catchError } from 'rxjs/operators';
import { lastValueFrom, catchError } from 'rxjs';

import { BaseQuickwitDataSource } from '@/datasource/base';

import {
CoreApp,
Expand Down Expand Up @@ -43,10 +43,10 @@ function createContextTimeRange(rowTimeEpochMs: number, direction: string) {
}

export class LogContextProvider {
datasource: QuickwitDataSource;
datasource: BaseQuickwitDataSource;
contextQuery: string | null;

constructor(datasource: QuickwitDataSource) {
constructor(datasource: BaseQuickwitDataSource) {
this.datasource = datasource;
this.contextQuery = null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/LogContext/components/LogContextUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Button } from "@grafana/ui";
import { useQueryBuilder } from '@/QueryBuilder/lucene';
import { LogContextQueryBuilderSidebar } from "./LogContextQueryBuilderSidebar";
import { DatasourceContext } from "@/components/QueryEditor/ElasticsearchQueryContext";
import { QuickwitDataSource } from "@/datasource";
import { BaseQuickwitDataSource } from "@/datasource/base";
import { useDatasourceFields } from "@/datasource/utils";
import { Field, FieldContingency, Filter } from "../types";

Expand Down Expand Up @@ -42,7 +42,7 @@ export interface LogContextProps {
origQuery?: DataQuery
}
export interface LogContextUIProps extends LogContextProps {
datasource: QuickwitDataSource,
datasource: BaseQuickwitDataSource,
updateQuery: (query: string) => void
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/QueryEditor/ElasticsearchQueryContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { createContext, PropsWithChildren, useCallback, useEffect, useSta

import { CoreApp, TimeRange } from '@grafana/data';

import { ElasticDatasource } from '@/datasource';
import { BaseQuickwitDataSource } from '@/datasource/base';
import { combineReducers, useStatelessReducer, DispatchContext } from '@/hooks/useStatelessReducer';
import { ElasticsearchQuery } from '@/types';

Expand All @@ -17,15 +17,15 @@ export const useRange = getHook(RangeContext);
export const QueryContext = createContext<ElasticsearchQuery | undefined>(undefined);
export const useQuery = getHook(QueryContext);

export const DatasourceContext = createContext<ElasticDatasource | undefined>(undefined);
export const DatasourceContext = createContext<BaseQuickwitDataSource | undefined>(undefined);
export const useDatasource = getHook(DatasourceContext);

interface Props {
query: ElasticsearchQuery;
app: CoreApp;
onChange: (query: ElasticsearchQuery) => void;
onRunQuery: () => void;
datasource: ElasticDatasource;
datasource: BaseQuickwitDataSource;
range: TimeRange;
}

Expand Down
Loading

0 comments on commit 03b6beb

Please sign in to comment.