Skip to content

Commit

Permalink
[Timelion] deangularize and typescriptify saved_object usage (#53125) (
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal authored Dec 18, 2019
1 parent 9dc29ce commit 4ecad44
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 101 deletions.
8 changes: 3 additions & 5 deletions src/legacy/core_plugins/timelion/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import 'ui/directives/saved_object_finder';
import 'ui/directives/listen';
import 'ui/kbn_top_nav';
import 'ui/saved_objects/ui/saved_object_save_as_checkbox';
import './services/saved_sheets';
import './services/_saved_sheet';
import './services/saved_sheet_register';

import rootTemplate from 'plugins/timelion/index.html';

Expand All @@ -57,13 +60,8 @@ document.title = 'Timelion - Kibana';

const app = require('ui/modules').get('apps/timelion', []);

require('plugins/timelion/services/saved_sheets');
require('plugins/timelion/services/_saved_sheet');

require('./vis');

SavedObjectRegistryProvider.register(require('plugins/timelion/services/saved_sheet_register'));

require('ui/routes').enable();

require('ui/routes').when('/:id?', {
Expand Down
82 changes: 0 additions & 82 deletions src/legacy/core_plugins/timelion/public/services/_saved_sheet.js

This file was deleted.

79 changes: 79 additions & 0 deletions src/legacy/core_plugins/timelion/public/services/_saved_sheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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 { createSavedObjectClass } from 'ui/saved_objects/saved_object';
import { SavedObjectKibanaServices } from 'ui/saved_objects/types';
import { IUiSettingsClient } from 'kibana/public';

// Used only by the savedSheets service, usually no reason to change this
export function createSavedSheetClass(
services: SavedObjectKibanaServices,
config: IUiSettingsClient
) {
const SavedObjectClass = createSavedObjectClass(services);

class SavedSheet extends SavedObjectClass {
static type = 'timelion-sheet';

// if type:sheet has no mapping, we push this mapping into ES
static mapping = {
title: 'text',
hits: 'integer',
description: 'text',
timelion_sheet: 'text',
timelion_interval: 'keyword',
timelion_other_interval: 'keyword',
timelion_chart_height: 'integer',
timelion_columns: 'integer',
timelion_rows: 'integer',
version: 'integer',
};

// Order these fields to the top, the rest are alphabetical
static fieldOrder = ['title', 'description'];
// SavedSheet constructor. Usually you'd interact with an instance of this.
// ID is option, without it one will be generated on save.
constructor(id: string) {
super({
type: SavedSheet.type,
mapping: SavedSheet.mapping,

// if this is null/undefined then the SavedObject will be assigned the defaults
id,

// default values that will get assigned if the doc is new
defaults: {
title: 'New TimeLion Sheet',
hits: 0,
description: '',
timelion_sheet: ['.es(*)'],
timelion_interval: 'auto',
timelion_chart_height: 275,
timelion_columns: config.get('timelion:default_columns') || 2,
timelion_rows: config.get('timelion:default_rows') || 2,
version: 1,
},
});
this.showInRecentlyAccessed = true;
this.getFullPath = () => `/app/timelion#/${this.id}`;
}
}

return SavedSheet;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/

import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_registry';
import './saved_sheets';

export default function savedSearchObjectFn(savedSheets) {
SavedObjectRegistryProvider.register((savedSheets: any) => {
return savedSheets;
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/

import { SavedObjectLoader, SavedObjectsClientProvider } from 'ui/saved_objects';
import { npStart } from 'ui/new_platform';
import { SavedObjectLoader } from 'ui/saved_objects';
// @ts-ignore
import { savedObjectManagementRegistry } from 'plugins/kibana/management/saved_object_registry';
// @ts-ignore
import { uiModules } from 'ui/modules';
import './_saved_sheet.js';
import { npStart } from '../../../../ui/public/new_platform';
import { createSavedSheetClass } from './_saved_sheet';

const module = uiModules.get('app/sheet');

Expand All @@ -33,17 +34,23 @@ savedObjectManagementRegistry.register({
});

// This is the only thing that gets injected into controllers
module.service('savedSheets', function(Private, SavedSheet, kbnUrl) {
const savedObjectClient = Private(SavedObjectsClientProvider);
module.service('savedSheets', function() {
const savedObjectsClient = npStart.core.savedObjects.client;
const services = {
savedObjectsClient,
indexPatterns: npStart.plugins.data.indexPatterns,
chrome: npStart.core.chrome,
overlays: npStart.core.overlays,
};

const SavedSheet = createSavedSheetClass(services, npStart.core.uiSettings);

const savedSheetLoader = new SavedObjectLoader(
SavedSheet,
savedObjectClient,
savedObjectsClient,
npStart.core.chrome
);
savedSheetLoader.urlFor = function(id) {
return kbnUrl.eval('#/{{id}}', { id: id });
};

savedSheetLoader.urlFor = id => `#/${encodeURIComponent(id)}`;
// Customize loader properties since adding an 's' on type doesn't work for type 'timelion-sheet'.
savedSheetLoader.loaderProperties = {
name: 'timelion-sheet',
Expand Down

0 comments on commit 4ecad44

Please sign in to comment.