dce-reactkit 5.0.8 → 5.0.10

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.
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  abbreviate,
16
16
  avg,
17
17
  ceilToNumDecimals,
18
+ convertDateKeyToDateInfo,
18
19
  floorToNumDecimals,
19
20
  forceNumIntoBounds,
20
21
  padDecimalZeros,
@@ -121,6 +122,7 @@ import isMobileOrTablet from './helpers/isMobileOrTablet';
121
122
  import makeLinksClickable from './helpers/makeLinksClickable';
122
123
  import combineClassNames from './helpers/combineClassNames';
123
124
  import useForceRender from './helpers/useForceRender';
125
+ import useBackButton, { backButtonController } from './helpers/useBackButton';
124
126
  import isSelectAdmin from './helpers/isSelectAdmin';
125
127
 
126
128
  // Import types
@@ -131,6 +133,8 @@ import Variant from './types/Variant';
131
133
  import IntelliTableColumn from './types/IntelliTableColumn';
132
134
  import DropdownItemType from './types/DropdownItemType';
133
135
  import ProgressBarSize from './types/ProgressBarSize';
136
+ import BackState from './types/BackState';
137
+ import BackButtonController from './types/BackButtonController';
134
138
 
135
139
  // Component-specific-types
136
140
  import PickableItem from './components/ItemPicker/types/PickableItem';
@@ -190,6 +194,8 @@ export {
190
194
  leaveToURL,
191
195
  combineClassNames,
192
196
  useForceRender,
197
+ useBackButton,
198
+ backButtonController,
193
199
  setClientEventMetadataPopulator,
194
200
  // Types
195
201
  ModalButtonType,
@@ -200,6 +206,8 @@ export {
200
206
  DropdownItemType,
201
207
  LogReviewerFilterState,
202
208
  ProgressBarSize,
209
+ BackState,
210
+ BackButtonController,
203
211
  // Component-specific-types
204
212
  PickableItem,
205
213
  DBEntry,
@@ -221,6 +229,7 @@ export {
221
229
  abbreviate,
222
230
  avg,
223
231
  ceilToNumDecimals,
232
+ convertDateKeyToDateInfo,
224
233
  floorToNumDecimals,
225
234
  forceNumIntoBounds,
226
235
  padDecimalZeros,
@@ -0,0 +1,43 @@
1
+ // Import types
2
+ import BackState from './BackState';
3
+
4
+ /**
5
+ * Controller for the back button, used to drive back navigation from anywhere
6
+ * in the app. Pass this to subpanels so they can describe their state and
7
+ * send the user home.
8
+ * @author Yuen Ler Chow
9
+ */
10
+ type BackButtonController = {
11
+ /**
12
+ * Call this when the user navigates to a child of the home screen (something
13
+ * they can come back from)
14
+ */
15
+ onSubpanelEntered: () => void,
16
+ /**
17
+ * Send the user back to the home screen
18
+ * @param [force] if true, go home immediately without checking the subpanel
19
+ * state (no confirmation, not blocked). If falsy, nothing happens when
20
+ * blocked and confirmation is required when there are unsaved changes
21
+ */
22
+ goHome: (force?: boolean) => Promise<void>,
23
+ /**
24
+ * Set the state of the current subpanel, which determines what happens when
25
+ * the user tries to go back
26
+ * @param newSubpanelState the new state of the subpanel
27
+ */
28
+ setSubpanelState: (newSubpanelState: BackState) => void,
29
+ /**
30
+ * Set the confirmation message shown if the user tries to go back while there
31
+ * are unsaved changes (cleared upon returning to the home screen)
32
+ * @param message the message to show
33
+ */
34
+ setCustomUnsavedChangesMessage: (message: string) => void,
35
+ /**
36
+ * Set the message shown if the user tries to go back while blocked (cleared
37
+ * upon returning to the home screen)
38
+ * @param message the message to show
39
+ */
40
+ setCustomBlockedMessage: (message: string) => void,
41
+ };
42
+
43
+ export default BackButtonController;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * State of the current subpanel, determining what happens when the user tries
3
+ * to go back to the home screen
4
+ * @author Yuen Ler Chow
5
+ */
6
+ enum BackState {
7
+ // The user can go back immediately, no confirmation required
8
+ Normal = 'Normal',
9
+ // The user must confirm before going back because progress will be lost
10
+ UnsavedChanges = 'UnsavedChanges',
11
+ // The user cannot go back right now because work is in progress
12
+ Blocked = 'Blocked',
13
+ }
14
+
15
+ export default BackState;