Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into kbn-65222-gs-so-p…
Browse files Browse the repository at this point in the history
…rovider
  • Loading branch information
pgayvallet committed Jul 2, 2020
2 parents 11caf68 + 1cfc935 commit 3ba6e89
Show file tree
Hide file tree
Showing 46 changed files with 745 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

## SavedObjectTypeRegistry.getAllTypes() method

Return all [types](./kibana-plugin-core-server.savedobjectstype.md) currently registered.
Return all [types](./kibana-plugin-core-server.savedobjectstype.md) currently registered, including the hidden ones.

To only get the visible types (which is the most common use case), use `getVisibleTypes` instead.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectTypeRegistry](./kibana-plugin-core-server.savedobjecttyperegistry.md) &gt; [getVisibleTypes](./kibana-plugin-core-server.savedobjecttyperegistry.getvisibletypes.md)

## SavedObjectTypeRegistry.getVisibleTypes() method

Returns all visible [types](./kibana-plugin-core-server.savedobjectstype.md)<!-- -->.

A visible type is a type that doesn't explicitly define `hidden=true` during registration.

<b>Signature:</b>

```typescript
getVisibleTypes(): SavedObjectsType[];
```
<b>Returns:</b>

`SavedObjectsType[]`

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export declare class SavedObjectTypeRegistry

| Method | Modifiers | Description |
| --- | --- | --- |
| [getAllTypes()](./kibana-plugin-core-server.savedobjecttyperegistry.getalltypes.md) | | Return all [types](./kibana-plugin-core-server.savedobjectstype.md) currently registered. |
| [getAllTypes()](./kibana-plugin-core-server.savedobjecttyperegistry.getalltypes.md) | | Return all [types](./kibana-plugin-core-server.savedobjectstype.md) currently registered, including the hidden ones.<!-- -->To only get the visible types (which is the most common use case), use <code>getVisibleTypes</code> instead. |
| [getImportableAndExportableTypes()](./kibana-plugin-core-server.savedobjecttyperegistry.getimportableandexportabletypes.md) | | Return all [types](./kibana-plugin-core-server.savedobjectstype.md) currently registered that are importable/exportable. |
| [getIndex(type)](./kibana-plugin-core-server.savedobjecttyperegistry.getindex.md) | | Returns the <code>indexPattern</code> property for given type, or <code>undefined</code> if the type is not registered. |
| [getType(type)](./kibana-plugin-core-server.savedobjecttyperegistry.gettype.md) | | Return the [type](./kibana-plugin-core-server.savedobjectstype.md) definition for given type name. |
| [getVisibleTypes()](./kibana-plugin-core-server.savedobjecttyperegistry.getvisibletypes.md) | | Returns all visible [types](./kibana-plugin-core-server.savedobjectstype.md)<!-- -->.<!-- -->A visible type is a type that doesn't explicitly define <code>hidden=true</code> during registration. |
| [isHidden(type)](./kibana-plugin-core-server.savedobjecttyperegistry.ishidden.md) | | Returns the <code>hidden</code> property for given type, or <code>false</code> if the type is not registered. |
| [isImportableAndExportable(type)](./kibana-plugin-core-server.savedobjecttyperegistry.isimportableandexportable.md) | | Returns the <code>management.importableAndExportable</code> property for given type, or <code>false</code> if the type is not registered or does not define a management section. |
| [isMultiNamespace(type)](./kibana-plugin-core-server.savedobjecttyperegistry.ismultinamespace.md) | | Returns whether the type is multi-namespace (shareable); resolves to <code>false</code> if the type is not registered |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const createRegistryMock = (): jest.Mocked<
const mock = {
registerType: jest.fn(),
getType: jest.fn(),
getVisibleTypes: jest.fn(),
getAllTypes: jest.fn(),
getImportableAndExportableTypes: jest.fn(),
isNamespaceAgnostic: jest.fn(),
Expand All @@ -35,6 +36,7 @@ const createRegistryMock = (): jest.Mocked<
isImportableAndExportable: jest.fn(),
};

mock.getVisibleTypes.mockReturnValue([]);
mock.getAllTypes.mockReturnValue([]);
mock.getImportableAndExportableTypes.mockReturnValue([]);
mock.getIndex.mockReturnValue('.kibana-test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,37 @@ describe('SavedObjectTypeRegistry', () => {
});
});

describe('#getVisibleTypes', () => {
it('returns only visible registered types', () => {
const typeA = createType({ name: 'typeA', hidden: false });
const typeB = createType({ name: 'typeB', hidden: true });
const typeC = createType({ name: 'typeC', hidden: false });
registry.registerType(typeA);
registry.registerType(typeB);
registry.registerType(typeC);

const registered = registry.getVisibleTypes();
expect(registered.length).toEqual(2);
expect(registered).toContainEqual(typeA);
expect(registered).toContainEqual(typeC);
});

it('does not mutate the registered types when altering the list', () => {
registry.registerType(createType({ name: 'typeA', hidden: false }));
registry.registerType(createType({ name: 'typeB', hidden: true }));
registry.registerType(createType({ name: 'typeC', hidden: false }));

const types = registry.getVisibleTypes();
types.splice(0, 2);

expect(registry.getVisibleTypes().length).toEqual(2);
});
});

describe('#getAllTypes', () => {
it('returns all registered types', () => {
const typeA = createType({ name: 'typeA' });
const typeB = createType({ name: 'typeB' });
const typeB = createType({ name: 'typeB', hidden: true });
const typeC = createType({ name: 'typeC' });
registry.registerType(typeA);
registry.registerType(typeB);
Expand Down
13 changes: 12 additions & 1 deletion src/core/server/saved_objects/saved_objects_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,18 @@ export class SavedObjectTypeRegistry {
}

/**
* Return all {@link SavedObjectsType | types} currently registered.
* Returns all visible {@link SavedObjectsType | types}.
*
* A visible type is a type that doesn't explicitly define `hidden=true` during registration.
*/
public getVisibleTypes() {
return [...this.types.values()].filter((type) => !this.isHidden(type.name));
}

/**
* Return all {@link SavedObjectsType | types} currently registered, including the hidden ones.
*
* To only get the visible types (which is the most common use case), use `getVisibleTypes` instead.
*/
public getAllTypes() {
return [...this.types.values()];
Expand Down
1 change: 1 addition & 0 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2468,6 +2468,7 @@ export class SavedObjectTypeRegistry {
getImportableAndExportableTypes(): SavedObjectsType[];
getIndex(type: string): string | undefined;
getType(type: string): SavedObjectsType | undefined;
getVisibleTypes(): SavedObjectsType[];
isHidden(type: string): boolean;
isImportableAndExportable(type: string): boolean;
isMultiNamespace(type: string): boolean;
Expand Down
5 changes: 1 addition & 4 deletions src/core/server/ui_settings/saved_objects/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export const uiSettingsType: SavedObjectsType = {
hidden: false,
namespaceType: 'single',
mappings: {
// we don't want to allow `true` in the public `SavedObjectsTypeMappingDefinition` type, however
// this is needed for the config that is kinda a special type. To avoid adding additional internal types
// just for this, we hardcast to any here.
dynamic: true as any,
dynamic: false,
properties: {
buildNum: {
type: 'keyword',
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/saved_objects/saved_objects_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export function savedObjectsMixin(kbnServer, server) {
const typeRegistry = kbnServer.newPlatform.start.core.savedObjects.getTypeRegistry();
const mappings = migrator.getActiveMappings();
const allTypes = typeRegistry.getAllTypes().map((t) => t.name);
const visibleTypes = typeRegistry.getVisibleTypes().map((t) => t.name);
const schema = new SavedObjectsSchema(convertTypesToLegacySchema(typeRegistry.getAllTypes()));
const visibleTypes = allTypes.filter((type) => !schema.isHiddenType(type));

server.decorate('server', 'kibanaMigrator', migrator);

Expand Down
16 changes: 16 additions & 0 deletions src/plugins/data/public/search/tabify/get_columns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,20 @@ describe('get columns', () => {
'Sum of @timestamp',
]);
});

test('should not fail if there is no field for date histogram agg', () => {
const columns = tabifyGetColumns(
createAggConfigs([
{
type: 'date_histogram',
schema: 'segment',
params: {},
},
{ type: 'sum', schema: 'metric', params: { field: '@timestamp' } },
]).aggs,
false
);

expect(columns.map((c) => c.name)).toEqual(['', 'Sum of @timestamp']);
});
});
9 changes: 8 additions & 1 deletion src/plugins/data/public/search/tabify/get_columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ import { IAggConfig } from '../aggs';
import { TabbedAggColumn } from './types';

const getColumn = (agg: IAggConfig, i: number): TabbedAggColumn => {
let name = '';
try {
name = agg.makeLabel();
} catch (e) {
// skip the case when makeLabel throws an error (e.x. no appropriate field for an aggregation)
}

return {
aggConfig: agg,
id: `col-${i}-${agg.id}`,
name: agg.makeLabel(),
name,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function DefaultEditorAggGroup({
<EuiSpacer size="s" />
{bucketsError && (
<>
<EuiFormErrorText>{bucketsError}</EuiFormErrorText>
<EuiFormErrorText data-test-subj="bucketsError">{bucketsError}</EuiFormErrorText>
<EuiSpacer size="s" />
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ function getAggParamsToRender({
const aggType = agg.type.type;
const aggName = agg.type.name;
const aggParams = get(aggParamsMap, [aggType, aggName], {});
paramEditor = get(aggParams, param.name) || get(aggParamsMap, ['common', param.type]);
paramEditor = get(aggParams, param.name);
}

if (!paramEditor) {
paramEditor = get(aggParamsMap, ['common', param.type]);
}

// show params with an editor component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ function SubMetricParamEditor({
defaultMessage: 'Bucket',
});
const type = aggParam.name;
const isCustomMetric = type === 'customMetric';

const aggTitle = type === 'customMetric' ? metricTitle : bucketTitle;
const aggGroup = type === 'customMetric' ? AggGroupNames.Metrics : AggGroupNames.Buckets;
const aggTitle = isCustomMetric ? metricTitle : bucketTitle;
const aggGroup = isCustomMetric ? AggGroupNames.Metrics : AggGroupNames.Buckets;

useMount(() => {
if (agg.params[type]) {
Expand Down Expand Up @@ -87,7 +88,7 @@ function SubMetricParamEditor({
setValidity={setValidity}
setTouched={setTouched}
schemas={schemas}
hideCustomLabel={true}
hideCustomLabel={!isCustomMetric}
/>
</>
);
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vis_type_table/public/table_vis_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { tableVisResponseHandler } from './table_vis_response_handler';
import tableVisTemplate from './table_vis.html';
import { TableOptions } from './components/table_vis_options_lazy';
import { getTableVisualizationControllerClass } from './vis_controller';
import { VIS_EVENT_TO_TRIGGER } from '../../../plugins/visualizations/public';

export function getTableVisTypeDefinition(core: CoreSetup, context: PluginInitializerContext) {
return {
Expand All @@ -39,6 +40,9 @@ export function getTableVisTypeDefinition(core: CoreSetup, context: PluginInitia
defaultMessage: 'Display values in a table',
}),
visualization: getTableVisualizationControllerClass(core, context),
getSupportedTriggers: () => {
return [VIS_EVENT_TO_TRIGGER.filter];
},
visConfig: {
defaults: {
perPage: 10,
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vis_type_tagcloud/public/tag_cloud_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { i18n } from '@kbn/i18n';
import { Schemas } from '../../vis_default_editor/public';

import { TagCloudOptions } from './components/tag_cloud_options';
import { VIS_EVENT_TO_TRIGGER } from '../../../plugins/visualizations/public';

// @ts-ignore
import { createTagCloudVisualization } from './components/tag_cloud_visualization';
Expand All @@ -31,6 +32,9 @@ export const createTagCloudVisTypeDefinition = (deps: TagCloudVisDependencies) =
name: 'tagcloud',
title: i18n.translate('visTypeTagCloud.vis.tagCloudTitle', { defaultMessage: 'Tag Cloud' }),
icon: 'visTagCloud',
getSupportedTriggers: () => {
return [VIS_EVENT_TO_TRIGGER.filter];
},
description: i18n.translate('visTypeTagCloud.vis.tagCloudDescription', {
defaultMessage: 'A group of words, sized according to their importance',
}),
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vis_type_vislib/public/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { getAreaOptionTabs, countLabel } from './utils/common_config';
import { createVislibVisController } from './vis_controller';
import { VisTypeVislibDependencies } from './plugin';
import { Rotates } from '../../charts/public';
import { VIS_EVENT_TO_TRIGGER } from '../../../plugins/visualizations/public';

export const createAreaVisTypeDefinition = (deps: VisTypeVislibDependencies) => ({
name: 'area',
Expand All @@ -49,6 +50,9 @@ export const createAreaVisTypeDefinition = (deps: VisTypeVislibDependencies) =>
defaultMessage: 'Emphasize the quantity beneath a line chart',
}),
visualization: createVislibVisController(deps),
getSupportedTriggers: () => {
return [VIS_EVENT_TO_TRIGGER.filter, VIS_EVENT_TO_TRIGGER.brush];
},
visConfig: {
defaults: {
type: 'area',
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vis_type_vislib/public/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { TimeMarker } from './vislib/visualizations/time_marker';
import { CommonVislibParams, ValueAxis } from './types';
import { VisTypeVislibDependencies } from './plugin';
import { ColorSchemas, ColorSchemaParams } from '../../charts/public';
import { VIS_EVENT_TO_TRIGGER } from '../../../plugins/visualizations/public';

export interface HeatmapVisParams extends CommonVislibParams, ColorSchemaParams {
type: 'heatmap';
Expand All @@ -48,6 +49,9 @@ export const createHeatmapVisTypeDefinition = (deps: VisTypeVislibDependencies)
description: i18n.translate('visTypeVislib.heatmap.heatmapDescription', {
defaultMessage: 'Shade cells within a matrix',
}),
getSupportedTriggers: () => {
return [VIS_EVENT_TO_TRIGGER.filter];
},
visualization: createVislibVisController(deps),
visConfig: {
defaults: {
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vis_type_vislib/public/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { getAreaOptionTabs, countLabel } from './utils/common_config';
import { createVislibVisController } from './vis_controller';
import { VisTypeVislibDependencies } from './plugin';
import { Rotates } from '../../charts/public';
import { VIS_EVENT_TO_TRIGGER } from '../../../plugins/visualizations/public';

export const createHistogramVisTypeDefinition = (deps: VisTypeVislibDependencies) => ({
name: 'histogram',
Expand All @@ -50,6 +51,9 @@ export const createHistogramVisTypeDefinition = (deps: VisTypeVislibDependencies
defaultMessage: 'Assign a continuous variable to each axis',
}),
visualization: createVislibVisController(deps),
getSupportedTriggers: () => {
return [VIS_EVENT_TO_TRIGGER.filter, VIS_EVENT_TO_TRIGGER.brush];
},
visConfig: {
defaults: {
type: 'histogram',
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vis_type_vislib/public/horizontal_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { getAreaOptionTabs, countLabel } from './utils/common_config';
import { createVislibVisController } from './vis_controller';
import { VisTypeVislibDependencies } from './plugin';
import { Rotates } from '../../charts/public';
import { VIS_EVENT_TO_TRIGGER } from '../../../plugins/visualizations/public';

export const createHorizontalBarVisTypeDefinition = (deps: VisTypeVislibDependencies) => ({
name: 'horizontal_bar',
Expand All @@ -48,6 +49,9 @@ export const createHorizontalBarVisTypeDefinition = (deps: VisTypeVislibDependen
defaultMessage: 'Assign a continuous variable to each axis',
}),
visualization: createVislibVisController(deps),
getSupportedTriggers: () => {
return [VIS_EVENT_TO_TRIGGER.filter, VIS_EVENT_TO_TRIGGER.brush];
},
visConfig: {
defaults: {
type: 'histogram',
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vis_type_vislib/public/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { getAreaOptionTabs, countLabel } from './utils/common_config';
import { createVislibVisController } from './vis_controller';
import { VisTypeVislibDependencies } from './plugin';
import { Rotates } from '../../charts/public';
import { VIS_EVENT_TO_TRIGGER } from '../../../plugins/visualizations/public';

export const createLineVisTypeDefinition = (deps: VisTypeVislibDependencies) => ({
name: 'line',
Expand All @@ -47,6 +48,9 @@ export const createLineVisTypeDefinition = (deps: VisTypeVislibDependencies) =>
defaultMessage: 'Emphasize trends',
}),
visualization: createVislibVisController(deps),
getSupportedTriggers: () => {
return [VIS_EVENT_TO_TRIGGER.filter, VIS_EVENT_TO_TRIGGER.brush];
},
visConfig: {
defaults: {
type: 'line',
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vis_type_vislib/public/pie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { getPositions, Positions } from './utils/collections';
import { createVislibVisController } from './vis_controller';
import { CommonVislibParams } from './types';
import { VisTypeVislibDependencies } from './plugin';
import { VIS_EVENT_TO_TRIGGER } from '../../../plugins/visualizations/public';

export interface PieVisParams extends CommonVislibParams {
type: 'pie';
Expand All @@ -47,6 +48,9 @@ export const createPieVisTypeDefinition = (deps: VisTypeVislibDependencies) => (
defaultMessage: 'Compare parts of a whole',
}),
visualization: createVislibVisController(deps),
getSupportedTriggers: () => {
return [VIS_EVENT_TO_TRIGGER.filter];
},
visConfig: {
defaults: {
type: 'pie',
Expand Down
Loading

0 comments on commit 3ba6e89

Please sign in to comment.