@zeniai/client-epic-state 5.3.18-betaAK2 → 5.3.19

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.
@@ -54,6 +54,11 @@ const fetchAllTenantsEpic = (actions$, state, zeniAPI) => {
54
54
  // Screens that wait for this fetch (sign-in, the root route) read the
55
55
  // landing tenant's roles and product settings, which the list does
56
56
  // not carry, so it completes only once that tenant's record is in.
57
+ // The wait is deliberately not scoped to the landing tenant:
58
+ // fetchActiveTenantEpic switches to the latest request, so another
59
+ // tenant's fetch dispatched meanwhile cancels this one and its answer
60
+ // is the only one that will come. Either way a full current tenant is
61
+ // in once any active-tenant fetch settles.
57
62
  return (0, rxjs_1.merge)(actions$.pipe((0, operators_1.filter)((landingAction) => tenantReducer_1.updateTenantSuccess.match(landingAction) ||
58
63
  tenantReducer_1.updateTenantFailure.match(landingAction)), (0, operators_1.take)(1), (0, operators_1.map)(() => tenantsLoaded)), (0, rxjs_1.of)((0, tenantReducer_1.fetchActiveTenant)(userId, landingTenantId, zeniSessionId)));
59
64
  }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, tenantReducer_1.updateTenantsFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected error', 'Fetch All Tenants REST API call errored out' +
@@ -29,29 +29,29 @@ function getTenantIdByCompanyId(tenantState, companyId) {
29
29
  return (Object.values(tenantState.tenantsById).find((tenant) => tenant.companyId === companyId) ??
30
30
  Object.values(tenantState.tenantSummariesById).find((tenantSummary) => tenantSummary.companyId === companyId))?.tenantId;
31
31
  }
32
+ /** One tenant's entry: its full record when loaded, else its list entry. */
33
+ function getTenantListEntry(tenantState, tenantId) {
34
+ const tenant = tenantState.tenantsById[tenantId];
35
+ if (tenant != null) {
36
+ return {
37
+ companyId: tenant.companyId,
38
+ companyName: tenant.companyName,
39
+ tenantEmailDomain: tenant.tenantEmailDomain,
40
+ tenantId: tenant.tenantId,
41
+ userLastCheckInTime: tenant.userLastCheckInTime,
42
+ userRole: tenant.userRole,
43
+ };
44
+ }
45
+ const tenantSummary = tenantState.tenantSummariesById[tenantId];
46
+ return tenantSummary != null ? { ...tenantSummary, userRole: [] } : undefined;
47
+ }
32
48
  /**
33
49
  * Every tenant in the list, most recently opened first. Roles are known only
34
50
  * for tenants whose full record is loaded; the list itself carries none.
35
51
  */
36
52
  function getTenantListEntriesByCheckInDate(tenantState) {
37
53
  const entries = tenantState.tenantIds
38
- .map((tenantId) => {
39
- const tenant = tenantState.tenantsById[tenantId];
40
- const tenantSummary = tenantState.tenantSummariesById[tenantId];
41
- if (tenant != null) {
42
- return {
43
- companyId: tenant.companyId,
44
- companyName: tenant.companyName,
45
- tenantEmailDomain: tenant.tenantEmailDomain,
46
- tenantId: tenant.tenantId,
47
- userLastCheckInTime: tenant.userLastCheckInTime,
48
- userRole: tenant.userRole,
49
- };
50
- }
51
- return tenantSummary != null
52
- ? { ...tenantSummary, userRole: [] }
53
- : undefined;
54
- })
54
+ .map((tenantId) => getTenantListEntry(tenantState, tenantId))
55
55
  .filter((entry) => entry != null);
56
56
  return (0, orderBy_1.default)(entries, (entry) => entry.userLastCheckInTime.valueOf(), 'desc');
57
57
  }
@@ -89,7 +89,7 @@ const isCurrentTenantLoaded = (state) => {
89
89
  };
90
90
  exports.isCurrentTenantLoaded = isCurrentTenantLoaded;
91
91
  exports.getTenantBaseViewForTenantId = (0, toolkit_1.createSelector)((state) => state.tenantState, (state) => state.companyState, (_state, tenantId) => tenantId, (tenantState, companyState, tenantId) => {
92
- const entry = getTenantListEntriesByCheckInDate(tenantState).find((listEntry) => listEntry.tenantId === tenantId);
92
+ const entry = getTenantListEntry(tenantState, tenantId);
93
93
  return entry != null
94
94
  ? getTenantBaseViewForEntry(entry, companyState)
95
95
  : undefined;
@@ -1,7 +1,7 @@
1
1
  import { defer, from, merge, of } from 'rxjs';
2
2
  import { catchError, filter, map, mergeMap, switchMap, take, } from 'rxjs/operators';
3
3
  import { toMonth } from '../../../commonStateTypes/timePeriod';
4
- import { createZeniAPIStatus, isSuccessResponse, } from '../../../responsePayload';
4
+ import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
5
5
  import { getSessionEndpointsLoader } from '../../../sessionEndpointsLoader';
6
6
  import { date, dateNow } from '../../../zeniDayJS';
7
7
  import { fetchActiveTenant, fetchAllTenants, updateTenantFailure, updateTenantSuccess, updateTenantSummariesSuccess, updateTenantsFailure, } from '../tenantReducer';
@@ -51,6 +51,11 @@ export const fetchAllTenantsEpic = (actions$, state, zeniAPI) => {
51
51
  // Screens that wait for this fetch (sign-in, the root route) read the
52
52
  // landing tenant's roles and product settings, which the list does
53
53
  // not carry, so it completes only once that tenant's record is in.
54
+ // The wait is deliberately not scoped to the landing tenant:
55
+ // fetchActiveTenantEpic switches to the latest request, so another
56
+ // tenant's fetch dispatched meanwhile cancels this one and its answer
57
+ // is the only one that will come. Either way a full current tenant is
58
+ // in once any active-tenant fetch settles.
54
59
  return merge(actions$.pipe(filter((landingAction) => updateTenantSuccess.match(landingAction) ||
55
60
  updateTenantFailure.match(landingAction)), take(1), map(() => tenantsLoaded)), of(fetchActiveTenant(userId, landingTenantId, zeniSessionId)));
56
61
  }), catchError((error) => of(updateTenantsFailure(createZeniAPIStatus('Unexpected error', 'Fetch All Tenants REST API call errored out' +
@@ -19,29 +19,29 @@ export function getTenantIdByCompanyId(tenantState, companyId) {
19
19
  return (Object.values(tenantState.tenantsById).find((tenant) => tenant.companyId === companyId) ??
20
20
  Object.values(tenantState.tenantSummariesById).find((tenantSummary) => tenantSummary.companyId === companyId))?.tenantId;
21
21
  }
22
+ /** One tenant's entry: its full record when loaded, else its list entry. */
23
+ function getTenantListEntry(tenantState, tenantId) {
24
+ const tenant = tenantState.tenantsById[tenantId];
25
+ if (tenant != null) {
26
+ return {
27
+ companyId: tenant.companyId,
28
+ companyName: tenant.companyName,
29
+ tenantEmailDomain: tenant.tenantEmailDomain,
30
+ tenantId: tenant.tenantId,
31
+ userLastCheckInTime: tenant.userLastCheckInTime,
32
+ userRole: tenant.userRole,
33
+ };
34
+ }
35
+ const tenantSummary = tenantState.tenantSummariesById[tenantId];
36
+ return tenantSummary != null ? { ...tenantSummary, userRole: [] } : undefined;
37
+ }
22
38
  /**
23
39
  * Every tenant in the list, most recently opened first. Roles are known only
24
40
  * for tenants whose full record is loaded; the list itself carries none.
25
41
  */
26
42
  function getTenantListEntriesByCheckInDate(tenantState) {
27
43
  const entries = tenantState.tenantIds
28
- .map((tenantId) => {
29
- const tenant = tenantState.tenantsById[tenantId];
30
- const tenantSummary = tenantState.tenantSummariesById[tenantId];
31
- if (tenant != null) {
32
- return {
33
- companyId: tenant.companyId,
34
- companyName: tenant.companyName,
35
- tenantEmailDomain: tenant.tenantEmailDomain,
36
- tenantId: tenant.tenantId,
37
- userLastCheckInTime: tenant.userLastCheckInTime,
38
- userRole: tenant.userRole,
39
- };
40
- }
41
- return tenantSummary != null
42
- ? { ...tenantSummary, userRole: [] }
43
- : undefined;
44
- })
44
+ .map((tenantId) => getTenantListEntry(tenantState, tenantId))
45
45
  .filter((entry) => entry != null);
46
46
  return orderBy(entries, (entry) => entry.userLastCheckInTime.valueOf(), 'desc');
47
47
  }
@@ -77,7 +77,7 @@ export const isCurrentTenantLoaded = (state) => {
77
77
  return currentTenantId != null && isTenantLoaded(state, currentTenantId);
78
78
  };
79
79
  export const getTenantBaseViewForTenantId = createSelector((state) => state.tenantState, (state) => state.companyState, (_state, tenantId) => tenantId, (tenantState, companyState, tenantId) => {
80
- const entry = getTenantListEntriesByCheckInDate(tenantState).find((listEntry) => listEntry.tenantId === tenantId);
80
+ const entry = getTenantListEntry(tenantState, tenantId);
81
81
  return entry != null
82
82
  ? getTenantBaseViewForEntry(entry, companyState)
83
83
  : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.3.18-betaAK2",
3
+ "version": "5.3.19",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",