Skip to content

Commit

Permalink
Move saved objects loader to dashboard plugin (elastic#124708)
Browse files Browse the repository at this point in the history
* Move SavedObjectLoader into the dashboard plugin

* Remove old comment recommending savedobjectloader

* Fix types
  • Loading branch information
rudolf authored Feb 10, 2022
1 parent 05f187a commit 00fb06c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import {
SavedObjectsFindOptionsReference,
SavedObjectReference,
} from 'kibana/public';
import { SavedObject } from '../types';
import { StringUtils } from './helpers/string_utils';
import { SavedObject } from '../../../saved_objects/public';
import { upperFirst } from './string_utils';

/**
* @deprecated
* @removeBy 8.0
*/
export interface SavedObjectLoaderFindOptions {
size?: number;
fields?: string[];
Expand All @@ -23,6 +27,8 @@ export interface SavedObjectLoaderFindOptions {

/**
* @deprecated
* @removeBy 8.0
*
* The SavedObjectLoader class provides some convenience functions
* to load and save one kind of saved objects (specified in the constructor).
*
Expand All @@ -46,7 +52,7 @@ export class SavedObjectLoader {

this.loaderProperties = {
name: `${this.lowercaseType}s`,
noun: StringUtils.upperFirst(this.type),
noun: upperFirst(this.type),
nouns: `${this.lowercaseType}s`,
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/dashboard/public/services/saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export type {
SavedObject,
SavedObjectsStart,
SavedObjectSaveOpts,
SavedObjectLoaderFindOptions,
} from '../../../saved_objects/public';
export {
showSaveModal,
SavedObjectLoader,
SavedObjectSaveModal,
getSavedObjectFinder,
} from '../../../saved_objects/public';
export { SavedObjectLoader } from './saved_object_loader';
export type { SavedObjectLoaderFindOptions } from './saved_object_loader';
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
* Side Public License, v 1.
*/

import { StringUtils } from './string_utils';
import { upperFirst } from './string_utils';

describe('StringUtils class', () => {
describe('static upperFirst', () => {
describe('StringUtils', () => {
describe('upperFirst', () => {
test('should converts the first character of string to upper case', () => {
expect(StringUtils.upperFirst()).toBe('');
expect(StringUtils.upperFirst('')).toBe('');
expect(upperFirst()).toBe('');
expect(upperFirst('')).toBe('');

expect(StringUtils.upperFirst('Fred')).toBe('Fred');
expect(StringUtils.upperFirst('fred')).toBe('Fred');
expect(StringUtils.upperFirst('FRED')).toBe('FRED');
expect(upperFirst('Fred')).toBe('Fred');
expect(upperFirst('fred')).toBe('Fred');
expect(upperFirst('FRED')).toBe('FRED');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
* Side Public License, v 1.
*/

export class StringUtils {
/**
* Returns a version of the string with the first letter capitalized.
* @param str {string}
* @returns {string}
*/
public static upperFirst(str: string = ''): string {
return str ? str.charAt(0).toUpperCase() + str.slice(1) : '';
}
/**
* Returns a version of the string with the first letter capitalized.
* @param str {string}
* @returns {string}
*/
export function upperFirst(str: string = ''): string {
return str ? str.charAt(0).toUpperCase() + str.slice(1) : '';
}
8 changes: 1 addition & 7 deletions src/plugins/saved_objects/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ export { SavedObjectSaveModal, SavedObjectSaveModalOrigin, showSaveModal } from
export type { SavedObjectFinderUiProps, SavedObjectMetaData } from './finder';
export { getSavedObjectFinder, SavedObjectFinderUi } from './finder';
export type {
SavedObjectLoaderFindOptions,
SavedObjectDecorator,
SavedObjectDecoratorFactory,
SavedObjectDecoratorConfig,
} from './saved_object';
export {
SavedObjectLoader,
checkForDuplicateTitle,
saveWithConfirmation,
isErrorNonFatal,
} from './saved_object';
export { checkForDuplicateTitle, saveWithConfirmation, isErrorNonFatal } from './saved_object';
export type { SavedObjectSaveOpts, SavedObject, SavedObjectConfig } from './types';
export { PER_PAGE_SETTING, LISTING_LIMIT_SETTING } from '../common';
export type { SavedObjectsStart, SavedObjectSetup } from './plugin';
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/saved_objects/public/saved_object/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/

export { createSavedObjectClass } from './saved_object';
export type { SavedObjectLoaderFindOptions } from './saved_object_loader';
export { SavedObjectLoader } from './saved_object_loader';
export { checkForDuplicateTitle } from './helpers/check_for_duplicate_title';
export { saveWithConfirmation } from './helpers/save_with_confirmation';
export { isErrorNonFatal } from './helpers/save_saved_object';
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/saved_objects/public/saved_object/saved_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export function createSavedObjectClass(
* provides additional functionality besides loading/saving/deleting/etc.
*
* It is overloaded and configured to provide type-aware functionality.
* To just retrieve the attributes of saved objects, it is recommended to use SavedObjectLoader
* which returns instances of SimpleSavedObject which don't introduce additional type-specific complexity.
* @param {*} config
*/
class SavedObjectClass {
Expand Down

0 comments on commit 00fb06c

Please sign in to comment.