Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vis: Default editor] Reactify the timelion editor #52990

Merged
merged 21 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8287a0e
Reactify timelion editor
sulemanof Dec 12, 2019
b390d1d
Change translation ids
sulemanof Dec 13, 2019
df7dc2d
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Dec 13, 2019
78bd381
Merge branch 'master' into EUIfication/options/timelion
elasticmachine Dec 13, 2019
6f10b86
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Dec 16, 2019
c35088b
Merge branch 'EUIfication/options/timelion' of github.com:sulemanof/k…
sulemanof Dec 16, 2019
6a600b0
Add @types/pegjs into renovate.json5
sulemanof Dec 16, 2019
73fbc38
Add validation, add hover suggestions
sulemanof Dec 16, 2019
40400bc
Style fixes
sulemanof Dec 17, 2019
bcf36c6
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Dec 17, 2019
f640b05
Change plugin setup, use kibana context
sulemanof Dec 19, 2019
a691c12
Merge branch 'master' into EUIfication/options/timelion
elasticmachine Dec 19, 2019
3cf416f
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Dec 20, 2019
8f2101e
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Dec 21, 2019
2091a0c
Change plugin start
sulemanof Dec 21, 2019
daf056e
Mock services
sulemanof Dec 21, 2019
21bd6d6
Fix other comments
sulemanof Dec 23, 2019
1a2d283
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Dec 23, 2019
474d14e
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Jan 8, 2020
f3a6df8
Build renovate config
sulemanof Jan 8, 2020
5887a92
Fix some classnames and SASS file structure
Jan 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
"@types/mustache": "^0.8.31",
"@types/node": "^10.12.27",
"@types/opn": "^5.1.0",
"@types/pegjs": "^0.10.1",
"@types/pngjs": "^3.3.2",
"@types/podium": "^1.0.0",
"@types/prop-types": "^15.5.3",
Expand Down
8 changes: 8 additions & 0 deletions renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,14 @@
'@types/opn',
],
},
{
groupSlug: 'pegjs',
groupName: 'pegjs related packages',
packageNames: [
'pegjs',
'@types/pegjs',
],
},
{
groupSlug: 'pngjs',
groupName: 'pngjs related packages',
Expand Down
46 changes: 46 additions & 0 deletions src/legacy/core_plugins/timelion/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

type TimelionFunctionArgsTypes = 'seriesList' | 'number' | 'string' | 'boolean' | 'null';

interface TimelionFunctionArgsSuggestion {
name: string;
help: string;
}

export interface TimelionFunctionArgs {
name: string;
help?: string;
multi?: boolean;
types: TimelionFunctionArgsTypes[];
suggestions?: TimelionFunctionArgsSuggestion[];
}

export interface ITimelionFunction {
aliases: string[];
args: TimelionFunctionArgs[];
name: string;
help: string;
chainable: boolean;
extended: boolean;
isAlias: boolean;
argsByName: {
[key: string]: TimelionFunctionArgs[];
};
}
21 changes: 21 additions & 0 deletions src/legacy/core_plugins/timelion/public/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './timelion_expression_input';
export * from './timelion_interval';
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React, { useEffect, useCallback, useRef } from 'react';
import { EuiFormRow } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';

import { IUiSettingsClient, HttpSetup } from 'kibana/public';
import { CodeEditor, KibanaContextProvider } from '../../../../../plugins/kibana_react/public';
import { suggest, getSuggestion } from './timelion_expression_input_helpers';
import { ArgValueSuggestions } from '../services/arg_value_suggestions';
import { ITimelionFunction, TimelionFunctionArgs } from '../../common/types';

const LANGUAGE_ID = 'timelion_expression';
monacoEditor.languages.register({ id: LANGUAGE_ID });

export interface TimelionExpressionInputDependencies {
argValueSuggestions: ArgValueSuggestions;
http: HttpSetup;
sulemanof marked this conversation as resolved.
Show resolved Hide resolved
uiSettings: IUiSettingsClient;
}

interface TimelionExpressionInputProps {
value: string;
setValue(value: string): void;
}

function TimelionExpressionInput({
argValueSuggestions,
http,
uiSettings,
value,
setValue,
}: TimelionExpressionInputProps & TimelionExpressionInputDependencies) {
const functionList = useRef([]);

const provideCompletionItems = useCallback(
async (model: monacoEditor.editor.ITextModel, position: monacoEditor.Position) => {
const text = model.getValue();
const wordUntil = model.getWordUntilPosition(position);
const wordRange = new monacoEditor.Range(
position.lineNumber,
wordUntil.startColumn,
position.lineNumber,
wordUntil.endColumn
);

const suggestions = await suggest(
text,
functionList.current,
// it's important to offset the cursor position on 1 point left
// because of PEG parser starts the line with 0, but monaco with 1
position.column - 1,
argValueSuggestions
);

return {
suggestions: suggestions
? suggestions.list.map((s: ITimelionFunction | TimelionFunctionArgs) =>
getSuggestion(s, suggestions.type, wordRange)
)
: [],
};
},
[argValueSuggestions]
);

const provideHover = useCallback(
async (model: monacoEditor.editor.ITextModel, position: monacoEditor.Position) => {
const suggestions = await suggest(
model.getValue(),
functionList.current,
// it's important to offset the cursor position on 1 point left
// because of PEG parser starts the line with 0, but monaco with 1
position.column - 1,
argValueSuggestions
);

return {
contents: suggestions
? suggestions.list.map((s: ITimelionFunction | TimelionFunctionArgs) => ({
value: s.help,
}))
: [],
};
},
[argValueSuggestions]
);

useEffect(() => {
http.get('../api/timelion/functions').then(data => {
functionList.current = data;
});
}, [http]);

return (
<KibanaContextProvider services={{ uiSettings }}>
sulemanof marked this conversation as resolved.
Show resolved Hide resolved
<EuiFormRow
className="visEditor__timelionExpressionInput"
fullWidth
label={i18n.translate('timelion.vis.expressionLabel', {
defaultMessage: 'Timelion expression',
})}
>
<div className="timelionExpressionInput__editor">
<CodeEditor
languageId={LANGUAGE_ID}
value={value}
onChange={setValue}
suggestionProvider={{
triggerCharacters: ['.', '(', '=', ':'],
provideCompletionItems,
}}
hoverProvider={{ provideHover }}
options={{
automaticLayout: true,
fixedOverflowWidgets: true,
fontSize: 16,
scrollBeyondLastLine: false,
quickSuggestions: true,
minimap: {
enabled: false,
},
wordBasedSuggestions: false,
wordWrap: 'on',
wrappingIndent: 'indent',
}}
languageConfiguration={{
autoClosingPairs: [
{
open: '(',
close: ')',
},
],
}}
/>
</div>
</EuiFormRow>
</KibanaContextProvider>
);
}

export { TimelionExpressionInput };
Loading