dce-reactkit 3.2.2-beta.44 → 3.2.2-beta.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Type of the context map in a LogMetadata file
3
+ * @author Gabe Abrams
4
+ */
5
+ declare type LogMetadataContextMap = {
6
+ [k: string]: (string | {
7
+ _: string;
8
+ [k: string]: string;
9
+ });
10
+ };
11
+ export default LogMetadataContextMap;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Type of the tag map inside a LogMetadata file
3
+ * @author Gabe Abrams
4
+ */
5
+ declare type LogMetadataTagMap = {
6
+ [k: string]: string;
7
+ };
8
+ export default LogMetadataTagMap;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Type of the target map inside a LogMetadata file
3
+ * @author Gabe Abrams
4
+ */
5
+ declare type LogMetadataTargetMap = {
6
+ [k: string]: string;
7
+ };
8
+ export default LogMetadataTargetMap;
@@ -1,19 +1,13 @@
1
+ import LogMetadataContextMap from './LogMetadataContextMap';
2
+ import LogMetadataTagMap from './LogMetadataTagMap';
3
+ import LogMetadataTargetMap from './LogMetadataTargetMap';
1
4
  /**
2
5
  * Type of a LogMetadata file
3
6
  * @author Gabe Abrams
4
7
  */
5
8
  declare type LogMetadataType = {
6
- Context?: {
7
- [k: string]: (string | {
8
- _: string;
9
- [k: string]: string;
10
- });
11
- };
12
- Tag?: {
13
- [k: string]: string;
14
- };
15
- Target?: {
16
- [k: string]: string;
17
- };
9
+ Context?: LogMetadataContextMap;
10
+ Tag?: LogMetadataTagMap;
11
+ Target?: LogMetadataTargetMap;
18
12
  };
19
13
  export default LogMetadataType;
package/dist/index.d.ts CHANGED
@@ -369,23 +369,41 @@ declare type Props$3 = {
369
369
  };
370
370
  declare const ItemPicker: React.FC<Props$3>;
371
371
 
372
+ /**
373
+ * Type of the context map in a LogMetadata file
374
+ * @author Gabe Abrams
375
+ */
376
+ declare type LogMetadataContextMap = {
377
+ [k: string]: (string | {
378
+ _: string;
379
+ [k: string]: string;
380
+ });
381
+ };
382
+
383
+ /**
384
+ * Type of the tag map inside a LogMetadata file
385
+ * @author Gabe Abrams
386
+ */
387
+ declare type LogMetadataTagMap = {
388
+ [k: string]: string;
389
+ };
390
+
391
+ /**
392
+ * Type of the target map inside a LogMetadata file
393
+ * @author Gabe Abrams
394
+ */
395
+ declare type LogMetadataTargetMap = {
396
+ [k: string]: string;
397
+ };
398
+
372
399
  /**
373
400
  * Type of a LogMetadata file
374
401
  * @author Gabe Abrams
375
402
  */
376
403
  declare type LogMetadataType = {
377
- Context?: {
378
- [k: string]: (string | {
379
- _: string;
380
- [k: string]: string;
381
- });
382
- };
383
- Tag?: {
384
- [k: string]: string;
385
- };
386
- Target?: {
387
- [k: string]: string;
388
- };
404
+ Context?: LogMetadataContextMap;
405
+ Tag?: LogMetadataTagMap;
406
+ Target?: LogMetadataTargetMap;
389
407
  };
390
408
 
391
409
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.2.2-beta.44",
3
+ "version": "3.2.2-beta.47",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -31,6 +31,7 @@ import ModalType from '../types/ModalType';
31
31
  import CheckboxButton from './CheckboxButton';
32
32
  import CSVDownloadButton from './CSVDownloadButton';
33
33
  import Variant from '../types/Variant';
34
+ import { alert } from './AppWrapper';
34
35
 
35
36
  /*------------------------------------------------------------------------*/
36
37
  /* Types */
@@ -92,6 +93,10 @@ enum ActionType {
92
93
  UpdateColumnVisibility = 'update-column-visibility',
93
94
  // Toggle the column visibility customization modal
94
95
  ToggleColVisCusModalVisibility = 'toggle-col-vis-cus-modal-visibility',
96
+ // Show all columns
97
+ ShowAllColumns = 'show-all-columns',
98
+ // Hide all columns
99
+ HideAllColumns = 'hide-all-columns',
95
100
  }
96
101
 
97
102
  // Action definitions
@@ -114,6 +119,8 @@ type Action = (
114
119
  // Action type
115
120
  type: (
116
121
  | ActionType.ToggleColVisCusModalVisibility
122
+ | ActionType.ShowAllColumns
123
+ | ActionType.HideAllColumns
117
124
  ),
118
125
  }
119
126
  );
@@ -163,6 +170,26 @@ const reducer = (state: State, action: Action): State => {
163
170
  columnVisibilityCustomizationModalVisible: !state.columnVisibilityCustomizationModalVisible,
164
171
  };
165
172
  }
173
+ case ActionType.ShowAllColumns: {
174
+ const { columnVisibilityMap } = state;
175
+ Object.keys(columnVisibilityMap).forEach((param) => {
176
+ columnVisibilityMap[param] = true;
177
+ });
178
+ return {
179
+ ...state,
180
+ columnVisibilityMap,
181
+ };
182
+ }
183
+ case ActionType.HideAllColumns: {
184
+ const { columnVisibilityMap } = state;
185
+ Object.keys(columnVisibilityMap).forEach((param) => {
186
+ columnVisibilityMap[param] = false;
187
+ });
188
+ return {
189
+ ...state,
190
+ columnVisibilityMap,
191
+ };
192
+ }
166
193
  default: {
167
194
  return state;
168
195
  }
@@ -251,12 +278,25 @@ const IntelliTable: React.FC<Props> = (props) => {
251
278
  type={ModalType.Okay}
252
279
  title="Choose columns to show:"
253
280
  onClose={() => {
281
+ const noColumnsSelected = (
282
+ Object.values(columnVisibilityMap)
283
+ .every((isSelected) => {
284
+ return !isSelected;
285
+ })
286
+ );
287
+ if (noColumnsSelected) {
288
+ return alert(
289
+ 'Choose at least one column',
290
+ 'To continue, you have to choose at least one column to show'
291
+ );
292
+ }
254
293
  dispatch({
255
294
  type: ActionType.ToggleColVisCusModalVisibility,
256
295
  });
257
296
  }}
258
297
  okayVariant={Variant.Light}
259
298
  >
299
+ {/* Columns */}
260
300
  {
261
301
  columns.map((column) => {
262
302
  return (
@@ -273,13 +313,42 @@ const IntelliTable: React.FC<Props> = (props) => {
273
313
  });
274
314
  }}
275
315
  checked={columnVisibilityMap[column.param]}
276
- ariaLabel={`show "${column.title}" column`}
316
+ ariaLabel={`show "${column.title}" column in the ${title} table`}
277
317
  checkedVariant={Variant.Light}
278
318
  uncheckedVariant={Variant.Secondary}
279
319
  />
280
320
  );
281
321
  })
282
322
  }
323
+ <div className="mt-3">
324
+ Or you can:
325
+ </div>
326
+ <button
327
+ type="button"
328
+ id={`IntelliTable-${id}-select-all-columns`}
329
+ className="btn btn-secondary me-2"
330
+ aria-label={`show all columns in the ${title} table`}
331
+ onClick={() => {
332
+ dispatch({
333
+ type: ActionType.ShowAllColumns,
334
+ });
335
+ }}
336
+ >
337
+ Select All
338
+ </button>
339
+ <button
340
+ type="button"
341
+ id={`IntelliTable-${id}-select-none-columns`}
342
+ className="btn btn-secondary"
343
+ aria-label={`hide all columns in the ${title} table`}
344
+ onClick={() => {
345
+ dispatch({
346
+ type: ActionType.HideAllColumns,
347
+ });
348
+ }}
349
+ >
350
+ Deselect All
351
+ </button >
283
352
  </Modal>
284
353
  );
285
354
  }
@@ -625,7 +694,9 @@ const IntelliTable: React.FC<Props> = (props) => {
625
694
  // Build CSV
626
695
  const csv = genCSV(
627
696
  data,
628
- columns,
697
+ columns.filter((column) => {
698
+ return columnVisibilityMap[column.param];
699
+ }),
629
700
  );
630
701
 
631
702
  // Build main UI