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

[NP] Migrate Markdown to NP #62940

Merged
merged 8 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"timelion": ["src/legacy/core_plugins/timelion", "src/legacy/core_plugins/vis_type_timelion", "src/plugins/timelion"],
"uiActions": "src/plugins/ui_actions",
"visDefaultEditor": "src/plugins/vis_default_editor",
"visTypeMarkdown": "src/legacy/core_plugins/vis_type_markdown",
"visTypeMarkdown": "src/plugins/vis_type_markdown",
"visTypeMetric": "src/legacy/core_plugins/vis_type_metric",
"visTypeTable": "src/legacy/core_plugins/vis_type_table",
"visTypeTagCloud": "src/legacy/core_plugins/vis_type_tagcloud",
Expand Down
44 changes: 0 additions & 44 deletions src/legacy/core_plugins/vis_type_markdown/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/legacy/core_plugins/vis_type_markdown/package.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,5 @@
* under the License.
*/

import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';
import { MarkdownPluginSetupDependencies } from './plugin';
import { plugin } from '.';

const plugins: Readonly<MarkdownPluginSetupDependencies> = {
expressions: npSetup.plugins.expressions,
visualizations: npSetup.plugins.visualizations,
};

const pluginInstance = plugin({} as PluginInitializerContext);

export const setup = pluginInstance.setup(npSetup.core, plugins);
export const start = pluginInstance.start(npStart.core);
export { RangeOption } from './range';
export { SwitchOption } from './switch';
85 changes: 85 additions & 0 deletions src/plugins/charts/public/static/components/range.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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, { useState } from 'react';
import { EuiFormRow, EuiRange, EuiRangeProps } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

interface RangeOptionProps<ParamName extends string> {
label: string;
max: number;
min: number;
paramName: ParamName;
showInput?: boolean;
showLabels?: boolean;
showValue?: boolean;
step?: number;
value: '' | number;
setValue: (paramName: ParamName, value: number) => void;
}

function RangeOption<ParamName extends string>({
label,
max,
min,
showInput,
showLabels,
showValue = true,
step,
paramName,
value,
setValue,
}: RangeOptionProps<ParamName>) {
const [stateValue, setStateValue] = useState(value);
const [isValidState, setIsValidState] = useState(true);

const error = i18n.translate('charts.controls.rangeErrorMessage', {
defaultMessage: 'Values must be on or between {min} and {max}',
values: { min, max },
});

const onChangeHandler: EuiRangeProps['onChange'] = (event, isValid) => {
const { valueAsNumber } = event.target as HTMLInputElement; // since we don't show ticks on EuiRange, the target will definitely be HTMLInputElement type, so we can cast it directly.

setStateValue(valueAsNumber);
setIsValidState(isValid);

if (isValid) {
setValue(paramName, valueAsNumber);
}
};
return (
<EuiFormRow label={label} fullWidth={true} isInvalid={!isValidState} error={error} compressed>
<EuiRange
compressed
fullWidth
max={max}
min={min}
showInput={showInput}
showLabels={showLabels}
showValue={showValue}
step={step}
value={stateValue}
onChange={onChangeHandler}
/>
</EuiFormRow>
);
}

export { RangeOption };
59 changes: 59 additions & 0 deletions src/plugins/charts/public/static/components/switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 from 'react';

import { EuiFormRow, EuiSwitch, EuiToolTip } from '@elastic/eui';

interface SwitchOptionProps<ParamName extends string> {
'data-test-subj'?: string;
label?: string;
tooltip?: string;
disabled?: boolean;
value?: boolean;
paramName: ParamName;
setValue: (paramName: ParamName, value: boolean) => void;
}

function SwitchOption<ParamName extends string>({
'data-test-subj': dataTestSubj,
tooltip,
label,
disabled,
paramName,
value = false,
setValue,
}: SwitchOptionProps<ParamName>) {
return (
<EuiFormRow fullWidth={true} compressed={true}>
<EuiToolTip content={tooltip} delay="long" position="right">
<EuiSwitch
compressed={true}
label={label}
checked={value}
disabled={disabled}
data-test-subj={dataTestSubj}
onChange={ev => setValue(paramName, ev.target.checked)}
/>
</EuiToolTip>
</EuiFormRow>
);
}

export { SwitchOption };
1 change: 1 addition & 0 deletions src/plugins/charts/public/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export * from './color_maps';
export * from './components';
6 changes: 6 additions & 0 deletions src/plugins/vis_type_markdown/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "markdown_vis",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flash1293 I wonder if we change ids to camel case during the migration?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should do this and to make everything consistent, we should also rename the plugin to the same naming scheme we use with the folders: visTypeMarkdown.

Also the same things as in the metric vis type PR apply: #63096 (review)

"version": "kibana",
"ui": true,
"requiredPlugins": ["expressions", "visualizations"]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import 'src/legacy/ui/public/styles/styling_constants';

// Prefix all styles with "mkd" to avoid conflicts.
// Examples
// mkdChart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { PluginInitializerContext } from '../../../../core/public';
import { PluginInitializerContext } from '../../../core/public';
import { MarkdownPlugin as Plugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
* under the License.
*/

// eslint-disable-next-line
import { functionWrapper } from '../../../../plugins/expressions/common/expression_functions/specs/tests/utils';
import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';
import { createMarkdownVisFn } from './markdown_fn';

describe('interpreter/functions#markdown', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition, Render } from '../../../../plugins/expressions/public';
import { ExpressionFunctionDefinition, Render } from '../../expressions/public';
import { Arguments, MarkdownVisParams } from './types';

interface RenderValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n';
import { MarkdownVisWrapper } from './markdown_vis_controller';
import { MarkdownOptions } from './markdown_options';
import { SettingsOptions } from './settings_options';
import { DefaultEditorSize } from '../../../../plugins/vis_default_editor/public';
import { DefaultEditorSize } from '../../vis_default_editor/public';

export const markdownVisDefinition = {
name: 'markdown',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import React from 'react';
import { Markdown } from '../../../../plugins/kibana_react/public';
import { Markdown } from '../../kibana_react/public';
import { MarkdownVisParams } from './types';

interface MarkdownVisComponentProps extends MarkdownVisParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
* under the License.
*/

import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../../core/public';
import { Plugin as ExpressionsPublicPlugin } from '../../../../plugins/expressions/public';
import { VisualizationsSetup } from '../../../../plugins/visualizations/public';
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { Plugin as ExpressionsPublicPlugin } from '../../expressions/public';
import { VisualizationsSetup } from '../../visualizations/public';

import { markdownVisDefinition } from './markdown_vis';
import { createMarkdownVisFn } from './markdown_fn';

import './index.scss';

/** @internal */
export interface MarkdownPluginSetupDependencies {
expressions: ReturnType<ExpressionsPublicPlugin['setup']>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { EuiPanel } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { VisOptionsProps } from 'src/plugins/vis_default_editor/public';
import { RangeOption, SwitchOption } from '../../vis_type_vislib/public';
import { RangeOption, SwitchOption } from '../../charts/public';
import { MarkdownVisParams } from './types';

function SettingsOptions({ stateParams, setValue }: VisOptionsProps<MarkdownVisParams>) {
Expand Down