Skip to content

Commit 01a296a

Browse files
committed
Add products.ts, getPrimaryAppProductId, update imports
1 parent 628a5c9 commit 01a296a

19 files changed

+99
-73
lines changed

packages/components/src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
createProductUrlFromPartsWithContainer,
2525
spliceURL,
2626
} from './internal/url/AppURL';
27+
import { AppLink } from './internal/url/AppLink';
2728
import { getHref } from './internal/url/utils';
2829
import { hasParameter, imageURL, toggleParameter } from './internal/url/ActionURL';
2930
import { Container } from './internal/components/base/models/Container';
@@ -711,7 +712,13 @@ import { BarTenderSettingsForm } from './internal/components/labelPrinting/BarTe
711712
import { ColumnSelectionModal } from './internal/components/ColumnSelectionModal';
712713

713714
import { AppReducers, ProductMenuReducers, ServerNotificationReducers } from './internal/app/reducers';
714-
715+
import {
716+
isBiologicsEnabled,
717+
isFreezerManagementEnabled,
718+
isLIMSEnabled,
719+
isPremiumProductEnabled,
720+
isSampleManagerEnabled,
721+
} from './internal/app/products';
715722
import {
716723
biologicsIsPrimaryApp,
717724
CloseEventCode,
@@ -739,25 +746,21 @@ import {
739746
isAssayFileUploadEnabled,
740747
isAssayQCEnabled,
741748
isAssayRequestsEnabled,
742-
isBiologicsEnabled,
743749
isConditionalFormattingEnabled,
744750
isCustomImportTemplatesEnabled,
745751
isDataChangeCommentRequirementFeatureEnabled,
746752
isELNEnabled,
747753
isExperimentAliasEnabled,
748-
isFreezerManagementEnabled,
749754
isLKSSupportEnabled,
750755
isMediaEnabled,
751756
isNonstandardAssayEnabled,
752757
isNotebookTagsEnabled,
753758
isPlatesEnabled,
754-
isPremiumProductEnabled,
755759
isProductFoldersEnabled,
756760
isProjectContainer,
757761
isProtectedDataEnabled,
758762
isRegistryEnabled,
759763
isSampleAliquotSelectorEnabled,
760-
isSampleManagerEnabled,
761764
isSampleStatusEnabled,
762765
isSharedContainer,
763766
isSourceTypeEnabled,
@@ -968,6 +971,7 @@ const App = {
968971
isPlatesEnabled,
969972
isSampleManagerEnabled,
970973
isBiologicsEnabled,
974+
isLIMSEnabled,
971975
isPremiumProductEnabled,
972976
isSampleAliquotSelectorEnabled,
973977
isProjectContainer,
@@ -1225,6 +1229,7 @@ export {
12251229
buildURL,
12261230
imageURL,
12271231
spliceURL,
1232+
AppLink,
12281233
WHERE_FILTER_TYPE,
12291234
NOT_ANY_FILTER_TYPE,
12301235
createProductUrl,

packages/components/src/internal/app/constants.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ import { SAMPLE_MANAGER_SEARCH_PLACEHOLDER, SEARCH_PLACEHOLDER } from '../compon
1111
import { GENERAL_ASSAY_PROVIDER_NAME } from '../components/assay/constants';
1212

1313
import { AppProperties } from './models';
14-
15-
// These ids should match what is used by the MenuProviders in the Java code, so we can avoid toLowerCase comparisons.
16-
export const LKS_PRODUCT_ID = 'LabKeyServer';
17-
const BIOLOGICS_PRODUCT_ID = 'Biologics';
18-
const LIMS_PRODUCT_ID = 'LIMS';
19-
const SAMPLE_MANAGER_PRODUCT_ID = 'SampleManager';
20-
const FREEZER_MANAGER_PRODUCT_ID = 'FreezerManager';
14+
import {
15+
BIOLOGICS_PRODUCT_ID,
16+
FREEZER_MANAGER_PRODUCT_ID,
17+
LIMS_PRODUCT_ID,
18+
SAMPLE_MANAGER_PRODUCT_ID,
19+
} from './products';
2120

2221
const SAMPLE_MANAGER_PRODUCT_NAME = 'Sample Manager';
2322
const BIOLOGICS_PRODUCT_NAME = 'Biologics';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Note: This whole file was created so we could avoid circular dependencies with AppURL please do not add any code
2+
// that imports AppURL to this file, either directly (by adding an import to AppURL in this file) or indirectly (by
3+
// adding imports which import AppURL).
4+
import { getServerContext } from '@labkey/api';
5+
6+
import { ModuleContext, resolveModuleContext } from '../components/base/ServerContext';
7+
import { Container } from '../components/base/models/Container';
8+
9+
// These ids should match what is used by the MenuProviders in the Java code, so we can avoid toLowerCase comparisons.
10+
export const LKS_PRODUCT_ID = 'LabKeyServer';
11+
export const BIOLOGICS_PRODUCT_ID = 'Biologics';
12+
export const LIMS_PRODUCT_ID = 'LIMS';
13+
export const SAMPLE_MANAGER_PRODUCT_ID = 'SampleManager';
14+
export const FREEZER_MANAGER_PRODUCT_ID = 'FreezerManager';
15+
16+
export function isFreezerManagementEnabled(moduleContext?: ModuleContext): boolean {
17+
return resolveModuleContext(moduleContext)?.inventory !== undefined;
18+
}
19+
20+
export function isBiologicsEnabled(moduleContext?: ModuleContext): boolean {
21+
return resolveModuleContext(moduleContext)?.biologics !== undefined;
22+
}
23+
24+
export function isSampleManagerEnabled(moduleContext?: ModuleContext): boolean {
25+
return resolveModuleContext(moduleContext)?.samplemanagement !== undefined;
26+
}
27+
28+
export function isPremiumProductEnabled(moduleContext?: ModuleContext): boolean {
29+
return isSampleManagerEnabled(moduleContext) || isBiologicsEnabled(moduleContext);
30+
}
31+
32+
export function isLIMSEnabled(moduleContext?: ModuleContext, container?: Container): boolean {
33+
// The check for folder type is not ideal here, but since the product is provided through the sampleManagement module
34+
// a simple module check isn't sufficient. Since the product configuration is global to the server, we have no good
35+
// way to know which URLs to construct in a particular container except by inspecting the folder type (at the moment).
36+
return isSampleManagerEnabled(moduleContext) && (container ?? getServerContext().container)?.folderType === 'LIMS';
37+
}
38+
39+
export function getPrimaryAppProductId(moduleContext?: ModuleContext): string {
40+
if (isBiologicsEnabled(moduleContext)) return BIOLOGICS_PRODUCT_ID;
41+
if (isLIMSEnabled(moduleContext)) return LIMS_PRODUCT_ID;
42+
if (isSampleManagerEnabled(moduleContext)) return SAMPLE_MANAGER_PRODUCT_ID;
43+
if (isFreezerManagementEnabled(moduleContext)) return FREEZER_MANAGER_PRODUCT_ID;
44+
return undefined;
45+
}

packages/components/src/internal/app/utils.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ import {
2121
import { Container } from '../components/base/models/Container';
2222

2323
import { MenuSectionConfig } from '../components/navigation/model';
24-
24+
import {
25+
isBiologicsEnabled,
26+
isFreezerManagementEnabled,
27+
isLIMSEnabled,
28+
isPremiumProductEnabled,
29+
isSampleManagerEnabled,
30+
} from './products';
2531
import {
2632
addAssaysSectionConfig,
2733
addSourcesSectionConfig,
@@ -38,19 +44,14 @@ import {
3844
isAssayEnabled,
3945
isAssayQCEnabled,
4046
isAssayRequestsEnabled,
41-
isBiologicsEnabled,
4247
isCalculatedFieldsEnabled,
4348
isCommunityDistribution,
4449
isELNEnabled,
45-
isFreezerManagementEnabled,
46-
isLIMSEnabled,
4750
isLKSSupportEnabled,
4851
isMediaEnabled,
49-
isPremiumProductEnabled,
5052
isProductNavigationEnabled,
5153
isProjectContainer,
5254
isProtectedDataEnabled,
53-
isSampleManagerEnabled,
5455
isSampleStatusEnabled,
5556
isSharedContainer,
5657
isTransformScriptsEnabled,

packages/components/src/internal/app/utils.ts

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { hasAllPermissions, hasPermissions, User } from '../components/base/mode
1212
import { MenuSectionConfig } from '../components/navigation/model';
1313
import { imageURL } from '../url/ActionURL';
1414
import { AppURL } from '../url/AppURL';
15-
import { ModuleContext } from '../components/base/ServerContext';
15+
import { ModuleContext, resolveModuleContext } from '../components/base/ServerContext';
1616

1717
import { Container } from '../components/base/models/Container';
1818

@@ -51,6 +51,13 @@ import {
5151
ARCHIVED_FOLDERS,
5252
DEPRECATED_OBJECT_LEVEL_DISCUSSIONS,
5353
} from './constants';
54+
import {
55+
isBiologicsEnabled,
56+
isFreezerManagementEnabled,
57+
isLIMSEnabled,
58+
isPremiumProductEnabled,
59+
isSampleManagerEnabled,
60+
} from './products';
5461

5562
declare var LABKEY: LabKey;
5663

@@ -75,10 +82,6 @@ export enum CloseEventCode {
7582
TLS_HANDSHAKE = 1015,
7683
}
7784

78-
export function resolveModuleContext(moduleContext?: ModuleContext): ModuleContext {
79-
return moduleContext ?? getServerContext().moduleContext;
80-
}
81-
8285
export function userCanReadAssays(user: User): boolean {
8386
return hasAllPermissions(user, [PermissionTypes.ReadAssay]);
8487
}
@@ -139,10 +142,6 @@ export function userCanEditSharedViews(user: User): boolean {
139142
return hasPermissions(user, [PermissionTypes.EditSharedView]);
140143
}
141144

142-
export function isFreezerManagementEnabled(moduleContext?: ModuleContext): boolean {
143-
return resolveModuleContext(moduleContext)?.inventory !== undefined;
144-
}
145-
146145
export function isOntologyEnabled(moduleContext?: ModuleContext): boolean {
147146
return hasModule('Ontology', moduleContext);
148147
}
@@ -183,18 +182,6 @@ export function setProductFolders(moduleContext: ModuleContext, hasProductFolder
183182
});
184183
}
185184

186-
export function isSampleManagerEnabled(moduleContext?: ModuleContext): boolean {
187-
return resolveModuleContext(moduleContext)?.samplemanagement !== undefined;
188-
}
189-
190-
export function isBiologicsEnabled(moduleContext?: ModuleContext): boolean {
191-
return resolveModuleContext(moduleContext)?.biologics !== undefined;
192-
}
193-
194-
export function isPremiumProductEnabled(moduleContext?: ModuleContext): boolean {
195-
return isSampleManagerEnabled(moduleContext) || isBiologicsEnabled(moduleContext);
196-
}
197-
198185
export function isAppHomeFolder(container?: Partial<Container>, moduleContext?: ModuleContext): boolean {
199186
// If it's a Home project, or if it's a subfolder and products are disabled.
200187
const currentContainer: Partial<Container> = container ?? getServerContext().container;
@@ -394,13 +381,6 @@ export function isLKSSupportEnabled(moduleContext?: ModuleContext): boolean {
394381
return isBiologicsEnabled(moduleContext) || hasPremiumModule(moduleContext);
395382
}
396383

397-
export function isLIMSEnabled(moduleContext?: ModuleContext, container?: Container): boolean {
398-
// The check for folder type is not ideal here, but since the product is provided through the sampleManagement module
399-
// a simple module check isn't sufficient. Since the product configuration is global to the server, we have no good
400-
// way to know which URLs to construct in a particular container except by inspecting the folder type (at the moment).
401-
return isSampleManagerEnabled(moduleContext) && (container ?? getServerContext().container)?.folderType === 'LIMS';
402-
}
403-
404384
export function isAssayFileUploadEnabled(moduleContext?: ModuleContext): boolean {
405385
return isBiologicsEnabled(moduleContext) || isLIMSEnabled(moduleContext);
406386
}

packages/components/src/internal/components/auditlog/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import React, { ReactNode } from 'react';
66
import { Map } from 'immutable';
77

8+
import { isSampleManagerEnabled } from '../../app/products';
89
import {
910
isAssayEnabled,
1011
isChartBuilderEnabled,
1112
isELNEnabled,
1213
isProductFoldersEnabled,
1314
isRegistryEnabled,
14-
isSampleManagerEnabled,
1515
isWorkflowEnabled,
1616
} from '../../app/utils';
1717
import { ASSAYS_KEY, BOXES_KEY, SAMPLES_KEY, USER_KEY, WORKFLOW_KEY } from '../../app/constants';

packages/components/src/internal/components/base/ServerContext.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ export function withServerContext<T = {}>(Component: ComponentType<T>): FC<T> {
9494
);
9595
};
9696
}
97+
98+
export function resolveModuleContext(moduleContext?: ModuleContext): ModuleContext {
99+
return moduleContext ?? getServerContext().moduleContext;
100+
}

packages/components/src/internal/components/domainproperties/assay/AssayPropertiesPanel.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@ import {
1010
import { SectionHeading } from '../SectionHeading';
1111
import { BasePropertiesPanel, BasePropertiesPanelProps } from '../BasePropertiesPanel';
1212

13-
import {
14-
hasModule,
15-
isAssayQCEnabled,
16-
isPlatesEnabled,
17-
isPremiumProductEnabled,
18-
isTransformScriptsEnabled,
19-
} from '../../../app/utils';
13+
import { isPremiumProductEnabled } from '../../../app/products';
14+
import { hasModule, isAssayQCEnabled, isPlatesEnabled, isTransformScriptsEnabled } from '../../../app/utils';
2015

2116
import { useServerContext } from '../../base/ServerContext';
2217

packages/components/src/internal/components/domainproperties/dataclasses/DataClassDesigner.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { PureComponent, ReactNode } from 'react';
22
import { produce } from 'immer';
3-
import { List, Map } from 'immutable';
3+
import { List } from 'immutable';
44

55
import { Domain, getServerContext } from '@labkey/api';
66

@@ -9,7 +9,8 @@ import DomainForm from '../DomainForm';
99
import { getDomainPanelStatus, handleDomainUpdates, saveDomain, scrollDomainErrorIntoView } from '../actions';
1010
import { BaseDomainDesigner, InjectedBaseDomainDesignerProps, withBaseDomainDesigner } from '../BaseDomainDesigner';
1111

12-
import { getAppHomeFolderPath, isSampleManagerEnabled } from '../../../app/utils';
12+
import { isSampleManagerEnabled } from '../../../app/products';
13+
import { getAppHomeFolderPath } from '../../../app/utils';
1314

1415
import { NameExpressionValidationModal } from '../validation/NameExpressionValidationModal';
1516

packages/components/src/internal/components/domainproperties/dataclasses/DataClassPropertiesPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { loadNameExpressionOptions } from '../../settings/actions';
2323

2424
import { PREFIX_SUBSTITUTION_EXPRESSION, PROPERTIES_PANEL_NAMING_PATTERN_WARNING_MSG } from '../constants';
2525

26-
import { isSampleManagerEnabled } from '../../../app/utils';
26+
import { isSampleManagerEnabled } from '../../../app/products';
2727

2828
import { NameExpressionGenIdProps } from '../NameExpressionGenIdBanner';
2929

0 commit comments

Comments
 (0)