Skip to content

Commit

Permalink
Initial commits for kicking off query editor implementations and data…
Browse files Browse the repository at this point in the history
…source support (#546)

* initial commit - monaco editor

Signed-off-by: Eric Wei <menwe@amazon.com>

* raw editor

Signed-off-by: EC2 Default User <ec2-user@ip-172-31-2-58.us-east-2.compute.internal>

* visual builder placeholder

Signed-off-by: EC2 Default User <ec2-user@ip-172-31-2-58.us-east-2.compute.internal>

* datasource intial frame

Signed-off-by: EC2 Default User <ec2-user@ip-172-31-2-58.us-east-2.compute.internal>

* minor changes

Signed-off-by: Eric Wei <menwe@amazon.com>

---------

Signed-off-by: Eric Wei <menwe@amazon.com>
Signed-off-by: EC2 Default User <ec2-user@ip-172-31-2-58.us-east-2.compute.internal>
Co-authored-by: EC2 Default User <ec2-user@ip-172-31-2-58.us-east-2.compute.internal>
  • Loading branch information
mengweieric and EC2 Default User committed Jun 22, 2023
1 parent 4ab8089 commit fe66220
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 1 deletion.
6 changes: 5 additions & 1 deletion public/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
/* components */

// event analytics
@import 'components/event_analytics/index';
@import 'components/event_analytics/index';

/* plugins */

@import 'plugins/index.scss';
24 changes: 24 additions & 0 deletions public/plugins/data_explorer/data_explorer_plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export type KeyValue<T = any> = Record<string, T>;

export enum PluginType {
datasource = 'DATASOURCE',
}

export interface IPluginMeta {
name: string;
type: PluginType;
}

export abstract class DataExplorerPlugin<T extends IPluginMeta> {
metadata: T; // plugin meta data
hasError?: boolean; // if there's error when loading plugin

constructor() {
this.metadata = {} as T;
}
}
16 changes: 16 additions & 0 deletions public/plugins/datasources/datasource_plugin/datasource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export abstract class Datasource {
readonly name: string;
readonly type: string;
readonly metadata: any;

constructor(datasourceSettings: any) {
this.name = datasourceSettings.name;
this.type = datasourceSettings.type;
this.metadata = datasourceSettings.metadata;
}
}
24 changes: 24 additions & 0 deletions public/plugins/datasources/datasource_plugin/datasource_plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { DataExplorerPlugin, IPluginMeta } from '../../data_explorer/data_explorer_plugin';

export type IDatasourcePluginMeta = IPluginMeta;

export interface IDatasourcePluginComponents {
QueryEditor: any;
}

export class DatasourcePlugin extends DataExplorerPlugin<IDatasourcePluginMeta> {
components: IDatasourcePluginComponents | null = null;

constructor() {
super();
}

setQueryEditor(QueryEditor: any) {
this.components.QueryEditor = QueryEditor;
}
}
51 changes: 51 additions & 0 deletions public/plugins/datasources/sparksql/editor/spark_sql_editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { EuiIcon, EuiSpacer } from '@elastic/eui';
import {
SqlRawQueryEditor,
SqlVisualBuilder,
QueryHeader,
} from '../../../../plugins/query_editors';

const ROW_OPTIONS = [
{
value: 'host',
inputDisplay: (
<>
<EuiIcon type="string" />
host
</>
),
'data-test-subj': 'option-host',
disabled: false,
},
{
value: 'tags',
inputDisplay: (
<>
<EuiIcon type="string" />
tags
</>
),
'data-test-subj': 'option-tags',
disabled: false,
},
];

export const SparkSqlQueryEditor = ({ datasource, query }) => {
return (
<>
<QueryHeader />

{query.editorMode !== 'query_editor' && <SqlVisualBuilder options={ROW_OPTIONS} />}

<EuiSpacer size="s" />

{query.editorMode === 'query_editor' && <SqlRawQueryEditor onEditorChange={() => {}} />}
</>
);
};
6 changes: 6 additions & 0 deletions public/plugins/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

@import './query_editors/query_header.scss';
9 changes: 9 additions & 0 deletions public/plugins/query_editors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export { SqlVisualBuilder } from './sql/visual_builder/sql_visual_builder';
export { SqlRawQueryEditor } from './sql/sql_raw_query_editor';
export { MonacoRawQueryEditor } from './monaco_raw_query_editor';
export { QueryHeader } from './query_header';
17 changes: 17 additions & 0 deletions public/plugins/query_editors/monaco_raw_query_editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

/**
* This component should include functionalities related to Monaco specifically,
* for example adding lazy loading, error handings and other enhancements or overriding
* features.
*/

import React from 'react';
import MonacoEditor, { MonacoEditorProps } from 'react-monaco-editor';

export const MonacoRawQueryEditor = React.memo((props: MonacoEditorProps) => {
return <MonacoEditor theme="euiColors" {...props} />;
});
4 changes: 4 additions & 0 deletions public/plugins/query_editors/query_header.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
55 changes: 55 additions & 0 deletions public/plugins/query_editors/query_header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useState } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiButton, EuiButtonGroup } from '@elastic/eui';

const QUERY_MODE_OPTIONS = [
{ label: 'Builder', id: 'visual_builder' },
{ label: 'Code', id: 'query_editor' },
];

export const QueryModeSwitcher = () => {
const [toggleCompressedIdSelected, setToggleCompressedIdSelected] = useState('query_editor');

const onModeChange = (modeId: string) => {
setToggleCompressedIdSelected(modeId);
};

return (
<EuiButtonGroup
color="text"
id="hidden"
isDisabled={false}
isIconOnly={false}
key="1"
name="Hidden"
onChange={onModeChange}
buttonSize="compressed"
options={QUERY_MODE_OPTIONS}
idSelected={toggleCompressedIdSelected}
legend=""
isFullWidth={false}
/>
);
};

export const QueryHeader = (props) => {
return (
<>
<EuiFlexGroup gutterSize="s" justifyContent="flexStart" alignItems="flexStart">
<EuiFlexItem grow={3} />
<EuiFlexItem key="queryHeader__search-run" className="queryHeader__search-run" grow={false}>
<EuiButton fill size="s" iconType="play">
Run
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<QueryModeSwitcher />
</EuiFlexItem>
</EuiFlexGroup>
</>
);
};
17 changes: 17 additions & 0 deletions public/plugins/query_editors/sql/sql_raw_query_editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { EuiSpacer } from '@elastic/eui';
import { MonacoRawQueryEditor } from '../monaco_raw_query_editor';
import { QueryHeader } from '../query_header';

export const SqlRawQueryEditor = (props) => {
return (
<>
<MonacoRawQueryEditor width="100%" height={500} value={''} onChange={props.onEditorChange} />
</>
);
};
17 changes: 17 additions & 0 deletions public/plugins/query_editors/sql/visual_builder/sql_select_row.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useState } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiButton, EuiButtonGroup, EuiSuperSelect } from '@elastic/eui';

export const SqlSelectRow = ({ colRaw }) => {
return (
<EuiFlexGroup gutterSize="s" justifyContent="flexStart" alignItems="flexStart">
<EuiFlexItem key="queryHeader__search-run" className="queryHeader__search-run" grow={false}>
<EuiSuperSelect options={colOptions} valueOfSelected={} />
</EuiFlexItem>
</EuiFlexGroup>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiButton, EuiButtonGroup } from '@elastic/eui';
import { SqlSelectRow } from './sql_select_row';

export const SqlVisualBuilder = (props) => {
return (
<EuiFlexGroup gutterSize="s" justifyContent="flexStart" alignItems="flexStart">
<EuiFlexItem key="queryHeader__search-run" className="queryHeader__search-run">
<SqlSelectRow options={props.options} />
</EuiFlexItem>
</EuiFlexGroup>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { Datasource } from 'public/plugins/datasources/datasource_plugin/datasource';
import { IDatasourceService } from './types/datasource_service';

export class DatasourceService implements IDatasourceService {
private datasources: Record<string, Datasource> = {};
private settingsByName: Record<string, Datasource> = {};
private settingsByType: Record<string, Datasource> = {};

constructor() {}

init(settingsByName: Record<string, Datasource>) {}

getList(filters: any) {}

getInstance(dsRef: any) {}

getSettings(dsRef: any) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export interface IDatasourceService {
getInstance: (dsRef: any) => any;
getList: (filters: any) => any;
}

0 comments on commit fe66220

Please sign in to comment.