Skip to content

Commit

Permalink
Index Pattern Field class - factor out copy_field code for future typ…
Browse files Browse the repository at this point in the history
…escripting (#63083)

* Index Pattern Field class - factor out copy_field code for future typescripting
  • Loading branch information
mattkime authored and wayneseymour committed Apr 15, 2020
1 parent 6567a30 commit 2871d7e
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export declare class Field implements IFieldType
| [format](./kibana-plugin-plugins-data-public.indexpatternfield.format.md) | | <code>any</code> | |
| [lang](./kibana-plugin-plugins-data-public.indexpatternfield.lang.md) | | <code>string</code> | |
| [name](./kibana-plugin-plugins-data-public.indexpatternfield.name.md) | | <code>string</code> | |
| [routes](./kibana-plugin-plugins-data-public.indexpatternfield.routes.md) | | <code>Record&lt;string, string&gt;</code> | |
| [script](./kibana-plugin-plugins-data-public.indexpatternfield.script.md) | | <code>string</code> | |
| [scripted](./kibana-plugin-plugins-data-public.indexpatternfield.scripted.md) | | <code>boolean</code> | |
| [searchable](./kibana-plugin-plugins-data-public.indexpatternfield.searchable.md) | | <code>boolean</code> | |
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export declare class FieldList extends Array<Field> implements IFieldList
| [getByName](./kibana-plugin-plugins-data-public.indexpatternfieldlist.getbyname.md) | | <code>(name: string) =&gt; Field &#124; undefined</code> | |
| [getByType](./kibana-plugin-plugins-data-public.indexpatternfieldlist.getbytype.md) | | <code>(type: string) =&gt; any[]</code> | |
| [remove](./kibana-plugin-plugins-data-public.indexpatternfieldlist.remove.md) | | <code>(field: IFieldType) =&gt; void</code> | |
| [update](./kibana-plugin-plugins-data-public.indexpatternfieldlist.update.md) | | <code>(field: Field) =&gt; void</code> | |
| [update](./kibana-plugin-plugins-data-public.indexpatternfieldlist.update.md) | | <code>(field: Record&lt;string, any&gt;) =&gt; void</code> | |
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
update: (field: Field) => void;
update: (field: Record<string, any>) => void;
```
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const renderFieldEditor = (
indexPattern={indexPattern}
field={field}
helpers={{
Field: IndexPatternField,
getConfig,
$http,
fieldFormatEditors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const TAB_INDEXED_FIELDS = 'indexedFields';
const TAB_SCRIPTED_FIELDS = 'scriptedFields';
const TAB_SOURCE_FILTERS = 'sourceFilters';

const EDIT_FIELD_PATH = '/management/kibana/index_patterns/{{indexPattern.id}}/field/{{name}}';

function updateSourceFiltersTable($scope) {
$scope.$$postDigest(() => {
const node = document.getElementById(REACT_SOURCE_FILTERS_DOM_ELEMENT_ID);
Expand Down Expand Up @@ -97,8 +99,8 @@ function updateScriptedFieldsTable($scope) {
fieldFilter={$scope.fieldFilter}
scriptedFieldLanguageFilter={$scope.scriptedFieldLanguageFilter}
helpers={{
redirectToRoute: (obj, route) => {
$scope.kbnUrl.changeToRoute(obj, route);
redirectToRoute: field => {
$scope.kbnUrl.changePath(EDIT_FIELD_PATH, field);
$scope.$apply();
},
getRouteHref: (obj, route) => $scope.kbnUrl.getRouteHref(obj, route),
Expand Down Expand Up @@ -140,8 +142,8 @@ function updateIndexedFieldsTable($scope) {
fieldWildcardMatcher={$scope.fieldWildcardMatcher}
indexedFieldTypeFilter={$scope.indexedFieldTypeFilter}
helpers={{
redirectToRoute: (obj, route) => {
$scope.kbnUrl.changeToRoute(obj, route);
redirectToRoute: field => {
$scope.kbnUrl.changePath(EDIT_FIELD_PATH, field);
$scope.$apply();
},
getFieldInfo: $scope.getFieldInfo,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export class IndexedFieldsTable extends Component {
return {
...field,
displayName: field.displayName,
routes: field.routes,
indexPattern: field.indexPattern,
format: getFieldFormat(indexPattern, field.name),
excluded: fieldWildcardMatch ? fieldWildcardMatch(field.name) : false,
Expand Down Expand Up @@ -104,7 +103,7 @@ export class IndexedFieldsTable extends Component {
<Table
indexPattern={indexPattern}
items={fields}
editField={field => this.props.helpers.redirectToRoute(field, 'edit')}
editField={field => this.props.helpers.redirectToRoute(field)}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class ScriptedFieldsTable extends Component<
<Table
indexPattern={indexPattern}
items={items}
editField={field => this.props.helpers.redirectToRoute(field, 'edit')}
editField={field => this.props.helpers.redirectToRoute(field)}
deleteField={this.startDeleteField}
/>

Expand Down
13 changes: 4 additions & 9 deletions src/legacy/ui/public/field_editor/field_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import { ScriptingHelpFlyout } from './components/scripting_help';
import { FieldFormatEditor } from './components/field_format_editor';

import { FIELD_TYPES_BY_LANG, DEFAULT_FIELD_TYPES } from './constants';
import { copyField, executeScript, isScriptValid } from './lib';
import { executeScript, isScriptValid } from './lib';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down Expand Up @@ -100,7 +100,6 @@ export class FieldEditor extends PureComponent {
indexPattern: PropTypes.object.isRequired,
field: PropTypes.object.isRequired,
helpers: PropTypes.shape({
Field: PropTypes.func.isRequired,
getConfig: PropTypes.func.isRequired,
$http: PropTypes.func.isRequired,
fieldFormatEditors: PropTypes.object.isRequired,
Expand All @@ -111,11 +110,7 @@ export class FieldEditor extends PureComponent {
constructor(props) {
super(props);

const {
field,
indexPattern,
helpers: { Field },
} = props;
const { field, indexPattern } = props;

this.state = {
isReady: false,
Expand All @@ -125,7 +120,7 @@ export class FieldEditor extends PureComponent {
fieldTypes: [],
fieldTypeFormats: [],
existingFieldNames: indexPattern.fields.map(f => f.name),
field: copyField(field, indexPattern, Field),
field: { ...field, format: field.format },
fieldFormatId: undefined,
fieldFormatParams: {},
showScriptingHelp: false,
Expand Down Expand Up @@ -730,7 +725,7 @@ export class FieldEditor extends PureComponent {
};

saveField = async () => {
const field = this.state.field.toActualField();
const field = this.state.field;
const { indexPattern } = this.props;
const { fieldFormatId } = this.state;

Expand Down
48 changes: 0 additions & 48 deletions src/legacy/ui/public/field_editor/lib/__tests__/copy_field.test.js

This file was deleted.

82 changes: 0 additions & 82 deletions src/legacy/ui/public/field_editor/lib/copy_field.js

This file was deleted.

1 change: 0 additions & 1 deletion src/legacy/ui/public/field_editor/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
* under the License.
*/

export { copyField } from './copy_field';
export { executeScript, isScriptValid } from './validate_script';
7 changes: 0 additions & 7 deletions src/plugins/data/public/index_patterns/fields/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ export class Field implements IFieldType {
subType?: IFieldSubType;
displayName?: string;
format: any;
routes: Record<string, string> = {
edit: '/management/kibana/index_patterns/{{indexPattern.id}}/field/{{name}}',
};
$$spec: FieldSpec;

constructor(
Expand Down Expand Up @@ -146,7 +143,3 @@ export class Field implements IFieldType {
return obj.create();
}
}

Field.prototype.routes = {
edit: '/management/kibana/index_patterns/{{indexPattern.id}}/field/{{name}}',
};
13 changes: 7 additions & 6 deletions src/plugins/data/public/index_patterns/fields/field_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ export class FieldList extends Array<Field> implements IFieldList {
this.splice(fieldIndex, 1);
};

update = (field: Field) => {
const index = this.findIndex(f => f.name === field.name);
this.splice(index, 1, field);
this.setByName(field);
this.removeByGroup(field);
this.setByGroup(field);
update = (field: FieldSpec) => {
const newField = new Field(this.indexPattern, field, this.shortDotsEnable);
const index = this.findIndex(f => f.name === newField.name);
this.splice(index, 1, newField);
this.setByName(newField);
this.removeByGroup(newField);
this.setByGroup(newField);
};
}
4 changes: 1 addition & 3 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,6 @@ export class IndexPatternField implements IFieldType {
// (undocumented)
name: string;
// (undocumented)
routes: Record<string, string>;
// (undocumented)
script?: string;
// (undocumented)
scripted?: boolean;
Expand Down Expand Up @@ -978,7 +976,7 @@ export class IndexPatternFieldList extends Array<IndexPatternField> implements I
// (undocumented)
remove: (field: IFieldType) => void;
// (undocumented)
update: (field: IndexPatternField) => void;
update: (field: Record<string, any>) => void;
}

// Warning: (ae-missing-release-tag) "indexPatterns" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down

0 comments on commit 2871d7e

Please sign in to comment.