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] EUIficate raw json control #32888

Merged
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import dateMath from '@elastic/datemath';
import 'ui/doc_table';
import 'ui/visualize';
import 'ui/fixed_scroll';
import 'ui/directives/validate_json';
import 'ui/filters/moment';
import 'ui/index_patterns';
import 'ui/state_management/app_state';
Expand Down
23 changes: 0 additions & 23 deletions src/legacy/ui/public/agg_types/controls/raw_json.html

This file was deleted.

61 changes: 61 additions & 0 deletions src/legacy/ui/public/agg_types/controls/raw_json.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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, EuiIcon, EuiTextArea, EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { AggParamRequiredEditorProps } from '../../vis/editors/default';

function RawJsonParamEditor({
agg,
value,
setValue,
isInvalid,
}: AggParamRequiredEditorProps<string>) {
const label = (
<>
<FormattedMessage id="common.ui.aggTypes.jsonInputLabel" defaultMessage="JSON input" />{' '}
<EuiToolTip
maryia-lapata marked this conversation as resolved.
Show resolved Hide resolved
position="right"
content={i18n.translate('common.ui.aggTypes.jsonInputTooltip', {
defaultMessage:
"Any JSON formatted properties you add here will be merged with the elasticsearch aggregation definition for this section. For example 'shard_size' on a terms aggregation.",
})}
>
<EuiIcon type="questionInCircle" />
</EuiToolTip>
</>
);

return (
<EuiFormRow label={label} isInvalid={isInvalid} fullWidth={true}>
<EuiTextArea
id={`visEditorRawJson${agg.id}`}
isInvalid={isInvalid}
value={value || ''}
onChange={ev => setValue(ev.target.value)}
rows={2}
fullWidth={true}
/>
</EuiFormRow>
);
}

export { RawJsonParamEditor };
4 changes: 2 additions & 2 deletions src/legacy/ui/public/agg_types/param_types/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import editorHtml from '../controls/raw_json.html';
import { RawJsonParamEditor } from '../controls/raw_json';
import { BaseParamType } from './base';
import { createLegacyClass } from '../../utils/legacy_class';

Expand All @@ -30,7 +30,7 @@ function JsonParamType(config) {
JsonParamType.Super.call(this, config);
}

JsonParamType.prototype.editor = editorHtml;
JsonParamType.prototype.editorComponent = RawJsonParamEditor;

/**
* Write the aggregation parameter.
Expand Down
111 changes: 0 additions & 111 deletions src/legacy/ui/public/directives/__tests__/validate_json.js

This file was deleted.

64 changes: 0 additions & 64 deletions src/legacy/ui/public/directives/validate_json.js

This file was deleted.

50 changes: 50 additions & 0 deletions src/legacy/ui/public/vis/editors/default/__tests__/utils.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 expect from 'expect.js';
maryia-lapata marked this conversation as resolved.
Show resolved Hide resolved
import { isValidJson } from '../utils';

const input = {
valid: '{ "test": "json input" }',
invalid: 'strings are not json',
};

describe('AggType utils', () => {
describe('isValidJson', () => {
it('should return true when empty string', () => {
expect(isValidJson('')).to.be(true);
});

it('should return true when undefine', () => {
expect(isValidJson(undefined as any)).to.be(true);
});

it('should return fasle when invalid string', () => {
expect(isValidJson(input.invalid)).to.be(false);
});

it('should return true when valid string', () => {
expect(isValidJson(input.valid)).to.be(true);
});

it('should return fasle if a number', () => {
expect(isValidJson('0')).to.be(false);
});
});
});
1 change: 1 addition & 0 deletions src/legacy/ui/public/vis/editors/default/_agg_select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
.visEditorAggSelect__helpLink {
@include euiFontSizeXS;
}

3 changes: 3 additions & 0 deletions src/legacy/ui/public/vis/editors/default/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,6 @@
}
}

vis-agg-param-react-wrapper .euiFormRow {
margin-bottom: 7px;
maryia-lapata marked this conversation as resolved.
Show resolved Hide resolved
}
Loading