Skip to content

Commit

Permalink
[visualizations] read only config flag for vis_types (#158507)
Browse files Browse the repository at this point in the history
Part of #154307

### Overview
PR adds `readOnly` configuration to all vis_type plugins.

### Test
* Start kibana with `yarn start --serverless=es`
* set the following yaml configuration values
    ```
    vis_type_gauge.readOnly: true
    vis_type_heatmap.readOnly: true
    vis_type_metric.readOnly: true
    vis_type_pie.readOnly: true
    vis_type_table.readOnly: true
    vis_type_tagcloud.readOnly: true
    vis_type_timelion.readOnly: true
    vis_type_timeseries.readOnly: true
    vis_type_vislib.readOnly: true
    vis_type_xy.readOnly: true
    ```

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
3 people authored May 30, 2023
1 parent b529887 commit 21151dd
Show file tree
Hide file tree
Showing 48 changed files with 517 additions and 127 deletions.
44 changes: 24 additions & 20 deletions src/plugins/dashboard/public/dashboard_app/top_nav/editor_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,29 +218,33 @@ export const EditorMenu = ({ createNewVisType, createNewEmbeddable }: Props) =>
});

const getEditorMenuPanels = (closePopover: () => void) => {
const initialPanelItems = [
...visTypeAliases.map(getVisTypeAliasMenuItem),
...Object.values(factoryGroupMap).map(({ id, appName, icon, panelId }) => ({
name: appName,
icon,
panel: panelId,
'data-test-subj': `dashboardEditorMenu-${id}Group`,
})),
...ungroupedFactories.map((factory) => {
return getEmbeddableFactoryMenuItem(factory, closePopover);
}),
...promotedVisTypes.map(getVisTypeMenuItem),
];
if (aggsBasedVisTypes.length > 0) {
initialPanelItems.push({
name: aggsPanelTitle,
icon: 'visualizeApp',
panel: aggBasedPanelID,
'data-test-subj': `dashboardEditorAggBasedMenuItem`,
});
}
initialPanelItems.push(...toolVisTypes.map(getVisTypeMenuItem));

return [
{
id: 0,
items: [
...visTypeAliases.map(getVisTypeAliasMenuItem),
...Object.values(factoryGroupMap).map(({ id, appName, icon, panelId }) => ({
name: appName,
icon,
panel: panelId,
'data-test-subj': `dashboardEditorMenu-${id}Group`,
})),
...ungroupedFactories.map((factory) => {
return getEmbeddableFactoryMenuItem(factory, closePopover);
}),
...promotedVisTypes.map(getVisTypeMenuItem),
{
name: aggsPanelTitle,
icon: 'visualizeApp',
panel: aggBasedPanelID,
'data-test-subj': `dashboardEditorAggBasedMenuItem`,
},
...toolVisTypes.map(getVisTypeMenuItem),
],
items: initialPanelItems,
},
{
id: aggBasedPanelID,
Expand Down
13 changes: 12 additions & 1 deletion src/plugins/vis_types/gauge/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),

readOnly: schema.conditional(
schema.contextRef('serverless'),
true,
schema.maybe(schema.boolean({ defaultValue: false })),
schema.never()
),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
export type GaugeConfig = TypeOf<typeof configSchema>;

export interface GaugePublicConfig {
readOnly?: boolean;
}
6 changes: 4 additions & 2 deletions src/plugins/vis_types/gauge/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
* Side Public License, v 1.
*/

import { PluginInitializerContext } from '@kbn/core/public';
import { GaugePublicConfig } from '../config';
import { VisTypeGaugePlugin } from './plugin';

export function plugin() {
return new VisTypeGaugePlugin();
export function plugin(initializerContext: PluginInitializerContext<GaugePublicConfig>) {
return new VisTypeGaugePlugin(initializerContext);
}

export type { VisTypeGaugePluginSetup, VisTypeGaugePluginStart } from './types';
Expand Down
22 changes: 19 additions & 3 deletions src/plugins/vis_types/gauge/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
* Side Public License, v 1.
*/

import { CoreSetup, CoreStart } from '@kbn/core/public';
import { CoreSetup, CoreStart, PluginInitializerContext } from '@kbn/core/public';
import { VisualizationsSetup } from '@kbn/visualizations-plugin/public';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { GaugePublicConfig } from '../config';
import { LEGACY_GAUGE_CHARTS_LIBRARY } from '../common';
import { VisTypeGaugePluginSetup } from './types';
import { gaugeVisType, goalVisType } from './vis_type';
Expand All @@ -27,14 +28,29 @@ export interface VisTypeGaugePluginStartDependencies {
}

export class VisTypeGaugePlugin {
private readonly initializerContext: PluginInitializerContext<GaugePublicConfig>;

constructor(initializerContext: PluginInitializerContext<GaugePublicConfig>) {
this.initializerContext = initializerContext;
}

public setup(
core: CoreSetup<VisTypeGaugeSetupDependencies>,
{ visualizations }: VisTypeGaugeSetupDependencies
): VisTypeGaugePluginSetup {
if (!core.uiSettings.get(LEGACY_GAUGE_CHARTS_LIBRARY)) {
const { readOnly } = this.initializerContext.config.get<GaugePublicConfig>();
const visTypeProps = { showElasticChartsOptions: true };
visualizations.createBaseVisualization(gaugeVisType(visTypeProps));
visualizations.createBaseVisualization(goalVisType(visTypeProps));
visualizations.createBaseVisualization({
...gaugeVisType(visTypeProps),
disableCreate: Boolean(readOnly),
disableEdit: Boolean(readOnly),
});
visualizations.createBaseVisualization({
...goalVisType(visTypeProps),
disableCreate: Boolean(readOnly),
disableEdit: Boolean(readOnly),
});
}

return {};
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/vis_types/gauge/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
* Side Public License, v 1.
*/

import { PluginConfigDescriptor } from '@kbn/core/server';
import { configSchema, ConfigSchema } from '../config';
import { PluginInitializerContext, PluginConfigDescriptor } from '@kbn/core/server';
import { configSchema, GaugeConfig } from '../config';
import { VisTypeGaugeServerPlugin } from './plugin';

export const config: PluginConfigDescriptor<ConfigSchema> = {
export const config: PluginConfigDescriptor<GaugeConfig> = {
exposeToBrowser: {
readOnly: true,
},
schema: configSchema,
};

export const plugin = () => new VisTypeGaugeServerPlugin();
export const plugin = (initializerContext: PluginInitializerContext) =>
new VisTypeGaugeServerPlugin(initializerContext);
20 changes: 18 additions & 2 deletions src/plugins/vis_types/gauge/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import { i18n } from '@kbn/i18n';
import { schema } from '@kbn/config-schema';

import { CoreSetup, Plugin, UiSettingsParams } from '@kbn/core/server';
import { CoreSetup, Plugin, PluginInitializerContext, UiSettingsParams } from '@kbn/core/server';
import type { VisualizationsServerSetup } from '@kbn/visualizations-plugin/server';
import { GaugeConfig } from '../config';

import { LEGACY_GAUGE_CHARTS_LIBRARY } from '../common';

Expand All @@ -34,10 +36,24 @@ export const getUiSettingsConfig: () => Record<string, UiSettingsParams<boolean>
},
});

interface PluginSetupDependencies {
visualizations: VisualizationsServerSetup;
}

export class VisTypeGaugeServerPlugin implements Plugin<object, object> {
public setup(core: CoreSetup) {
constructor(private readonly initializerContext: PluginInitializerContext) {
this.initializerContext = initializerContext;
}

public setup(core: CoreSetup, plugins: PluginSetupDependencies) {
core.uiSettings.register(getUiSettingsConfig());

const { readOnly } = this.initializerContext.config.get<GaugeConfig>();
if (readOnly) {
plugins.visualizations.registerReadOnlyVisType('gauge');
plugins.visualizations.registerReadOnlyVisType('goal');
}

return {};
}

Expand Down
13 changes: 12 additions & 1 deletion src/plugins/vis_types/heatmap/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),

readOnly: schema.conditional(
schema.contextRef('serverless'),
true,
schema.maybe(schema.boolean({ defaultValue: false })),
schema.never()
),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
export type HeatmapConfig = TypeOf<typeof configSchema>;

export interface HeatmapPublicConfig {
readOnly?: boolean;
}
5 changes: 4 additions & 1 deletion src/plugins/vis_types/heatmap/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
* Side Public License, v 1.
*/

import { PluginInitializerContext } from '@kbn/core/public';
import { HeatmapPublicConfig } from '../config';
import { VisTypeHeatmapPlugin } from './plugin';

export { heatmapVisType } from './vis_type';

export const plugin = () => new VisTypeHeatmapPlugin();
export const plugin = (initializerContext: PluginInitializerContext<HeatmapPublicConfig>) =>
new VisTypeHeatmapPlugin(initializerContext);
20 changes: 15 additions & 5 deletions src/plugins/vis_types/heatmap/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
* Side Public License, v 1.
*/

import { CoreSetup, CoreStart } from '@kbn/core/public';
import { CoreSetup, CoreStart, PluginInitializerContext } from '@kbn/core/public';
import type { VisualizationsSetup } from '@kbn/visualizations-plugin/public';
import type { ChartsPluginSetup } from '@kbn/charts-plugin/public';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { HeatmapPublicConfig } from '../config';
import { LEGACY_HEATMAP_CHARTS_LIBRARY } from '../common';
import { heatmapVisType } from './vis_type';
import { setDataViewsStart } from './services';
Expand All @@ -36,17 +37,26 @@ export interface VisTypeHeatmapStartDependencies {
}

export class VisTypeHeatmapPlugin {
private readonly initializerContext: PluginInitializerContext<HeatmapPublicConfig>;

constructor(initializerContext: PluginInitializerContext<HeatmapPublicConfig>) {
this.initializerContext = initializerContext;
}

setup(
core: CoreSetup<VisTypeHeatmapPluginStartDependencies>,
{ visualizations, charts, usageCollection }: VisTypeHeatmapSetupDependencies
) {
if (!core.uiSettings.get(LEGACY_HEATMAP_CHARTS_LIBRARY)) {
visualizations.createBaseVisualization(
heatmapVisType({
const { readOnly } = this.initializerContext.config.get<HeatmapPublicConfig>();
visualizations.createBaseVisualization({
...heatmapVisType({
showElasticChartsOptions: true,
palettes: charts.palettes,
})
);
}),
disableCreate: Boolean(readOnly),
disableEdit: Boolean(readOnly),
});
}
return {};
}
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/vis_types/heatmap/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
* Side Public License, v 1.
*/

import { PluginConfigDescriptor } from '@kbn/core/server';
import { configSchema, ConfigSchema } from '../config';
import { PluginConfigDescriptor, PluginInitializerContext } from '@kbn/core/server';
import { configSchema, HeatmapConfig } from '../config';
import { VisTypeHeatmapServerPlugin } from './plugin';

export const config: PluginConfigDescriptor<ConfigSchema> = {
export const config: PluginConfigDescriptor<HeatmapConfig> = {
exposeToBrowser: {
readOnly: true,
},
schema: configSchema,
};

export const plugin = () => new VisTypeHeatmapServerPlugin();
export const plugin = (initializerContext: PluginInitializerContext) =>
new VisTypeHeatmapServerPlugin(initializerContext);
19 changes: 17 additions & 2 deletions src/plugins/vis_types/heatmap/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import { i18n } from '@kbn/i18n';
import { schema } from '@kbn/config-schema';

import { CoreSetup, Plugin, UiSettingsParams } from '@kbn/core/server';
import { CoreSetup, Plugin, PluginInitializerContext, UiSettingsParams } from '@kbn/core/server';
import type { VisualizationsServerSetup } from '@kbn/visualizations-plugin/server';
import { HeatmapConfig } from '../config';

import { LEGACY_HEATMAP_CHARTS_LIBRARY } from '../common';

Expand Down Expand Up @@ -45,10 +47,23 @@ export const getUiSettingsConfig: () => Record<string, UiSettingsParams<boolean>
},
});

interface PluginSetupDependencies {
visualizations: VisualizationsServerSetup;
}

export class VisTypeHeatmapServerPlugin implements Plugin<object, object> {
public setup(core: CoreSetup) {
constructor(private readonly initializerContext: PluginInitializerContext) {
this.initializerContext = initializerContext;
}

public setup(core: CoreSetup, plugins: PluginSetupDependencies) {
core.uiSettings.register(getUiSettingsConfig());

const { readOnly } = this.initializerContext.config.get<HeatmapConfig>();
if (readOnly) {
plugins.visualizations.registerReadOnlyVisType('heatmap');
}

return {};
}

Expand Down
13 changes: 12 additions & 1 deletion src/plugins/vis_types/metric/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),

readOnly: schema.conditional(
schema.contextRef('serverless'),
true,
schema.maybe(schema.boolean({ defaultValue: false })),
schema.never()
),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
export type MetricConfig = TypeOf<typeof configSchema>;

export interface MetricPublicConfig {
readOnly?: boolean;
}
3 changes: 2 additions & 1 deletion src/plugins/vis_types/metric/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
*/

import { PluginInitializerContext } from '@kbn/core/public';
import { MetricPublicConfig } from '../config';
import { MetricVisPlugin as Plugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
export function plugin(initializerContext: PluginInitializerContext<MetricPublicConfig>) {
return new Plugin(initializerContext);
}
13 changes: 9 additions & 4 deletions src/plugins/vis_types/metric/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '@kbn/cor
import { VisualizationsSetup } from '@kbn/visualizations-plugin/public';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { createMetricVisTypeDefinition } from './metric_vis_type';
import { ConfigSchema } from '../config';
import { MetricPublicConfig } from '../config';
import { setDataViewsStart } from './services';

/** @internal */
Expand All @@ -27,14 +27,19 @@ export interface MetricVisPluginStartDependencies {
export class MetricVisPlugin
implements Plugin<void, void, MetricVisPluginSetupDependencies, MetricVisPluginStartDependencies>
{
initializerContext: PluginInitializerContext<ConfigSchema>;
initializerContext: PluginInitializerContext<MetricPublicConfig>;

constructor(initializerContext: PluginInitializerContext<ConfigSchema>) {
constructor(initializerContext: PluginInitializerContext<MetricPublicConfig>) {
this.initializerContext = initializerContext;
}

public setup(core: CoreSetup, { visualizations }: MetricVisPluginSetupDependencies) {
visualizations.createBaseVisualization(createMetricVisTypeDefinition());
const { readOnly } = this.initializerContext.config.get<MetricPublicConfig>();
visualizations.createBaseVisualization({
...createMetricVisTypeDefinition(),
disableCreate: Boolean(readOnly),
disableEdit: Boolean(readOnly),
});
}

public start(core: CoreStart, { dataViews }: MetricVisPluginStartDependencies) {
Expand Down
Loading

0 comments on commit 21151dd

Please sign in to comment.