@imposium-hub/components 2.4.0-0 → 2.4.0-1

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.
Files changed (32) hide show
  1. package/dist/cjs/components/app-wrapper/AppWrapper.js +43 -23
  2. package/dist/cjs/components/app-wrapper/AppWrapper.js.map +1 -1
  3. package/dist/cjs/components/auth-gate/AuthGate.js +3 -2
  4. package/dist/cjs/components/auth-gate/AuthGate.js.map +1 -1
  5. package/dist/cjs/components/header/Header.d.ts +1 -1
  6. package/dist/cjs/components/header/Header.js +26 -28
  7. package/dist/cjs/components/header/Header.js.map +1 -1
  8. package/dist/cjs/index.d.ts +2 -2
  9. package/dist/cjs/index.js +3 -2
  10. package/dist/cjs/index.js.map +1 -1
  11. package/dist/cjs/services/Session.d.ts +6 -6
  12. package/dist/cjs/services/Session.js +14 -14
  13. package/dist/cjs/services/Session.js.map +1 -1
  14. package/dist/esm/components/app-wrapper/AppWrapper.js +43 -23
  15. package/dist/esm/components/app-wrapper/AppWrapper.js.map +1 -1
  16. package/dist/esm/components/auth-gate/AuthGate.js +3 -2
  17. package/dist/esm/components/auth-gate/AuthGate.js.map +1 -1
  18. package/dist/esm/components/header/Header.d.ts +1 -1
  19. package/dist/esm/components/header/Header.js +26 -23
  20. package/dist/esm/components/header/Header.js.map +1 -1
  21. package/dist/esm/index.d.ts +2 -2
  22. package/dist/esm/index.js +2 -2
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/esm/services/Session.d.ts +6 -6
  25. package/dist/esm/services/Session.js +14 -14
  26. package/dist/esm/services/Session.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/components/app-wrapper/AppWrapper.tsx +39 -21
  29. package/src/components/auth-gate/AuthGate.tsx +3 -2
  30. package/src/components/header/Header.tsx +43 -40
  31. package/src/index.ts +8 -1
  32. package/src/services/Session.ts +14 -14
@@ -164,7 +164,7 @@ class AppWrapper extends React.Component<IAppWrapperProps, IAppWrapperState> {
164
164
  );
165
165
  if (org) {
166
166
  initialOrganizationId = org.id;
167
- } else {
167
+ } else if (firstOrg) {
168
168
  initialOrganizationId = firstOrg.id;
169
169
  }
170
170
  }
@@ -177,34 +177,52 @@ class AppWrapper extends React.Component<IAppWrapperProps, IAppWrapperState> {
177
177
  initialStoryId = sessionIds.storyId;
178
178
  } else {
179
179
  // If that doesn't work - default to the first org & story
180
- const story = firstOrg.stories[0];
181
- initialOrganizationId = firstOrg.id;
182
- initialStoryId = story.id;
180
+ if (firstOrg) {
181
+ initialOrganizationId = firstOrg.id;
182
+ const story = firstOrg.stories[0];
183
+ if (story) {
184
+ initialStoryId = story.id;
185
+ } else {
186
+ initialStoryId = null;
187
+ }
188
+ } else {
189
+ initialOrganizationId = null;
190
+ initialStoryId = null;
191
+ }
183
192
  }
184
193
  }
185
194
 
186
- SessionService.buildFreshSession(freshIdentity, initialOrganizationId, initialStoryId);
187
- onAuthenticated(initialOrganizationId, initialStoryId);
195
+ // If at least one org was found, propagate that
196
+ if (initialOrganizationId) {
197
+ SessionService.buildFreshSession(freshIdentity, initialOrganizationId, initialStoryId);
198
+ onAuthenticated(initialOrganizationId, initialStoryId);
199
+
200
+ if (this.state.blockRender) {
201
+ this.setState({ blockRender: false });
202
+ }
188
203
 
189
- if (this.state.blockRender) {
190
- this.setState({ blockRender: false });
204
+ // If not, show the no-orgs interface
205
+ } else {
206
+ this.setState({ restrictAccess: true, blockRender: false });
191
207
  }
192
208
  };
193
209
 
194
210
  /*
195
211
  Bust cached creds if exist, invoke auth failure handler
196
212
  */
197
- private handleCheckSessionFailure = (e: Error): void => {
198
- if (this.props.storyId) {
199
- SessionService.cacheStoryId(this.props.storyId);
200
- } else {
201
- SessionService.clearCachedStoryId();
202
- }
213
+ private handleCheckSessionFailure = (e: Error, sub?: string): void => {
214
+ if (sub) {
215
+ if (this.props.storyId) {
216
+ SessionService.cacheStoryId(this.props.storyId, sub);
217
+ } else {
218
+ SessionService.clearCachedStoryId(sub);
219
+ }
203
220
 
204
- if (this.props.organizationId) {
205
- SessionService.cacheOrgId(this.props.organizationId);
206
- } else {
207
- SessionService.clearCachedOrgId();
221
+ if (this.props.organizationId) {
222
+ SessionService.cacheOrgId(this.props.organizationId, sub);
223
+ } else {
224
+ SessionService.clearCachedOrgId(sub);
225
+ }
208
226
  }
209
227
 
210
228
  this.props.clearCachedAuth();
@@ -222,9 +240,10 @@ class AppWrapper extends React.Component<IAppWrapperProps, IAppWrapperState> {
222
240
  }
223
241
  AuthService.checkSession()
224
242
  .then((freshIdentity: IIdentity) => {
243
+ const sub = freshIdentity.idTokenPayload.sub;
225
244
  const orgId = this.props.organizationId
226
245
  ? this.props.organizationId
227
- : SessionService.getCachedOrgId();
246
+ : SessionService.getCachedOrgId(sub);
228
247
  SessionService.getAccessData(freshIdentity.accessToken, baseUrl, false, orgId)
229
248
  .then((freshAccess: any) => {
230
249
  this.props.setAccessData(freshAccess);
@@ -233,11 +252,10 @@ class AppWrapper extends React.Component<IAppWrapperProps, IAppWrapperState> {
233
252
  })
234
253
  .catch((e: Error) => {
235
254
  console.error(e);
236
- this.handleCheckSessionFailure(e);
255
+ this.handleCheckSessionFailure(e, sub);
237
256
  });
238
257
  })
239
258
  .catch((e: Error) => {
240
- console.error(e);
241
259
  this.handleCheckSessionFailure(e);
242
260
  });
243
261
  };
@@ -36,9 +36,10 @@ class AuthGate extends React.PureComponent<IAuthGateProps> {
36
36
  } else {
37
37
  AuthService.parseIdFromHash(auth0Hash)
38
38
  .then((freshIdentity: IIdentity) => {
39
+ const sub = freshIdentity.idTokenPayload.sub;
39
40
  // Use the cached org ID and story ID if it exists
40
- const orgId = SessionService.getCachedOrgId() || null;
41
- const storyId = SessionService.getCachedStoryId() || null;
41
+ const orgId = SessionService.getCachedOrgId(sub) || null;
42
+ const storyId = SessionService.getCachedStoryId(sub) || null;
42
43
 
43
44
  SessionService.getAccessData(freshIdentity.accessToken, baseUrl, false, orgId)
44
45
  .then((freshAccess: any) => {
@@ -9,6 +9,8 @@ import _ from 'lodash';
9
9
  import DataTable from '../data-table/DataTable';
10
10
  import AssetsTableDateCell from '../assets/AssetsTableDateCell';
11
11
  import SessionService, { IHubSession } from '../../services/Session';
12
+ import { setAccessData } from '../../redux/actions/access';
13
+ import { bindActionCreators } from 'redux';
12
14
 
13
15
  export interface IHeaderProps {
14
16
  email?: string;
@@ -16,6 +18,7 @@ export interface IHeaderProps {
16
18
  activeStory?: string;
17
19
  hideStoryPicker?: boolean;
18
20
  hideOrgPicker?: boolean;
21
+ setAccessData(access: any): void;
19
22
  onOrganizationChange?: (orgId: any) => any;
20
23
  onStoryChange?: (story: any) => any;
21
24
  logout: (...args) => any;
@@ -40,7 +43,6 @@ export interface IHeaderState {
40
43
  activeFirstChar: string;
41
44
  order: string;
42
45
  orderDirection: string;
43
- accessData: any;
44
46
  dataLoading: boolean;
45
47
  }
46
48
 
@@ -150,8 +152,7 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
150
152
  activeFirstChar: '',
151
153
  order: 'date_modified',
152
154
  orderDirection: 'desc',
153
- accessData: null,
154
- dataLoading: true
155
+ dataLoading: false
155
156
  };
156
157
 
157
158
  this.serviceToggleRef = React.createRef();
@@ -160,26 +161,19 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
160
161
  }
161
162
 
162
163
  public componentDidMount = (): void => {
163
- this.getAccessDataHandler();
164
+ if (this.props.access && this.props.activeOrganization) {
165
+ this.parseAccessData(this.props.access, this.props.activeOrganization);
166
+ }
164
167
  };
165
168
 
166
169
  public componentDidUpdate(prevProps: Readonly<IHeaderProps>): void {
167
- const { accessData } = this.state;
168
170
  const { activeOrganization, access } = this.props;
169
171
 
170
- if (activeOrganization !== prevProps.activeOrganization) {
171
- if (accessData !== null) {
172
- this.parseAccessData(accessData, activeOrganization);
173
- } else {
174
- this.getAccessDataHandler();
172
+ if (activeOrganization !== prevProps.activeOrganization || access !== prevProps.access) {
173
+ if (access !== null) {
174
+ this.parseAccessData(access, activeOrganization);
175
175
  }
176
176
  }
177
-
178
- if (!_.isEqual(access, accessData)) {
179
- this.setState({ accessData: access }, () =>
180
- this.parseAccessData(access, activeOrganization)
181
- );
182
- }
183
177
  }
184
178
 
185
179
  private parseAccessData = (accessData: any, activeOrganization: string): void => {
@@ -310,13 +304,12 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
310
304
 
311
305
  this.setState({ dataLoading: true });
312
306
 
313
- SessionService.getAccessData(accessToken, baseUrl)
307
+ SessionService.getAccessData(accessToken, baseUrl, false, activeOrganization)
314
308
  .then((res) => {
315
- this.setState({ dataLoading: false, accessData: res }, () =>
316
- this.parseAccessData(res, activeOrganization)
317
- );
309
+ this.setState({ dataLoading: false });
310
+ this.props.setAccessData(res);
318
311
  })
319
- .catch((e: Error) => {
312
+ .catch((e) => {
320
313
  console.error(e);
321
314
  });
322
315
  };
@@ -331,10 +324,10 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
331
324
  hideOrgPicker,
332
325
  additionalButtons,
333
326
  showFTLogo,
334
- hideDocs
327
+ hideDocs,
328
+ access
335
329
  } = this.props;
336
330
  const {
337
- accessData,
338
331
  showAccountDropdown,
339
332
  servicesByOrganization,
340
333
  activeServiceBlob,
@@ -373,7 +366,7 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
373
366
  </button>
374
367
  );
375
368
 
376
- if (accessData) {
369
+ if (access) {
377
370
  activeService = servicesByOrganization.find((s: any) =>
378
371
  window.location.href.includes(s.url)
379
372
  );
@@ -463,21 +456,22 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
463
456
  </button>
464
457
  );
465
458
 
466
- accountDropdownToggle = !hideOrgPicker ? (
467
- <button
468
- id='btn-toggle-orgs'
469
- className='btn-toggle-orgs'
470
- ref={this.orgsToggleRef}
471
- style={{ backgroundColor: dropdownToggleColor }}
472
- onClick={() => this.toggleAccountDropdown(!showAccountDropdown)}>
473
- {activeFirstChar}
474
- </button>
475
- ) : (
476
- btnLogout
477
- );
459
+ accountDropdownToggle =
460
+ !hideOrgPicker && access.organizations.length > 0 ? (
461
+ <button
462
+ id='btn-toggle-orgs'
463
+ className='btn-toggle-orgs'
464
+ ref={this.orgsToggleRef}
465
+ style={{ backgroundColor: dropdownToggleColor }}
466
+ onClick={() => this.toggleAccountDropdown(!showAccountDropdown)}>
467
+ {activeFirstChar}
468
+ </button>
469
+ ) : (
470
+ btnLogout
471
+ );
478
472
  }
479
473
 
480
- if (accessData && activeOrganizationBlob) {
474
+ if (access && activeOrganizationBlob) {
481
475
  activePanel = (
482
476
  <div className='orgs-menu-active-org'>
483
477
  <div
@@ -491,11 +485,11 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
491
485
  );
492
486
  }
493
487
 
494
- if (accessData && accessData.organizations && accessData.organizations.length === 0) {
488
+ if (access && access.organizations && access.organizations.length === 0) {
495
489
  storyToggle = null;
496
490
  }
497
491
 
498
- if (accessData && activeOrganizationBlob && !hideStoryPicker) {
492
+ if (access && activeOrganizationBlob && !hideStoryPicker) {
499
493
  currentStory = activeOrganizationBlob.stories.find((s: any) => s.id === activeStory);
500
494
  storyToggle = (
501
495
  <button
@@ -641,6 +635,15 @@ class ImposiumHeader extends React.PureComponent<IHeaderProps, IHeaderState> {
641
635
  }
642
636
  }
643
637
 
638
+ const mapDispatchToProps = (dispatch) => {
639
+ return bindActionCreators(
640
+ {
641
+ setAccessData
642
+ },
643
+ dispatch
644
+ );
645
+ };
646
+
644
647
  const mapStateToProps = (state): any => {
645
648
  return {
646
649
  auth: state.auth,
@@ -649,4 +652,4 @@ const mapStateToProps = (state): any => {
649
652
  };
650
653
  };
651
654
 
652
- export default connect(mapStateToProps, null)(ImposiumHeader);
655
+ export default connect(mapStateToProps, mapDispatchToProps)(ImposiumHeader);
package/src/index.ts CHANGED
@@ -80,7 +80,13 @@ import {
80
80
  clearStoryPublishStatus,
81
81
  getStoryPublishStatus
82
82
  } from './redux/actions/publish';
83
- import { storyAdded, storyNameMutated, orgNameMutated, storyDeleted } from './redux/actions/access';
83
+ import {
84
+ storyAdded,
85
+ storyNameMutated,
86
+ orgNameMutated,
87
+ storyDeleted,
88
+ setAccessData
89
+ } from './redux/actions/access';
84
90
  import { resetFilters, updateFilters } from './redux/actions/asset-filters';
85
91
  import {
86
92
  getAssets,
@@ -228,6 +234,7 @@ export {
228
234
  login,
229
235
  clearCachedAuth,
230
236
  access,
237
+ setAccessData,
231
238
  storyAdded,
232
239
  storyNameMutated,
233
240
  orgNameMutated,
@@ -9,9 +9,9 @@ export interface IHubSession {
9
9
  }
10
10
 
11
11
  export default class SessionService {
12
- private static readonly LOGIN_STORY_ID_CACHE: string = 'imp_hub_last_story_id';
12
+ private static readonly LOGIN_STORY_ID_CACHE: string = 'imp_hub_last_story_id-';
13
13
 
14
- private static readonly LOGIN_ORG_ID_CACHE: string = 'imp_hub_last_org_id';
14
+ private static readonly LOGIN_ORG_ID_CACHE: string = 'imp_hub_last_org_id-';
15
15
 
16
16
  private static readonly SESSION_COOKIE_NAME: string = 'auth_state';
17
17
 
@@ -93,28 +93,28 @@ export default class SessionService {
93
93
  Cookies.set(SessionService.SESSION_COOKIE_NAME, cookieData, { domain, expires: expiry });
94
94
  };
95
95
 
96
- public static cacheOrgId = (organizationId: string): void => {
97
- localStorage.setItem(SessionService.LOGIN_ORG_ID_CACHE, organizationId);
96
+ public static cacheOrgId = (organizationId: string, sub): void => {
97
+ localStorage.setItem(SessionService.LOGIN_ORG_ID_CACHE + sub, organizationId);
98
98
  };
99
99
 
100
- public static clearCachedOrgId = () => {
101
- localStorage.removeItem(SessionService.LOGIN_ORG_ID_CACHE);
100
+ public static clearCachedOrgId = (sub) => {
101
+ localStorage.removeItem(SessionService.LOGIN_ORG_ID_CACHE + sub);
102
102
  };
103
103
 
104
- public static getCachedOrgId = (): string => {
105
- return localStorage.getItem(SessionService.LOGIN_ORG_ID_CACHE);
104
+ public static getCachedOrgId = (sub): string => {
105
+ return localStorage.getItem(SessionService.LOGIN_ORG_ID_CACHE + sub);
106
106
  };
107
107
 
108
- public static cacheStoryId = (storyId: string): void => {
109
- localStorage.setItem(SessionService.LOGIN_STORY_ID_CACHE, storyId);
108
+ public static cacheStoryId = (storyId: string, sub): void => {
109
+ localStorage.setItem(SessionService.LOGIN_STORY_ID_CACHE + sub, storyId);
110
110
  };
111
111
 
112
- public static clearCachedStoryId = (): void => {
113
- localStorage.removeItem(SessionService.LOGIN_STORY_ID_CACHE);
112
+ public static clearCachedStoryId = (sub): void => {
113
+ localStorage.removeItem(SessionService.LOGIN_STORY_ID_CACHE + sub);
114
114
  };
115
115
 
116
- public static getCachedStoryId = (): string => {
117
- return localStorage.getItem(SessionService.LOGIN_STORY_ID_CACHE);
116
+ public static getCachedStoryId = (sub): string => {
117
+ return localStorage.getItem(SessionService.LOGIN_STORY_ID_CACHE + sub);
118
118
  };
119
119
 
120
120
  public static updateSession = (values: any, auth0Expiry: number): void => {