Skip to content

Commit

Permalink
Merge pull request #52 from quickwit-oss/fmassot/fix-react-error
Browse files Browse the repository at this point in the history
Fix minified React error #185.
  • Loading branch information
fmassot authored Jan 28, 2024
2 parents 260a9b3 + 8bf1dfc commit 09fe172
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { reducerTester } from 'dependencies/reducerTester';
import { reducerTester } from './../../../../dependencies/reducerTester';
import { BucketAggregation, DateHistogram, ElasticsearchQuery } from '../../../../types';
import { changeMetricType } from '../../MetricAggregationsEditor/state/actions';
import { initQuery } from '../../state';
Expand All @@ -12,7 +12,7 @@ import {
removeBucketAggregation,
} from './actions';
import { createReducer } from './reducer';
import { defaultBucketAgg } from 'queryDef';
import { defaultBucketAgg } from './../../../../queryDef';

describe('Bucket Aggregations Reducer', () => {
it('Should correctly add new aggregations', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

import { Action } from '@reduxjs/toolkit';

import { defaultBucketAgg } from '../../../../queryDef';
import { ElasticsearchQuery, Terms, BucketAggregation } from '../../../../types';
import { removeEmpty } from '../../../../utils';
import { changeMetricType } from '../../MetricAggregationsEditor/state/actions';
import { metricAggregationConfig } from '../../MetricAggregationsEditor/utils';
import { initExploreQuery, initQuery } from '../../state';
import { initQuery, initExploreQuery } from '../../state';
import { bucketAggregationConfig } from '../utils';

import {
Expand Down Expand Up @@ -107,10 +107,9 @@ export const createReducer =
}

if (initQuery.match(action) || initExploreQuery.match(action)) {
if (state?.length || 0 > 0) {
if (state && state.length > 0) {
return state;
}

return [{ ...defaultBucketAgg('2'), field: defaultTimeField }];
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/QueryEditor/ElasticsearchQueryContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';
import React, { PropsWithChildren } from 'react';

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

import { ElasticDatasource } from '../../datasource';
import { ElasticsearchQuery } from '../../types';
Expand All @@ -25,7 +25,7 @@ describe('ElasticsearchQueryContext', () => {
render(
<ElasticsearchProvider
query={{ refId: 'A' }}
app={undefined}
app={CoreApp.Unknown}
onChange={onChange}
datasource={datasource}
onRunQuery={onRunQuery}
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('ElasticsearchQueryContext', () => {
<ElasticsearchProvider
datasource={{} as ElasticDatasource}
query={query}
app={undefined}
app={CoreApp.Unknown}
onChange={() => {}}
onRunQuery={() => {}}
range={getDefaultTimeRange()}
Expand Down
8 changes: 4 additions & 4 deletions src/components/QueryEditor/ElasticsearchQueryContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const RangeContext = createContext<TimeRange | undefined>(undefined);

interface Props {
query: ElasticsearchQuery;
app: CoreApp | undefined;
app: CoreApp;
onChange: (query: ElasticsearchQuery) => void;
onRunQuery: () => void;
datasource: ElasticDatasource;
Expand Down Expand Up @@ -61,15 +61,15 @@ export const ElasticsearchProvider = ({
// This initializes the query by dispatching an init action to each reducer.
// useStatelessReducer will then call `onChange` with the newly generated query
useEffect(() => {
if (shouldRunInit) {
if (shouldRunInit && isUninitialized) {
if (app === CoreApp.Explore) {
dispatch(initExploreQuery());
} else {
dispatch(initQuery());
}
setShouldRunInit(false);
}
}, [shouldRunInit, dispatch, app]);
}, [shouldRunInit, dispatch, isUninitialized, app]);

if (isUninitialized) {
return null;
Expand Down Expand Up @@ -97,7 +97,7 @@ const getHook: GetHook = (c) => () => {
throw new Error('use ElasticsearchProvider first.');
}

return contextValue as NonNullable<typeof contextValue>;
return contextValue;
};

export const useQuery = getHook(QueryContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Metric Editor', () => {
<ElasticsearchProvider
datasource={{ getFields: getFields } as ElasticDatasource}
query={query}
app={undefined}
app={CoreApp.Unknown}
range={getDefaultTimeRange()}
onChange={() => {}}
onRunQuery={() => {}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ export const reducer = (state: ElasticsearchQuery['metrics'], action: Action): E
}

if (initQuery.match(action)) {
if (state?.length || 0 > 0) {
if (state && state.length > 0) {
return state;
}
return [defaultMetricAgg('1')];
}

if (initExploreQuery.match(action)) {
if (state?.length || 0 > 0) {
if (state && state.length > 0) {
return state;
}
return [defaultLogsAgg('3')];
Expand Down
6 changes: 3 additions & 3 deletions src/components/QueryEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { css } from '@emotion/css';

import React from 'react';

import { getDefaultTimeRange, GrafanaTheme2, QueryEditorProps } from '@grafana/data';
import { CoreApp, getDefaultTimeRange, GrafanaTheme2, QueryEditorProps } from '@grafana/data';
import { InlineLabel, QueryField, useStyles2 } from '@grafana/ui';

import { ElasticDatasource } from '../../datasource';
Expand All @@ -15,7 +15,7 @@ import { ElasticsearchProvider } from './ElasticsearchQueryContext';
import { MetricAggregationsEditor } from './MetricAggregationsEditor';
import { metricAggregationConfig } from './MetricAggregationsEditor/utils';
import { changeQuery } from './state';
import { QuickwitOptions } from 'quickwit';
import { QuickwitOptions } from '../../quickwit';
import { QueryTypeSelector } from './QueryTypeSelector';

export type ElasticQueryEditorProps = QueryEditorProps<ElasticDatasource, ElasticsearchQuery, QuickwitOptions>;
Expand All @@ -25,9 +25,9 @@ export const QueryEditor = ({ query, onChange, onRunQuery, datasource, range, ap
<ElasticsearchProvider
datasource={datasource}
onChange={onChange}
app={app || CoreApp.Unknown}
onRunQuery={onRunQuery}
query={query}
app={app}
range={range || getDefaultTimeRange()}
>
<QueryEditorForm value={query} />
Expand Down
4 changes: 2 additions & 2 deletions src/configuration/ConfigEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useCallback } from 'react';
import { DataSourceHttpSettings, Input, InlineField, FieldSet } from '@grafana/ui';
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
import { QuickwitOptions } from 'quickwit';
import { QuickwitOptions } from '../quickwit';
import { coerceOptions } from './utils';
import { Divider } from 'components/Divider';
import { Divider } from '../components/Divider';
import { DataLinks } from './DataLinks';

interface Props extends DataSourcePluginOptionsEditorProps<QuickwitOptions> {}
Expand Down
2 changes: 0 additions & 2 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ export class QuickwitDataSource
* Get tag keys for adhoc filters
*/
getTagKeys() {
console.log("getTagKeys");
return lastValueFrom(this.getFields());
}

Expand Down Expand Up @@ -558,7 +557,6 @@ export class QuickwitDataSource
}

metricFindQuery(query: string, options?: { range: TimeRange }): Promise<MetricFindValue[]> {
console.log("metricFindQuery");
const range = options?.range;
const parsedQuery = JSON.parse(query);
if (query) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useFields.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PropsWithChildren } from 'react';
import { from } from 'rxjs';

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

import { ElasticsearchProvider } from '../components/QueryEditor/ElasticsearchQueryContext';
import { ElasticDatasource } from '../datasource';
Expand Down Expand Up @@ -29,7 +29,7 @@ describe('useFields hook', () => {
<ElasticsearchProvider
datasource={{ getFields: getFields } as ElasticDatasource}
query={query}
app={undefined}
app={CoreApp.Unknown}
range={timeRange}
onChange={() => {}}
onRunQuery={() => {}}
Expand Down
2 changes: 1 addition & 1 deletion src/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataSourceInstanceSettings, PluginType } from '@grafana/data';

import { QuickwitDataSource } from './datasource';
import { QuickwitOptions } from 'quickwit';
import { QuickwitOptions } from './quickwit';

export function createElasticDatasource(
settings: Partial<DataSourceInstanceSettings<QuickwitOptions>> = {},
Expand Down
2 changes: 1 addition & 1 deletion src/quickwit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataSourceJsonData } from "@grafana/data";
import { DataLinkConfig } from "types";
import { DataLinkConfig } from "./types";

export interface QuickwitOptions extends DataSourceJsonData {
timeField: string;
Expand Down
6 changes: 3 additions & 3 deletions src/test-helpers/render.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { render } from '@testing-library/react';
import React, { ComponentProps, ReactNode } from 'react';

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

import { ElasticDatasource } from '../datasource';
import { ElasticsearchProvider } from 'components/QueryEditor/ElasticsearchQueryContext';
import { ElasticsearchProvider } from '../components/QueryEditor/ElasticsearchQueryContext';

const defaultProviderProps = {
datasource: {} as ElasticDatasource,
Expand Down Expand Up @@ -32,7 +32,7 @@ export const renderWithESProvider = (
return render(
<ElasticsearchProvider
query={query}
app={undefined}
app={CoreApp.Unknown}
onChange={onChange}
datasource={datasource}
onRunQuery={onRunQuery}
Expand Down

0 comments on commit 09fe172

Please sign in to comment.