Skip to content

Commit

Permalink
input control read only (#158853)
Browse files Browse the repository at this point in the history
Part of #154307

### Test
* Start kibana with `yarn start --serverless=es`
* set the following yaml configuration values
    ```
    input_control_vis.readOnly: true
    ```

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
nreese and kibanamachine authored Jun 2, 2023
1 parent 7c8ddd0 commit 0eab3fb
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 6 deletions.
24 changes: 24 additions & 0 deletions src/plugins/input_control_vis/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { schema, TypeOf } from '@kbn/config-schema';

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

export type InputControlConfig = TypeOf<typeof configSchema>;

export interface InputControlPublicConfig {
readOnly?: boolean;
}
2 changes: 1 addition & 1 deletion src/plugins/input_control_vis/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Adds Input Control visualization to Kibana",
"plugin": {
"id": "inputControlVis",
"server": false,
"server": true,
"browser": true,
"requiredPlugins": [
"data",
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/input_control_vis/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

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

export function plugin(initializerContext: PluginInitializerContext) {
export function plugin(initializerContext: PluginInitializerContext<InputControlPublicConfig>) {
return new Plugin(initializerContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { toExpressionAst } from './to_ast';
import { InputControlVisParams } from './types';

export function createInputControlVisTypeDefinition(
deps: InputControlVisDependencies
deps: InputControlVisDependencies,
readOnly: boolean
): VisTypeDefinition<InputControlVisParams> {
const ControlsTab = getControlsTab(deps);

Expand All @@ -29,7 +30,8 @@ export function createInputControlVisTypeDefinition(
defaultMessage: 'Input controls are deprecated and will be removed in a future version.',
}),
stage: 'experimental',
disableCreate: true,
disableCreate: true, // input controls are deprecated and input control creation has been permanently disabled
disableEdit: readOnly,
isDeprecated: true,
visConfig: {
defaults: {
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/input_control_vis/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { VisualizationsSetup, VisualizationsStart } from '@kbn/visualizations-pl
import { createInputControlVisFn } from './input_control_fn';
import { getInputControlVisRenderer } from './input_control_vis_renderer';
import { createInputControlVisTypeDefinition } from './input_control_vis_type';
import { InputControlPublicConfig } from '../config';

type InputControlVisCoreSetup = CoreSetup<InputControlVisPluginStartDependencies, void>;

Expand Down Expand Up @@ -51,7 +52,7 @@ export interface InputControlVisPluginStartDependencies {

/** @internal */
export class InputControlVisPlugin implements Plugin<void, void> {
constructor(public initializerContext: PluginInitializerContext) {}
constructor(public initializerContext: PluginInitializerContext<InputControlPublicConfig>) {}

public setup(
core: InputControlVisCoreSetup,
Expand All @@ -69,8 +70,9 @@ export class InputControlVisPlugin implements Plugin<void, void> {

expressions.registerFunction(createInputControlVisFn);
expressions.registerRenderer(getInputControlVisRenderer(visualizationDependencies));
const { readOnly } = this.initializerContext.config.get<InputControlPublicConfig>();
visualizations.createBaseVisualization(
createInputControlVisTypeDefinition(visualizationDependencies)
createInputControlVisTypeDefinition(visualizationDependencies, Boolean(readOnly))
);
}

Expand Down
36 changes: 36 additions & 0 deletions src/plugins/input_control_vis/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { CoreSetup, PluginConfigDescriptor, PluginInitializerContext } from '@kbn/core/server';
import type { VisualizationsServerSetup } from '@kbn/visualizations-plugin/server';

import { configSchema, InputControlConfig } from '../config';

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

interface PluginSetupDependencies {
visualizations: VisualizationsServerSetup;
}

export const plugin = (initializerContext: PluginInitializerContext) => ({
setup(core: CoreSetup, plugins: PluginSetupDependencies) {
const { readOnly } = initializerContext.config.get<InputControlConfig>();
if (readOnly) {
plugins.visualizations.registerReadOnlyVisType('input_control_vis');
}

return {};
},

start() {},
});
2 changes: 2 additions & 0 deletions src/plugins/input_control_vis/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"include": [
"public/**/*",
"server/**/*",
"*.ts",
],
"kbn_references": [
"@kbn/kibana-react-plugin",
Expand All @@ -21,6 +22,7 @@
"@kbn/expect",
"@kbn/i18n-react",
"@kbn/test-jest-helpers",
"@kbn/config-schema",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'usageCollection.uiCounters.debug (boolean)',
'usageCollection.uiCounters.enabled (boolean)',
// readOnly is boolean flag
'input_control_vis.readOnly (any)',
'vis_type_gauge.readOnly (any)',
'vis_type_heatmap.readOnly (any)',
'vis_type_metric.readOnly (any)',
Expand Down

0 comments on commit 0eab3fb

Please sign in to comment.