forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typescriptify dashboard redux code (elastic#19857)
* Typescriptify dashboard redux code * Address code review comments * minor fixes * move all type dependencies to dev
- Loading branch information
1 parent
fbbd5c1
commit 26da49e
Showing
41 changed files
with
1,325 additions
and
879 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 0 additions & 60 deletions
60
src/core_plugins/kibana/public/dashboard/actions/embeddables.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
src/core_plugins/kibana/public/dashboard/actions/embeddables.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* 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 _ from 'lodash'; | ||
import { Dispatch } from 'redux'; | ||
import { createAction } from 'redux-actions'; | ||
import { | ||
CoreKibanaState, | ||
getEmbeddableCustomization, | ||
getPanel, | ||
} from '../../selectors'; | ||
import { PanelId, PanelState } from '../selectors'; | ||
import { updatePanel } from './panels'; | ||
|
||
import { EmbeddableMetadata, EmbeddableState } from 'ui/embeddable'; | ||
import { KibanaAction } from '../../selectors/types'; | ||
|
||
export enum EmbeddableActionTypeKeys { | ||
EMBEDDABLE_IS_INITIALIZING = 'EMBEDDABLE_IS_INITIALIZING', | ||
EMBEDDABLE_IS_INITIALIZED = 'EMBEDDABLE_IS_INITIALIZED', | ||
SET_STAGED_FILTER = 'SET_STAGED_FILTER', | ||
CLEAR_STAGED_FILTERS = 'CLEAR_STAGED_FILTERS', | ||
EMBEDDABLE_ERROR = 'EMBEDDABLE_ERROR', | ||
} | ||
|
||
export interface EmbeddableIsInitializingAction | ||
extends KibanaAction< | ||
EmbeddableActionTypeKeys.EMBEDDABLE_IS_INITIALIZING, | ||
PanelId | ||
> {} | ||
|
||
export interface EmbeddableIsInitializedActionPayload { | ||
panelId: PanelId; | ||
metadata: EmbeddableMetadata; | ||
} | ||
|
||
export interface EmbeddableIsInitializedAction | ||
extends KibanaAction< | ||
EmbeddableActionTypeKeys.EMBEDDABLE_IS_INITIALIZED, | ||
EmbeddableIsInitializedActionPayload | ||
> {} | ||
|
||
export interface SetStagedFilterActionPayload { | ||
panelId: PanelId; | ||
stagedFilter: object; | ||
} | ||
|
||
export interface SetStagedFilterAction | ||
extends KibanaAction< | ||
EmbeddableActionTypeKeys.SET_STAGED_FILTER, | ||
SetStagedFilterActionPayload | ||
> {} | ||
|
||
export interface ClearStagedFiltersAction | ||
extends KibanaAction< | ||
EmbeddableActionTypeKeys.CLEAR_STAGED_FILTERS, | ||
undefined | ||
> {} | ||
|
||
export interface EmbeddableErrorActionPayload { | ||
error: string | object; | ||
panelId: PanelId; | ||
} | ||
|
||
export interface EmbeddableErrorAction | ||
extends KibanaAction< | ||
EmbeddableActionTypeKeys.EMBEDDABLE_ERROR, | ||
EmbeddableErrorActionPayload | ||
> {} | ||
|
||
export type EmbeddableActions = | ||
| EmbeddableIsInitializingAction | ||
| EmbeddableIsInitializedAction | ||
| ClearStagedFiltersAction | ||
| SetStagedFilterAction | ||
| EmbeddableErrorAction; | ||
|
||
export const embeddableIsInitializing = createAction<PanelId>( | ||
EmbeddableActionTypeKeys.EMBEDDABLE_IS_INITIALIZING | ||
); | ||
export const embeddableIsInitialized = createAction< | ||
EmbeddableIsInitializedActionPayload | ||
>(EmbeddableActionTypeKeys.EMBEDDABLE_IS_INITIALIZED); | ||
export const setStagedFilter = createAction<SetStagedFilterActionPayload>( | ||
EmbeddableActionTypeKeys.SET_STAGED_FILTER | ||
); | ||
export const clearStagedFilters = createAction( | ||
EmbeddableActionTypeKeys.CLEAR_STAGED_FILTERS | ||
); | ||
export const embeddableError = createAction<EmbeddableErrorActionPayload>( | ||
EmbeddableActionTypeKeys.EMBEDDABLE_ERROR | ||
); | ||
|
||
/** | ||
* The main point of communication from the embeddable to the dashboard. Any time state in the embeddable | ||
* changes, this function will be called. The data is then extracted from EmbeddableState and stored in | ||
* redux so the appropriate actions are taken and UI updated. | ||
* | ||
* @param changeData.panelId - the id of the panel whose state has changed. | ||
* @param changeData.embeddableState - the new state of the embeddable. | ||
*/ | ||
export function embeddableStateChanged(changeData: { | ||
panelId: PanelId; | ||
embeddableState: EmbeddableState; | ||
}) { | ||
const { panelId, embeddableState } = changeData; | ||
return ( | ||
dispatch: Dispatch<CoreKibanaState>, | ||
getState: () => CoreKibanaState | ||
) => { | ||
// Translate embeddableState to things redux cares about. | ||
const customization = getEmbeddableCustomization(getState(), panelId); | ||
if (!_.isEqual(embeddableState.customization, customization)) { | ||
const originalPanelState = getPanel(getState(), panelId); | ||
const newPanelState: PanelState = { | ||
...originalPanelState, | ||
embeddableConfig: _.cloneDeep(embeddableState.customization), | ||
}; | ||
dispatch(updatePanel(newPanelState)); | ||
} | ||
|
||
if (embeddableState.stagedFilter) { | ||
dispatch( | ||
setStagedFilter({ stagedFilter: embeddableState.stagedFilter, panelId }) | ||
); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/core_plugins/kibana/public/dashboard/actions/metadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 { createAction } from 'redux-actions'; | ||
import { KibanaAction } from '../../selectors/types'; | ||
|
||
export enum MetadataActionTypeKeys { | ||
UPDATE_DESCRIPTION = 'UPDATE_DESCRIPTION', | ||
UPDATE_TITLE = 'UPDATE_TITLE', | ||
} | ||
|
||
export type UpdateTitleActionPayload = string; | ||
|
||
export interface UpdateTitleAction | ||
extends KibanaAction< | ||
MetadataActionTypeKeys.UPDATE_TITLE, | ||
UpdateTitleActionPayload | ||
> {} | ||
|
||
export type UpdateDescriptionActionPayload = string; | ||
|
||
export interface UpdateDescriptionAction | ||
extends KibanaAction< | ||
MetadataActionTypeKeys.UPDATE_DESCRIPTION, | ||
UpdateDescriptionActionPayload | ||
> {} | ||
|
||
export type MetadataActions = UpdateDescriptionAction | UpdateTitleAction; | ||
|
||
export const updateDescription = createAction<UpdateDescriptionAction>( | ||
MetadataActionTypeKeys.UPDATE_DESCRIPTION | ||
); | ||
export const updateTitle = createAction<UpdateTitleAction>( | ||
MetadataActionTypeKeys.UPDATE_TITLE | ||
); |
43 changes: 0 additions & 43 deletions
43
src/core_plugins/kibana/public/dashboard/actions/panels.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.