Skip to content

Commit

Permalink
[Rename] kibana_utils to opensearch_dashboards_utils (#102)
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
  • Loading branch information
kavilla authored Mar 11, 2021
1 parent 409b37b commit 13245d8
Show file tree
Hide file tree
Showing 120 changed files with 281 additions and 273 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# kibana-utils
# opensearch-dashboards-utils

Utilities for building Kibana plugins.
Utilities for building OpenSearch Dashboards plugins.

- [State containers](./docs/state_containers).
- [State syncing utilities](./docs/state_sync).
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import expect from '@kbn/expect';
import { DuplicateField, SavedObjectNotFound, KbnError } from './errors';
import expect from '@osd/expect';
import { DuplicateField, SavedObjectNotFound, OsdError } from './errors';

describe('errors', () => {
const errors = [new DuplicateField('dupfield'), new SavedObjectNotFound('dashboard', '123')];
Expand All @@ -33,8 +33,8 @@ describe('errors', () => {
expect(error.stack).to.not.be.empty();
});

it(`${className} is an instance of KbnError`, () => {
expect(error instanceof KbnError).to.be(true);
it(`${className} is an instance of OsdError`, () => {
expect(error instanceof OsdError).to.be(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/* eslint-disable max-classes-per-file */

// abstract error class
export class KbnError extends Error {
export class OsdError extends Error {
constructor(message: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
Expand All @@ -31,7 +31,7 @@ export class KbnError extends Error {
* when a mapping already exists for a field the user is attempting to add
* @param {String} name - the field name
*/
export class DuplicateField extends KbnError {
export class DuplicateField extends OsdError {
constructor(name: string) {
super(`The field "${name}" already exists in this mapping`);
}
Expand All @@ -40,7 +40,7 @@ export class DuplicateField extends KbnError {
/**
* A saved object was not found
*/
export class SavedObjectNotFound extends KbnError {
export class SavedObjectNotFound extends OsdError {
public savedObjectType: string;
public savedObjectId?: string;
constructor(type: string, id?: string, link?: string) {
Expand All @@ -63,7 +63,7 @@ export class SavedObjectNotFound extends KbnError {
* There was a scenario where we were importing objects with double-encoded JSON, and the system
* was silently failing. This error is now thrown in those scenarios.
*/
export class InvalidJSONProperty extends KbnError {
export class InvalidJSONProperty extends OsdError {
constructor(message: string) {
super(message);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## API Report File for "kibana"
## API Report File for "opensearch-dashboards"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts

import { ComponentType } from 'react';
import { Ensure } from '@kbn/utility-types';
import { Ensure } from '@osd/utility-types';
import { FC } from 'react';
import { Observable } from 'rxjs';
import React from 'react';
Expand All @@ -17,7 +17,7 @@ export type BaseState = object;
export interface BaseStateContainer<State extends BaseState> {
get: () => State;
set: (state: State) => void;
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "kibana" does not have an export "Observable"
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "opensearch-dashboards" does not have an export "Observable"
state$: Observable<State>;
}

Expand All @@ -33,7 +33,7 @@ export function createStateContainer<State extends BaseState>(defaultState: Stat
// @public
export function createStateContainer<State extends BaseState, PureTransitions extends object>(defaultState: State, pureTransitions: PureTransitions): ReduxLikeStateContainer<State, PureTransitions>;

// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "kibana" does not have an export "PureSelectors"
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "opensearch-dashboards" does not have an export "PureSelectors"
//
// @public
export function createStateContainer<State extends BaseState, PureTransitions extends object, PureSelectors extends object>(defaultState: State, pureTransitions: PureTransitions, pureSelectors: PureSelectors, options?: CreateStateContainerOptions): ReduxLikeStateContainer<State, PureTransitions, PureSelectors>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export const useContainerSelector = <Container extends StateContainer<any, any>,

/**
* Creates helpers for using {@link StateContainer | State Containers} with react
*
* TODO Update link
* Refer to {@link https://github.com/elastic/kibana/blob/master/src/plugins/kibana_utils/docs/state_containers/react.md | guide} for details
* @public
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* State containers are Redux-store-like objects meant to help you manage state in your services or apps.
* TODO: Update link
* Refer to {@link https://github.com/elastic/kibana/tree/master/src/plugins/kibana_utils/docs/state_containers | guides and examples} for more info
*
* @packageDocumentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { Observable } from 'rxjs';
import { Ensure } from '@kbn/utility-types';
import { Ensure } from '@osd/utility-types';
import { FC, ComponentType } from 'react';

/**
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/

/**
* In many places in Kibana we want to be agnostic to frontend view library,
* In many places in OpenSearch Dashboards we want to be agnostic to frontend view library,
* i.e. instead of exposing React-specific APIs we want to expose APIs that
* are orthogonal to any rendering library. This interface represents such UI
* components. UI component receives a DOM element and `props` through `render()`
* method, the `render()` method can be called many times.
*
* Although Kibana aims to be library agnostic, Kibana itself is written in React,
* Although Op aims to be library agnostic, OpenSearch Dashboards itself is written in React,
* thus here we define `UiComponent` which is an abstract unit of UI that can be
* implemented in any framework, but it maps easily to React components, i.e.
* `UiComponent<Props>` is like `React.ComponentType<Props>`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { defaultState, pureTransitions, TodoActions, TodoState } from '../state_containers/todomvc';
import { BaseState, BaseStateContainer, createStateContainer } from '../../common/state_containers';
import {
createKbnUrlStateStorage,
createOsdUrlStateStorage,
syncState,
INullableBaseStateContainer,
} from '../../public/state_sync';
Expand All @@ -31,7 +31,7 @@ const stateContainer = createStateContainer<TodoState, TodoActions>(defaultState
const { start, stop } = syncState({
stateContainer: withDefaultState(stateContainer, defaultState),
storageKey: '_s',
stateStorage: createKbnUrlStateStorage(),
stateStorage: createOsdUrlStateStorage(),
});

start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ your services or apps.
## Example

```ts
import { createStateContainer } from 'src/plugins/kibana_utils';
import { createStateContainer } from 'src/plugins/opensearch_dashboards_utils';

const container = createStateContainer(
{ count: 0 },
Expand All @@ -41,8 +41,8 @@ See demos [here](../../demos/state_containers/).
You can run them with

```
npx -q ts-node src/plugins/kibana_utils/demos/state_containers/counter.ts
npx -q ts-node src/plugins/kibana_utils/demos/state_containers/todomvc.ts
npx -q ts-node src/plugins/opensearch_dashboards_utils/demos/state_containers/counter.ts
npx -q ts-node src/plugins/opensearch_dashboards_utils/demos/state_containers/todomvc.ts
```

## Reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const defaultState: MyState = {
Create your a state container.

```ts
import { createStateContainer } from 'src/plugins/kibana_utils';
import { createStateContainer } from 'src/plugins/opensearch_dashboards_utils';

const container = createStateContainer<MyState>(defaultState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


```ts
import { createStateContainer, createStateContainerReactHelpers } from 'src/plugins/kibana_utils';
import { createStateContainer, createStateContainerReactHelpers } from 'src/plugins/opensearch_dashboards_utils';

const container = createStateContainer({});
export const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const setUiMode: PureTransition = state => uiMode => ({ ...state, uiMode });
You provide transitions as a second argument when you create your state container.

```ts
import { createStateContainer } from 'src/plugins/kibana_utils';
import { createStateContainer } from 'src/plugins/opensearch_dashboards_utils';

const container = createStateContainer(0, {
increment: (cnt: number) => (by: number) => cnt + by,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ State syncing utilities include:
- Subscribes to state changes and pushes them to state storage.
- Optionally subscribes to state storage changes and pushes them to state.
- Two types of storage compatible with `syncState`:
- [KbnUrlStateStorage](./storages/kbn_url_storage.md) - Serializes state and persists it to URL's query param in rison or hashed format.
- [OsdUrlStateStorage](./storages/osd_url_storage.md) - Serializes state and persists it to URL's query param in rison or hashed format.
Listens for state updates in the URL and pushes them back to state.
- [SessionStorageStateStorage](./storages/session_storage.md) - Serializes state and persists it to session storage.

Expand All @@ -33,11 +33,11 @@ State syncing utilities include:
import {
createStateContainer,
syncState,
createKbnUrlStateStorage,
} from 'src/plugins/kibana_utils/public';
createOsdUrlStateStorage,
} from 'src/plugins/opensearch_dashboards_utils/public';

const stateContainer = createStateContainer({ count: 0 });
const stateStorage = createKbnUrlStateStorage();
const stateStorage = createOsdUrlStateStorage();

const { start, stop } = syncState({
storageKey: '_a',
Expand All @@ -48,7 +48,7 @@ const { start, stop } = syncState({
start();

// state container change is synched to state storage
// kbnUrlStateStorage updates the URL to "/#?_a=(count:2)"
// osdUrlStateStorage updates the URL to "/#?_a=(count:2)"
stateContainer.set({ count: 2 });

stop();
Expand All @@ -58,11 +58,11 @@ stop();

See demo plugins [here](../../../../../examples/state_containers_examples).

To run them, start kibana with `--run-examples` flag.
To run them, start OpenSearch Dashboards with `--run-examples` flag.

## Reference

- [Syncing state with URL](./storages/kbn_url_storage.md).
- [Syncing state with URL](./storages/osd_url_storage.md).
- [Syncing state with sessionStorage](./storages/session_storage.md).
- [Setting up initial state](./initial_state.md).
- [Using without state containers](./no_state_containers.md).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Consider the following example:
const defaultState = { count: 0 }; // default application state

const stateContainer = createStateContainer(defaultState);
const stateStorage = createKbnUrlStateStorage();
const stateStorage = createOsdUrlStateStorage();

const { start, stop } = syncState({
storageKey: '_a',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
State syncing util doesn't have specific api for handling errors.
It expects that errors are handled on storage level.

see [KbnUrlStateStorage](./storages/kbn_url_storage.md#) error handling section for details.
see [OsdUrlStateStorage](./storages/osd_url_storage.md#) error handling section for details.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Consider the following scenario:
const defaultState = { count: 0 }; // default application state

const stateContainer = createStateContainer(defaultState);
const stateStorage = createKbnUrlStateStorage();
const stateStorage = createOsdUrlStateStorage();

const { start, stop } = syncState({
storageKey: '_a',
Expand Down Expand Up @@ -40,7 +40,7 @@ A possible synchronization for the state conflict above could look like this:
// window.location.href is "/#?_a=(count:2)"
const defaultState = { count: 0 }; // default application state

const urlStateStorage = createKbnUrlStateStorage();
const urlStateStorage = createOsdUrlStateStorage();

const initialStateFromUrl = urlStateStorage.get('_a');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class MyStateManager {

```ts
// app.ts
import { syncState, createKbnUrlStateStorage } from 'src/plugins/kibana_utils/public';
import { syncState, createOsdUrlStateStorage } from 'src/plugins/opensearch_dashboards_utils/public';
import { MyStateManager } from './my_state_manager';

const myStateManager = new MyStateManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Similar to [handling initial state](./initial_state.md) example, applications co

```ts
import { migrate } from '../app/state_helpers';
const urlStateStorage = createKbnUrlStateStorage();
const urlStateStorage = createOsdUrlStateStorage();
const initialStateFromUrl = urlStateStorage.get('_a');

// merge default state and initial state and migrate it to the current version
Expand All @@ -27,7 +27,7 @@ Since no application remount will happen, we need to transition to a new state o
```ts
import { migrate } from '../app/state_helpers';

const urlStateStorage = createKbnUrlStateStorage();
const urlStateStorage = createOsdUrlStateStorage();
const initialStateFromUrl = urlStateStorage.get('_a');

// merge default state and initial state and migrate them to current version if needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Two types of storage compatible with `syncState`:

- [KbnUrlStateStorage](./kbn_url_storage.md) - Serialises state and persists it to URL's query param in rison or hashed format (similar to what AppState & GlobalState did in legacy world).
- [OsdUrlStateStorage](./osd_url_storage.md) - Serialises state and persists it to URL's query param in rison or hashed format (similar to what AppState & GlobalState did in legacy world).
Listens for state updates in the URL and pushes updates back to state.
- [SessionStorageStateStorage](./session_storage.md) - Serializes state and persists it to session storage.
Loading

0 comments on commit 13245d8

Please sign in to comment.