Skip to content

Commit

Permalink
Support advanced settings (#68)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 authored Apr 15, 2022
1 parent f7ddcb8 commit 3b82489
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
5 changes: 1 addition & 4 deletions gantt-chart/public/components/options_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ export function OptionsEditor({ aggs, stateParams, setValue }: VisOptionsProps<G
<EuiSpacer size="s" />

<EuiFormRow label="Color">
<EuiColorPicker
color={stateParams.colors}
onChange={(e) => setValue('colors', e)}
/>
<EuiColorPicker color={stateParams.colors} onChange={(e) => setValue('colors', e)} />
</EuiFormRow>
</EuiPanel>
);
Expand Down
22 changes: 20 additions & 2 deletions gantt-chart/public/gantt_request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
import { IUiSettingsClient } from 'opensearch-dashboards/public';
import { IndexPattern } from 'src/plugins/data/public';
import { VisParams } from 'src/plugins/visualizations/public';
import { buildOpenSearchQuery, Filter, Query, TimeRange, getTime } from '../../../src/plugins/data/common';
import {
buildOpenSearchQuery,
Filter,
getTime,
OpenSearchQueryConfig,
Query,
TimeRange,
} from '../../../src/plugins/data/common';
import { GanttVisDependencies } from './plugin';

interface GanttRequestHandlerDeps {
Expand All @@ -22,7 +29,18 @@ const constructRequest = (
uiSettings: IUiSettingsClient,
{ timeRange, filters, query, index, visParams }: GanttRequestHandlerDeps
) => {
const DSL = buildOpenSearchQuery(index, query, filters);
let DSL;
try {
const config: OpenSearchQueryConfig = {
allowLeadingWildcards: uiSettings.get('query:allowLeadingWildcards'),
queryStringOptions: uiSettings.get('query:queryString:options'),
ignoreFilterIfFieldNotInIndex: uiSettings.get('courier:ignoreFilterIfFieldNotInIndex'),
};
DSL = buildOpenSearchQuery(index, query, filters, config);
} catch (error) {
DSL = buildOpenSearchQuery(index, query, filters);
}

const request: any = {
index: index.title,
size: visParams.size,
Expand Down
24 changes: 10 additions & 14 deletions gantt-chart/public/gantt_vis_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { Vis, PersistedState } from 'src/plugins/visualizations/public';
import { IAggConfigs } from 'src/plugins/data/public';
import { PersistedState, Vis } from 'src/plugins/visualizations/public';
import { GanttChart } from './components/gantt_chart';
import { GanttChartEditor } from './components/gantt_chart_editor';
import { GanttVisDependencies } from './plugin';
import { OptionsEditor } from './components/options_editor';
import { getGanttRequestHandler } from './gantt_request_handler';
import { GanttVisDependencies } from './plugin';

export interface SearchResponse {
_index: string;
Expand Down Expand Up @@ -77,19 +77,15 @@ export interface GanttSuccessResponse {
total: number;
}

const getGanttResponseHandler = () => async ({
total,
hits,
}: {
total: number;
hits: SearchResponse[];
}) => {
const responseData: GanttSuccessResponse = {
total,
source: hits.map((hit) => hit._source),
const getGanttResponseHandler =
() =>
async ({ total, hits }: { total: number; hits: SearchResponse[] }) => {
const responseData: GanttSuccessResponse = {
total,
source: hits.map((hit) => hit._source),
};
return responseData;
};
return responseData;
};

export function getGanttVisDefinition(dependencies: GanttVisDependencies) {
const ganttRequestHandler = getGanttRequestHandler(dependencies);
Expand Down
11 changes: 9 additions & 2 deletions gantt-chart/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { CoreSetup, Plugin, CoreStart, IUiSettingsClient, HttpSetup } from 'opensearch-dashboards/public';
import {
CoreSetup,
CoreStart,
HttpSetup,
IUiSettingsClient,
Plugin,
} from 'opensearch-dashboards/public';
import { VisualizationsSetup } from '../../../src/plugins/visualizations/public';
import { getGanttVisDefinition } from './gantt_vis_type';

Expand All @@ -17,7 +23,8 @@ export interface GanttVisDependencies extends Partial<CoreStart> {
}

export class CustomVisualizationsPublicPlugin
implements Plugin<CustomVisualizationsSetup, CustomVisualizationsStart> {
implements Plugin<CustomVisualizationsSetup, CustomVisualizationsStart>
{
public setup(core: CoreSetup, setupDeps: SetupDependencies) {
const dependencies: GanttVisDependencies = {
uiSettings: core.uiSettings,
Expand Down

0 comments on commit 3b82489

Please sign in to comment.