-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ui-state-actions.ts
516 lines (488 loc) · 14.9 KB
/
ui-state-actions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
// Copyright (c) 2023 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 {default as ActionTypes} from './action-types';
import {Merge} from '@kepler.gl/types';
import {ExportImage} from '@kepler.gl/constants';
/** TOGGLE_SIDE_PANEL */
export type ToggleSidePanelUpdaterAction = {
payload: string | null;
};
/**
* Toggle active side panel
* @memberof uiStateActions
* @param id id of side panel to be shown, one of `layer`, `filter`, `interaction`, `map`
* @public
*/
export const toggleSidePanel: (
id: string | null
) => Merge<
ToggleSidePanelUpdaterAction,
{type: typeof ActionTypes.TOGGLE_SIDE_PANEL}
> = createAction(ActionTypes.TOGGLE_SIDE_PANEL, (id: string | null) => ({payload: id}));
/** TOGGLE_MODAL */
export type ToggleModalUpdaterAction = {
payload: string | null;
};
/**
* Show and hide modal dialog
* @memberof uiStateActions
* @param id - id of modal to be shown, null to hide modals. One of:
* - [`DATA_TABLE_ID`](../constants/default-settings.md#data_table_id)
* - [`DELETE_DATA_ID`](../constants/default-settings.md#delete_data_id)
* - [`ADD_DATA_ID`](../constants/default-settings.md#add_data_id)
* - [`EXPORT_IMAGE_ID`](../constants/default-settings.md#export_image_id)
* - [`EXPORT_DATA_ID`](../constants/default-settings.md#export_data_id)
* - [`ADD_MAP_STYLE_ID`](../constants/default-settings.md#add_map_style_id)
* @public
*/
export const toggleModal: (
id: ToggleModalUpdaterAction['payload']
) => Merge<ToggleModalUpdaterAction, {type: typeof ActionTypes.TOGGLE_MODAL}> = createAction(
ActionTypes.TOGGLE_MODAL,
(id: ToggleModalUpdaterAction['payload']) => ({
payload: id
})
);
/** SHOW_EXPORT_DROPDOWN */
export type ShowExportDropdownUpdaterAction = {
payload: string;
};
/**
* Hide and show side panel header dropdown, activated by clicking the share link on top of the side panel
* @memberof uiStateActions
* @param id - id of the dropdown
* @public
*/
export const showExportDropdown: (
id: ShowExportDropdownUpdaterAction['payload']
) => Merge<
ShowExportDropdownUpdaterAction,
{type: typeof ActionTypes.SHOW_EXPORT_DROPDOWN}
> = createAction(
ActionTypes.SHOW_EXPORT_DROPDOWN,
(id: ShowExportDropdownUpdaterAction['payload']) => ({payload: id})
);
/**
* Hide side panel header dropdown, activated by clicking the share link on top of the side panel
* @memberof uiStateActions
* @public
*/
export const hideExportDropdown: () => {
type: typeof ActionTypes.HIDE_EXPORT_DROPDOWN;
} = createAction(ActionTypes.HIDE_EXPORT_DROPDOWN);
/** TOGGLE_SIDE_PANEL_CLOSE_BUTTON*/
export type ToggleSidePanelCloseButtonUpdaterAction = {
payload: {
show: boolean;
};
};
/**
* Toggle side panel close button
* @memberof uiStateActions
* @param show - if side panel button visible
* @public
*/
export const toggleSidePanelCloseButton: (
show: boolean
) => Merge<
ToggleSidePanelCloseButtonUpdaterAction,
{type: typeof ActionTypes.TOGGLE_SIDE_PANEL_CLOSE_BUTTON}
> = createAction(ActionTypes.TOGGLE_SIDE_PANEL_CLOSE_BUTTON, show => ({payload: {show}}));
/** TOGGLE_MAP_CONTROL */
export type ToggleMapControlUpdaterAction = {
payload: {
panelId: string;
index: number;
};
};
/**
* Toggle active map control panel
* @memberof uiStateActions
* @param panelId - map control panel id, one of the keys of: [`DEFAULT_MAP_CONTROLS`](#default_map_controls)
* @public
*/
export const toggleMapControl: (
panelId: ToggleMapControlUpdaterAction['payload']['panelId'],
index: ToggleMapControlUpdaterAction['payload']['index']
) => Merge<
ToggleMapControlUpdaterAction,
{type: typeof ActionTypes.TOGGLE_MAP_CONTROL}
> = createAction(
ActionTypes.TOGGLE_MAP_CONTROL,
(
panelId: ToggleMapControlUpdaterAction['payload']['panelId'],
index: ToggleMapControlUpdaterAction['payload']['index']
) => ({
payload: {
panelId,
index
}
})
);
/** SET_MAP_CONTROL_VISIBILITY */
export type setMapControlVisibilityUpdaterAction = {
payload: {
panelId: string;
show: boolean;
};
};
/**
* Toggle active map control panel
* @memberof uiStateActions
* @param panelId - map control panel id, one of the keys of: [`DEFAULT_MAP_CONTROLS`](#default_map_controls)
* @public
*/
export const setMapControlVisibility: (
panelId: setMapControlVisibilityUpdaterAction['payload']['panelId'],
show: setMapControlVisibilityUpdaterAction['payload']['show']
) => Merge<
setMapControlVisibilityUpdaterAction,
{type: typeof ActionTypes.SET_MAP_CONTROL_VISIBILITY}
> = createAction(
ActionTypes.SET_MAP_CONTROL_VISIBILITY,
(
panelId: setMapControlVisibilityUpdaterAction['payload']['panelId'],
show: setMapControlVisibilityUpdaterAction['payload']['show']
) => ({
payload: {
panelId,
show
}
})
);
/** OPEN_DELETE_MODAL */
export type OpenDeleteModalUpdaterAction = {
payload: string;
};
/**
* Toggle active map control panel
* @memberof uiStateActions
* @param datasetId - `id` of the dataset to be deleted
* @public
*/
export const openDeleteModal: (
datasetId: OpenDeleteModalUpdaterAction['payload']
) => Merge<
OpenDeleteModalUpdaterAction,
{type: typeof ActionTypes.OPEN_DELETE_MODAL}
> = createAction(
ActionTypes.OPEN_DELETE_MODAL,
(datasetId: OpenDeleteModalUpdaterAction['payload']) => ({payload: datasetId})
);
/** ADD_NOTIFICATION */
export type AddNotificationUpdaterAction = {
payload: object;
};
/**
* Add a notification to be displayed.
* Existing notification will be updated in case of matching id.
* @memberof uiStateActions
* @param notification - The `notification` object to be added or updated
* @public
*/
export const addNotification: (
notification: AddNotificationUpdaterAction['payload']
) => Merge<
AddNotificationUpdaterAction,
{
type: typeof ActionTypes.ADD_NOTIFICATION;
}
> = createAction(
ActionTypes.ADD_NOTIFICATION,
(notification: AddNotificationUpdaterAction['payload']) => ({payload: notification})
);
/** REMOVE_NOTIFICATION */
export type RemoveNotificationUpdaterAction = {
payload: string;
};
/**
* Remove a notification
* @memberof uiStateActions
* @param id - `id` of the notification to be removed
* @public
*/
export const removeNotification: (
id: RemoveNotificationUpdaterAction['payload']
) => Merge<
RemoveNotificationUpdaterAction,
{type: typeof ActionTypes.REMOVE_NOTIFICATION}
> = createAction(
ActionTypes.REMOVE_NOTIFICATION,
(id: RemoveNotificationUpdaterAction['payload']) => ({payload: id})
);
/** SET_EXPORT_IMAGE_SETTING */
export type SetExportImageSettingUpdaterAction = {
payload: Partial<ExportImage>;
};
/**
* Set `exportImage` settings: ratio, resolution, legend
* @memberof uiStateActions
* @param newSetting - {ratio: '1x'}
* @public
*/
export const setExportImageSetting: (
newSetting: SetExportImageSettingUpdaterAction['payload']
) => Merge<
SetExportImageSettingUpdaterAction,
{type: typeof ActionTypes.SET_EXPORT_IMAGE_SETTING}
> = createAction(
ActionTypes.SET_EXPORT_IMAGE_SETTING,
(newSetting: SetExportImageSettingUpdaterAction['payload']) => ({payload: newSetting})
);
/**
* Start exporting image flow
* @memberof uiStateActions
* @public
*/
export const startExportingImage: (options?: {
ratio?: string;
resolution?: string;
legend?: string;
center?: boolean;
}) => Merge<
SetExportImageSettingUpdaterAction,
{type: typeof ActionTypes.START_EXPORTING_IMAGE}
> = createAction(ActionTypes.START_EXPORTING_IMAGE, (payload: any) => ({payload}));
/** SET_EXPORT_IMAGE_DATA_URI */
export type SetExportImageDataUriUpdaterAction = {
payload: string;
};
/**
* Set `exportImage.setExportImageDataUri` to a dataUri
* @memberof uiStateActions
* @param dataUri - export image data uri
* @public
*/
export const setExportImageDataUri: (
dataUri: SetExportImageDataUriUpdaterAction['payload']
) => Merge<
SetExportImageDataUriUpdaterAction,
{type: typeof ActionTypes.SET_EXPORT_IMAGE_DATA_URI}
> = createAction(
ActionTypes.SET_EXPORT_IMAGE_DATA_URI,
(dataUri: SetExportImageDataUriUpdaterAction['payload']) => ({payload: dataUri})
);
/** SET_EXPORT_IMAGE_ERROR */
export type SetExportImageErrorUpdaterAction = {
payload: Error;
};
/**
* Set Export image error
* @memberof uiStateActions
* @public
*/
export const setExportImageError: (
error: SetExportImageErrorUpdaterAction['payload']
) => Merge<
SetExportImageErrorUpdaterAction,
{type: typeof ActionTypes.SET_EXPORT_IMAGE_ERROR}
> = createAction(
ActionTypes.SET_EXPORT_IMAGE_ERROR,
(error: SetExportImageErrorUpdaterAction['payload']) => ({payload: error})
);
/**
* Delete cached export image
* @memberof uiStateActions
* @public
*/
export const cleanupExportImage: () => {
type: typeof ActionTypes.CLEANUP_EXPORT_IMAGE;
} = createAction(ActionTypes.CLEANUP_EXPORT_IMAGE);
/** SET_EXPORT_SELECTED_DATASET */
export type SetExportSelectedDatasetUpdaterAction = {
payload: string;
};
/**
* Set selected dataset for export
* @memberof uiStateActions
* @param datasetId - dataset id
* @public
*/
export const setExportSelectedDataset: (
datasetId: SetExportSelectedDatasetUpdaterAction['payload']
) => Merge<
SetExportSelectedDatasetUpdaterAction,
{type: typeof ActionTypes.SET_EXPORT_SELECTED_DATASET}
> = createAction(
ActionTypes.SET_EXPORT_SELECTED_DATASET,
(datasetId: SetExportSelectedDatasetUpdaterAction['payload']) => ({payload: datasetId})
);
/** SET_EXPORT_DATA_TYPE */
export type SetExportDataTypeUpdaterAction = {
payload: string;
};
/**
* Set data format for exporting data
* @memberof uiStateActions
* @param dataType - one of `'text/csv'`
* @public
*/
export const setExportDataType: (
dataType: SetExportDataTypeUpdaterAction['payload']
) => Merge<
SetExportDataTypeUpdaterAction,
{type: typeof ActionTypes.SET_EXPORT_DATA_TYPE}
> = createAction(
ActionTypes.SET_EXPORT_DATA_TYPE,
(dataType: SetExportDataTypeUpdaterAction['payload']) => ({payload: dataType})
);
/** SET_EXPORT_FILTERED */
export type SetExportFilteredUpdaterAction = {
payload: boolean;
};
/**
* Whether to export filtered data, `true` or `false`
* @memberof uiStateActions
* @param payload - set `true` to ony export filtered data
* @public
*/
export const setExportFiltered: (
exportFiltered: SetExportFilteredUpdaterAction['payload']
) => Merge<
SetExportFilteredUpdaterAction,
{type: typeof ActionTypes.SET_EXPORT_FILTERED}
> = createAction(
ActionTypes.SET_EXPORT_FILTERED,
(payload: SetExportFilteredUpdaterAction['payload']) => ({payload})
);
/**
* Whether to including data in map config, toggle between `true` or `false`
* @memberof uiStateActions
* @public
*/
export const setExportData: () => {type: typeof ActionTypes.SET_EXPORT_DATA} = createAction(
ActionTypes.SET_EXPORT_DATA
);
/** SET_USER_MAPBOX_ACCESS_TOKEN */
export type SetUserMapboxAccessTokenUpdaterAction = {
payload: string;
};
/**
* Whether we export a mapbox access token used to create a single map html file
* @memberof uiStateActions
* @param payload - mapbox access token
* @public
*/
export const setUserMapboxAccessToken: (
payload: SetUserMapboxAccessTokenUpdaterAction['payload']
) => Merge<
SetUserMapboxAccessTokenUpdaterAction,
{type: typeof ActionTypes.SET_USER_MAPBOX_ACCESS_TOKEN}
> = createAction(
ActionTypes.SET_USER_MAPBOX_ACCESS_TOKEN,
(payload: SetUserMapboxAccessTokenUpdaterAction['payload']) => ({payload})
);
/** SET_EXPORT_MAP_FORMAT */
export type SetExportMapFormatUpdaterAction = {
payload: string;
};
/**
* Set the export map format (html, json)
* @memberOf uiStateActions
* @param payload - map format
* @public
*/
export const setExportMapFormat: (
mapFormat: SetExportMapFormatUpdaterAction['payload']
) => Merge<
SetExportMapFormatUpdaterAction,
{type: typeof ActionTypes.SET_EXPORT_MAP_FORMAT}
> = createAction(
ActionTypes.SET_EXPORT_MAP_FORMAT,
(payload: SetExportMapFormatUpdaterAction['payload']) => ({payload})
);
/** SET_EXPORT_MAP_HTML_MODE */
export type SetExportHTMLMapModeUpdaterAction = {
payload: string;
};
/**
* Set the HTML mode to use to export HTML mode
* @memberOf uiStateActions
* @param payload - map mode
*/
export const setExportHTMLMapMode: (
mode: SetExportHTMLMapModeUpdaterAction['payload']
) => Merge<
SetExportHTMLMapModeUpdaterAction,
{type: typeof ActionTypes.SET_EXPORT_MAP_HTML_MODE}
> = createAction(
ActionTypes.SET_EXPORT_MAP_HTML_MODE,
(payload: SetExportHTMLMapModeUpdaterAction['payload']) => ({payload})
);
/** SET_LOCALE */
export type SetLocaleUpdaterAction = {
payload: {locale: string};
};
/**
* Set `locale` value
* @memberof uiStateActions
* @param locale - locale of the UI
* @public
*/
export const setLocale: (
locale: SetLocaleUpdaterAction['payload']['locale']
) => Merge<SetLocaleUpdaterAction, {type: typeof ActionTypes.SET_LOCALE}> = createAction(
ActionTypes.SET_LOCALE,
(locale: SetLocaleUpdaterAction['payload']['locale']) => ({
payload: {
locale
}
})
);
/** TOGGLE_PANEL_LIST_VIEW */
export type TogglePanelListViewAction = {
payload: {
panelId: string;
listView: string;
};
};
/**
* Toggle layer panel list view
* @memberof uiStateActions
* @param payload
* @param payload.panelId panel id.
* @param payload.listView layer panel listView value. Can be 'list' or 'sortByDataset'
* @public
*/
export const togglePanelListView: (
payload: TogglePanelListViewAction['payload']
) => Merge<
TogglePanelListViewAction,
{type: typeof ActionTypes.TOGGLE_PANEL_LIST_VIEW}
> = createAction(
ActionTypes.TOGGLE_PANEL_LIST_VIEW,
(payload: TogglePanelListViewAction['payload']) => ({payload})
);
/**
* This declaration is needed to group actions in docs
*/
/**
* Actions handled mostly by `uiState` reducer.
* They manage UI changes in tha app, such as open and close side panel,
* switch between tabs in the side panel, open and close modal dialog for exporting data / images etc.
* It also manges which settings are selected during image and map export
*
* @public
*/
/* eslint-disable no-unused-vars */
// @ts-ignore
const uiStateActions = null;
/* eslint-enable no-unused-vars */