// Copyright (c) 2022 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. import {createAction} from '@reduxjs/toolkit'; import ActionTypes from 'constants/action-types'; import {UiState} from 'reducers/ui-state-updaters'; export type RegisterEntryUpdaterAction = { payload: { id: string; mint?: boolean; mapboxApiAccessToken?: string; mapboxApiUrl?: string; mapStylesReplaceDefault?: boolean; initialUiState?: Partial; }; }; /** * * Add a new kepler.gl instance in `keplerGlReducer`. This action is called under-the-hood when a `KeplerGl` component is **mounted** to the dom. * Note that if you dispatch actions such as adding data to a kepler.gl instance before the React component is mounted, the action will not be * performed. Instance reducer can only handle actions when it is instantiated. * @memberof rootActions * @param payload * @param payload.id - ***required** The id of the instance * @param payload.mint - Whether to use a fresh empty state, when `mint: true` it will *always* load a fresh state when the component is re-mounted. * When `mint: false` it will register with existing instance state under the same `id`, when the component is unmounted then mounted again. Default: `true` * @param payload.mapboxApiAccessToken - mapboxApiAccessToken to be saved in `map-style` reducer. * @param payload.mapboxApiUrl - mapboxApiUrl to be saved in `map-style` reducer. * @param payload.mapStylesReplaceDefault - mapStylesReplaceDefault to be saved in `map-style` reducer. * @param payload.initialUiState - initial ui state * @public */ export const registerEntry: ( entry: RegisterEntryUpdaterAction['payload'] ) => { type: typeof ActionTypes.REGISTER_ENTRY; payload: RegisterEntryUpdaterAction['payload']; } = createAction(ActionTypes.REGISTER_ENTRY, (payload: RegisterEntryUpdaterAction['payload']) => ({ payload })); /** * * Delete an instance from `keplerGlReducer`. This action is called under-the-hood when a `KeplerGl` component is **un-mounted** to the dom. * If `mint` is set to be `true` in the component prop, the instance state will be deleted from the root reducer. Otherwise, the root reducer will keep * the instance state and later transfer it to a newly mounted component with the same `id` * @memberof rootActions * @param {string} id - the id of the instance to be deleted * @public */ export const deleteEntry: ( id: string ) => { type: typeof ActionTypes.DELETE_ENTRY; payload: string; } = createAction(ActionTypes.DELETE_ENTRY, (id: string) => ({payload: id})); /** * * Rename an instance in the root reducer, keep its entire state * * @memberof rootActions * @param {string} oldId - ***required** old id * @param {string} newId - ***required** new id * @public */ export const renameEntry: ( oldId: string, newId: string ) => { type: typeof ActionTypes.RENAME_ENTRY; payload: { oldId: string; newId: string; }; } = createAction(ActionTypes.RENAME_ENTRY, (oldId: string, newId: string) => ({ payload: { oldId, newId } })); /** * This declaration is needed to group actions in docs */ /** * Root actions managers adding and removing instances in root reducer. * Under-the-hood, when a `KeplerGl` component is mounted or unmounted, * it will automatically calls these actions to add itself to the root reducer. * However, sometimes the data is ready before the component is registered in the reducer, * in this case, you can manually call these actions or the corresponding updater to add it to the reducer. * * @public */ /* eslint-disable no-unused-vars */ // @ts-ignore const rootActions = null; /* eslint-enable no-unused-vars */