-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathactions.ts
548 lines (474 loc) · 14 KB
/
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
import { makeConstant } from "@aics/redux-utils";
import Annotation from "../../entity/Annotation";
import FileFilter from "../../entity/FileFilter";
import FileFolder from "../../entity/FileFolder";
import FileSelection from "../../entity/FileSelection";
import FileSet from "../../entity/FileSet";
import FileSort from "../../entity/FileSort";
import NumericRange from "../../entity/NumericRange";
import Tutorial from "../../entity/Tutorial";
import { Dataset } from "../../services/DatasetService";
const STATE_BRANCH_NAME = "selection";
/**
* SET_FILE_FILTERS
*
* Intention to set, wholesale, a list of FileFilters into application state. This should not be dispatched
* by UI components; dispatch either an ADD_FILE_FILTER or REMOVE_FILE_FILTER action. Those actions will
* trigger the `modifyFileFilters` logic, which will then dispatch this action.
*/
export const SET_FILE_FILTERS = makeConstant(STATE_BRANCH_NAME, "set-file-filters");
export interface SetFileFiltersAction {
payload: FileFilter[];
type: string;
}
export function setFileFilters(filters: FileFilter[]): SetFileFiltersAction {
return {
payload: filters,
type: SET_FILE_FILTERS,
};
}
/**
* ADD_FILE_FILTER
*
* Intention to apply a FileFilter.
*/
export const ADD_FILE_FILTER = makeConstant(STATE_BRANCH_NAME, "add-file-filter");
export interface AddFileFilterAction {
payload: FileFilter | FileFilter[];
type: string;
}
export function addFileFilter(filter: FileFilter | FileFilter[]): AddFileFilterAction {
return {
payload: filter,
type: ADD_FILE_FILTER,
};
}
/**
* REMOVE_FILE_FILTER
*
* Intention to remove a currently applied FileFilter.
*/
export const REMOVE_FILE_FILTER = makeConstant(STATE_BRANCH_NAME, "remove-file-filter");
export interface RemoveFileFilterAction {
payload: FileFilter | FileFilter[];
type: string;
}
export function removeFileFilter(filter: FileFilter | FileFilter[]): RemoveFileFilterAction {
return {
payload: filter,
type: REMOVE_FILE_FILTER,
};
}
/**
* SORT_COLUMN
*
* Intention to sort files by a specific column
*/
export const SORT_COLUMN = makeConstant(STATE_BRANCH_NAME, "sort-column");
export interface SortColumnAction {
payload: string;
type: string;
}
export function sortColumn(annotation: string): SortColumnAction {
return {
payload: annotation,
type: SORT_COLUMN,
};
}
/**
* SET_SORT_COLUMN
*
* Intention to set the column to sort on
*/
export const SET_SORT_COLUMN = makeConstant(STATE_BRANCH_NAME, "set-sort-column");
export interface SetSortColumnAction {
payload?: FileSort;
type: string;
}
export function setSortColumn(fileSort?: FileSort): SetSortColumnAction {
return {
payload: fileSort,
type: SET_SORT_COLUMN,
};
}
/**
* SELECT_DISPLAY_ANNOTATION
*
* Intention to select one or many annotations for a file to display in the file list (i.e., as a column).
*
* For example, by default, we may only see "File name | File size | Date created" as the columns in the file list. This
* is the mechanism for a user to then add a column to view. If `replace` is `true`, the intention of the action
* should be interpreted as a setter instead of a updated.
*/
export const SELECT_DISPLAY_ANNOTATION = makeConstant(
STATE_BRANCH_NAME,
"select-display-annotation"
);
export interface SelectDisplayAnnotationAction {
payload: {
annotation: Annotation | Annotation[];
replace: boolean;
};
type: string;
}
export function selectDisplayAnnotation(
annotation: Annotation | Annotation[],
replace = false
): SelectDisplayAnnotationAction {
return {
payload: {
annotation,
replace,
},
type: SELECT_DISPLAY_ANNOTATION,
};
}
/**
* DESELECT_DISPLAY_ANNOTATION
*
* Intention to deselect one or many annotations from the columns of the file list. See comment for
* SELECT_DISPLAY_ANNOTATION for further explanation.
*/
export const DESELECT_DISPLAY_ANNOTATION = makeConstant(
STATE_BRANCH_NAME,
"deselect-display-annotation"
);
export interface DeselectDisplayAnnotationAction {
payload: {
annotation: Annotation | Annotation[];
};
type: string;
}
export function deselectDisplayAnnotation(
annotation: Annotation | Annotation[]
): DeselectDisplayAnnotationAction {
return {
payload: {
annotation,
},
type: DESELECT_DISPLAY_ANNOTATION,
};
}
/**
* RESIZE_COLUMN
*
* Intention to specify a particular amount of horizontal space a column within a file list should take up.
*/
export const RESIZE_COLUMN = makeConstant(STATE_BRANCH_NAME, "resize-column");
export interface ResizeColumnAction {
payload: {
columnHeader: string;
widthPercent: number; // between 0 and 1
};
type: string;
}
export function resizeColumn(columnHeader: string, widthPercent: number) {
return {
payload: {
columnHeader,
widthPercent,
},
type: RESIZE_COLUMN,
};
}
/**
* RESET_COLUMN_WIDTH
*
* Intention to remove a previous manual resizing of a column using the ResizeColumnAction. The expectation
* is that if no specific mapping between a column and a width exists in state, a default will apply.
*/
export const RESET_COLUMN_WIDTH = makeConstant(STATE_BRANCH_NAME, "reset-column-width");
export interface ResetColumnWidthAction {
payload: string; // columnHeader
type: string;
}
export function resetColumnWidth(columnHeader: string) {
return {
payload: columnHeader,
type: RESET_COLUMN_WIDTH,
};
}
/**
* SELECT_FILE
*
* Intention to mark one or many files as "selected." If `payload.updateExistingSelection`, add `payload.file` to
* existing selection, else, replace existing selection. The last selected file will be displayed by default in the
* details pane. Other uses for file selection are file download, dataset creation, and opening files with another tool.
*/
export const SELECT_FILE = makeConstant(STATE_BRANCH_NAME, "select-file");
interface SelectFileActionPayload {
fileSet: FileSet;
lastTouched?: number | undefined; // last index selected
selection: number | NumericRange;
sortOrder: number;
updateExistingSelection?: boolean;
}
export interface SelectFileAction {
payload: SelectFileActionPayload;
type: string;
}
export function selectFile(payload: SelectFileActionPayload): SelectFileAction {
const {
fileSet,
lastTouched = undefined,
selection,
sortOrder,
updateExistingSelection = false,
} = payload;
return {
payload: {
fileSet,
selection,
sortOrder,
updateExistingSelection,
lastTouched,
},
type: SELECT_FILE,
};
}
/**
* SELECT_NEARBY_FILE
*
* Intention to mark the file directly above or below as "selected." If `payload.updateExistingSelection`, add the
* corresponding file to the existing selection, else, replace existing selection. The newly selected file will be displayed
* within the file details pane.
*/
export const SELECT_NEARBY_FILE = makeConstant(STATE_BRANCH_NAME, "select-nearby-file");
export interface SelectNearbyFileAction {
payload: {
direction: "up" | "down";
updateExistingSelection: boolean;
};
type: string;
}
export function selectNearbyFile(
direction: "up" | "down",
updateExistingSelection: boolean
): SelectNearbyFileAction {
return {
payload: {
direction,
updateExistingSelection,
},
type: SELECT_NEARBY_FILE,
};
}
/**
* CHANGE_VIEW
*
* Intention is to select a pre-saved view to switch to (a view includes things like filters and sorts).
*/
export const CHANGE_VIEW = makeConstant(STATE_BRANCH_NAME, "change-view");
export interface ChangeView {
payload: string;
type: string;
}
export function changeView(view: string): ChangeView {
return {
payload: view,
type: CHANGE_VIEW,
};
}
/**
* SET_FILE_SELECTION
*
* This is not to be fired by UI; use the SELECT_FILE action instead.
*
* Setter-type action fired by selection/logics:selectFile, which intercepts SELECT_FILE actions,
* processes them along with existing selection state to create exact selection payloads that can
* be set directly into state. The seperation is to allow keeping a large amount of business logic
* out of the reducer.
*/
export const SET_FILE_SELECTION = makeConstant(STATE_BRANCH_NAME, "set-file-selection");
export interface SetFileSelection {
payload: FileSelection;
type: string;
}
export function setFileSelection(selection: FileSelection): SetFileSelection {
return {
payload: selection,
type: SET_FILE_SELECTION,
};
}
/**
* REORDER_ANNOTATION_HIERARCHY
* Intention to reorder an annotation within the hierachy of annotations by which to group files.
* By specifying an annotation not previously in the hierachy and any index within the hierachy (or N + 1, in the case of adding to end of hierarchy), this action also handles adding new annotations to the hierarchy.
*/
export const REORDER_ANNOTATION_HIERARCHY = makeConstant(
STATE_BRANCH_NAME,
"reorder-annotation-hierarchy"
);
export interface ReorderAnnotationHierarchyAction {
payload: {
id: string; // annotation_name
moveTo: number; // new index
};
type: string;
}
export function reorderAnnotationHierarchy(
annotationName: string,
moveTo: number
): ReorderAnnotationHierarchyAction {
return {
payload: {
id: annotationName,
moveTo,
},
type: REORDER_ANNOTATION_HIERARCHY,
};
}
/**
* REMOVE_FROM_ANNOTATION_HIERARCHY
* Intention to remove an annotation from the hierarchy of annotations by which to group files.
*/
export const REMOVE_FROM_ANNOTATION_HIERARCHY = makeConstant(
STATE_BRANCH_NAME,
"remove-from-annotation-hierarchy"
);
export interface RemoveFromAnnotationHierarchyAction {
payload: {
id: string; // annotation_name
};
type: string;
}
export function removeFromAnnotationHierarchy(
annotationName: string
): RemoveFromAnnotationHierarchyAction {
return {
payload: {
id: annotationName,
},
type: REMOVE_FROM_ANNOTATION_HIERARCHY,
};
}
/**
* SET_ANNOTATION_HIERARCHY
* Intention to set hierarchy of annotations by which to group files.
*/
export const SET_ANNOTATION_HIERARCHY = makeConstant(STATE_BRANCH_NAME, "set-annotation-hierarchy");
export interface SetAnnotationHierarchyAction {
payload: Annotation[];
type: string;
}
export function setAnnotationHierarchy(annotations: Annotation[]): SetAnnotationHierarchyAction {
return {
payload: annotations,
type: SET_ANNOTATION_HIERARCHY,
};
}
/**
* SET_AVAILABLE_ANNOTATIONS
* Intention to set annotations available for addition to the current hierarchy
*/
export const SET_AVAILABLE_ANNOTATIONS = makeConstant(
STATE_BRANCH_NAME,
"set-available-annotations"
);
export interface SetAvailableAnnotationsAction {
payload: string[];
type: string;
}
export function setAvailableAnnotations(annotationNames: string[]): SetAvailableAnnotationsAction {
return {
payload: annotationNames,
type: SET_AVAILABLE_ANNOTATIONS,
};
}
/**
* TOGGLE_FILE_FOLDER_COLLAPSE
* Intention to toggle the given file folder's collapsed state
*/
export const TOGGLE_FILE_FOLDER_COLLAPSE = makeConstant(
STATE_BRANCH_NAME,
"toggle-file-folder-collapse"
);
export interface ToggleFileFolderCollapseAction {
payload: FileFolder;
type: string;
}
export function toggleFileFolderCollapse(fileFolder: FileFolder): ToggleFileFolderCollapseAction {
return {
payload: fileFolder,
type: TOGGLE_FILE_FOLDER_COLLAPSE,
};
}
/**
* SET_OPEN_FILE_FOLDERS
* Intention to set which file folders are open as opposed to collapsed
*/
export const SET_OPEN_FILE_FOLDERS = makeConstant(STATE_BRANCH_NAME, "set-open-file-folders");
export interface SetOpenFileFoldersAction {
payload: FileFolder[];
type: string;
}
export function setOpenFileFolders(openFileFolders: FileFolder[]): SetOpenFileFoldersAction {
return {
payload: openFileFolders,
type: SET_OPEN_FILE_FOLDERS,
};
}
/**
* DECODE_FILE_EXPLORER_URL
*
* Intention to decode an incoming file explorer URL into application state
*/
export const DECODE_FILE_EXPLORER_URL = makeConstant(STATE_BRANCH_NAME, "decode-file-explorer-url");
export interface DecodeFileExplorerURLAction {
payload: string;
type: string;
}
export function decodeFileExplorerURL(decodedFileExplorerURL: string): DecodeFileExplorerURLAction {
return {
payload: decodedFileExplorerURL,
type: DECODE_FILE_EXPLORER_URL,
};
}
/**
* CHANGE_COLLECTION
*
* Intention to update the collection queries are run against.
*/
export const CHANGE_COLLECTION = makeConstant(STATE_BRANCH_NAME, "change-collection");
export interface ChangeCollectionAction {
payload?: Dataset;
type: string;
}
export function changeCollection(collection?: Dataset): ChangeCollectionAction {
return {
payload: collection,
type: CHANGE_COLLECTION,
};
}
/**
* SELECT_TUTORIAL
*
* Intention to update the current tutorial step displayed to users
*/
export const SELECT_TUTORIAL = makeConstant(STATE_BRANCH_NAME, "select-tutorial");
export interface SelectTutorial {
payload?: Tutorial;
type: string;
}
export function selectTutorial(tutorial?: Tutorial): SelectTutorial {
return {
payload: tutorial,
type: SELECT_TUTORIAL,
};
}
/**
* ADJUST_GLOBAL_FONT_SIZE
*
* Intention to set whether the current font size should be small or the default
*/
export const ADJUST_GLOBAL_FONT_SIZE = makeConstant(STATE_BRANCH_NAME, "adjust-global-font-size");
export interface AdjustGlobalFontSize {
payload: boolean;
type: string;
}
export function adjustGlobalFontSize(shouldDisplaySmallFont: boolean): AdjustGlobalFontSize {
return {
payload: shouldDisplaySmallFont,
type: ADJUST_GLOBAL_FONT_SIZE,
};
}