-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.ts
More file actions
711 lines (598 loc) · 26.9 KB
/
utils.ts
File metadata and controls
711 lines (598 loc) · 26.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
/*
* Copyright (c) 2019 LabKey Corporation. All rights reserved. No portion of this work may be reproduced in
* any form or by any electronic or mechanical means without written permission from LabKey Corporation.
*/
import { List, Map } from 'immutable';
import { ActionURL, getServerContext, LabKey, PermissionTypes } from '@labkey/api';
import { useMemo } from 'react';
import { hasAllPermissions, hasPermissions, User } from '../components/base/models/User';
import { MenuSectionConfig } from '../components/navigation/model';
import { imageURL } from '../url/ActionURL';
import { AppURL } from '../url/AppURL';
import { ModuleContext, resolveModuleContext } from '../components/base/ServerContext';
import { Container } from '../components/base/models/Container';
import { SHARED_CONTAINER_PATH } from '../constants';
import { AppProperties } from './models';
import {
APPLICATION_PROPERTIES,
ARCHIVED_FOLDERS,
ASSAYS_KEY,
BIOLOGICS_APP_PROPERTIES,
EXPERIMENTAL_PRODUCT_ALL_FOLDER_LOOKUPS,
EXPERIMENTAL_PRODUCT_FOLDER_DATA_LISTING_SCOPED,
EXPERIMENTAL_REQUESTS_MENU,
EXPERIMENTAL_SAMPLE_ALIQUOT_SELECTOR,
FOLDER_DATA_TYPE_EXCLUSIONS,
FREEZER_MANAGER_APP_PROPERTIES,
FREEZERS_KEY,
HOME_KEY,
LABKEY_SERVER_PRODUCT_NAME,
LIMS_APP_PROPERTIES,
MEDIA_KEY,
NEW_ASSAY_DESIGN_HREF,
NEW_SAMPLE_TYPE_HREF,
NEW_SOURCE_TYPE_HREF,
NEW_STANDARD_ASSAY_DESIGN_HREF,
NOTEBOOKS_KEY,
PICKLIST_KEY,
PLATES_KEY,
ProductFeature,
REGISTRY_KEY,
REQUESTS_KEY,
SAMPLE_MANAGER_APP_PROPERTIES,
SAMPLES_KEY,
SOURCES_KEY,
USER_KEY,
WORKFLOW_KEY,
} from './constants';
import {
biologicsIsPrimaryApp,
FREEZER_MANAGER_PRODUCT_ID,
getPrimaryAppProductId,
isBiologicsEnabled,
isFreezerManagementEnabled,
isLIMSProduct,
isSampleManagerEnabled,
sampleManagerIsPrimaryApp,
} from './products';
declare var LABKEY: LabKey;
// Type definition not provided for event codes so here we provide our own
// Source: https://www.iana.org/assignments/websocket/websocket.xml#close-code-number
export enum CloseEventCode {
ABNORMAL_CLOSURE = 1006,
BAD_GATEWAY = 1014,
GOING_AWAY = 1001,
INTERNAL_ERROR = 1011,
INVALID_FRAME_PAYLOAD_DATA = 1007,
MESSAGE_TOO_BIG = 1009,
MISSING_EXT = 1010,
NO_STATUS_RCVD = 1005,
NORMAL_CLOSURE = 1000,
POLICY_VIOLATION = 1008,
PROTOCOL_ERROR = 1002,
RESERVED = 1004,
SERVICE_RESTART = 1012,
TLS_HANDSHAKE = 1015,
TRY_AGAIN_LATER = 1013,
UNSUPPORTED_DATA = 1003,
}
export function userCanReadAssays(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.ReadAssay]);
}
export function userCanReadSources(user: User): boolean {
return userCanReadDataClasses(user);
}
export function userCanReadRegistry(user: User): boolean {
return userCanReadDataClasses(user);
}
export function userCanReadDataClasses(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.ReadDataClass]);
}
export function userCanReadMedia(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.ReadMedia]);
}
export function userCanReadNotebooks(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.ReadNotebooks]);
}
export function userCanManagePicklists(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.ManagePicklists]);
}
export function userCanDeletePublicPicklists(user: User): boolean {
return user.isAdmin;
}
export function userCanManageSampleWorkflow(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.ManageSampleWorkflows], false);
}
export function userCanDesignSourceTypes(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.DesignDataClass]);
}
export function userCanDesignLocations(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.DesignStorage], false);
}
export function userCanEditStorageData(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.EditStorageData], false);
}
export function userCanReadUserDetails(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.CanSeeUserDetails], false);
}
export function userCanReadGroupDetails(user: User): boolean {
return hasAllPermissions(user, [PermissionTypes.CanSeeGroupDetails], false);
}
export function userCanEditSharedViews(user: User): boolean {
return hasPermissions(user, [PermissionTypes.EditSharedView]);
}
export function isOntologyEnabled(moduleContext?: ModuleContext): boolean {
return hasModule('Ontology', moduleContext);
}
export function isProductNavigationEnabled(productId: string, moduleContext?: ModuleContext): boolean {
return getPrimaryAppProductId(moduleContext) === productId;
}
export function isExperimentAliasEnabled(moduleContext?: ModuleContext): boolean {
return biologicsIsPrimaryApp(moduleContext);
}
export function isProductFoldersEnabled(moduleContext?: ModuleContext): boolean {
return resolveModuleContext(moduleContext)?.query?.isProductFoldersEnabled === true;
}
export function hasProductFolders(moduleContext?: ModuleContext): boolean {
return resolveModuleContext(moduleContext)?.query?.hasProductFolders === true;
}
export function setProductFolders(moduleContext: ModuleContext, hasProductFolders: boolean): ModuleContext {
// side-effect set global moduleContext
if (LABKEY?.moduleContext?.query) {
LABKEY.moduleContext.query.hasProductFolders = hasProductFolders;
}
return Object.assign(moduleContext ?? {}, {
query: Object.assign(moduleContext?.query ?? {}, { hasProductFolders }),
});
}
export function isAppHomeFolder(container?: Partial<Container>, moduleContext?: ModuleContext): boolean {
// If it's a Home project, or if it's a subfolder and products are disabled.
const currentContainer: Partial<Container> = container ?? getServerContext().container;
const isTopFolder = currentContainer.isProject || isProjectContainer(currentContainer.path);
const isSubFolder = currentContainer.isFolder || isSubFolderContainer(currentContainer.path);
return isTopFolder || (isSubFolder && !isProductFoldersEnabled(moduleContext));
}
export function getAppHomeFolderPath(container?: Partial<Container>, moduleContext?: ModuleContext): string {
const currentContainer: Partial<Container> = container ?? getServerContext().container;
return isAppHomeFolder(currentContainer, moduleContext) ? currentContainer.path : currentContainer.parentPath;
}
export function getAppHomeFolderId(container?: Container, moduleContext?: ModuleContext): string {
const currentContainer: Partial<Container> = container ?? getServerContext().container;
return isAppHomeFolder(currentContainer, moduleContext) ? currentContainer.id : currentContainer.parentId;
}
export function isSharedContainer(containerPath: string): boolean {
return containerPath === SHARED_CONTAINER_PATH;
}
export function freezerManagerIsCurrentApp(): boolean {
return getCurrentAppProperties()?.productId === FREEZER_MANAGER_APP_PROPERTIES.productId;
}
export function isSampleStatusEnabled(moduleContext?: ModuleContext): boolean {
return hasSampleManagementModule(moduleContext);
}
export function isQueryMetadataEditor(): boolean {
const action = ActionURL.getAction()?.toLowerCase() || '';
return action === 'metadataquery' || action.startsWith('querymetadataeditor');
}
export function getCurrentAppProperties(): AppProperties {
const lcController = ActionURL.getController().toLowerCase();
if (!lcController) return undefined;
if (lcController === SAMPLE_MANAGER_APP_PROPERTIES.controllerName.toLowerCase()) {
return SAMPLE_MANAGER_APP_PROPERTIES;
} else if (lcController === BIOLOGICS_APP_PROPERTIES.controllerName.toLowerCase()) {
return BIOLOGICS_APP_PROPERTIES;
} else if (lcController === FREEZER_MANAGER_APP_PROPERTIES.controllerName.toLowerCase()) {
return FREEZER_MANAGER_APP_PROPERTIES;
} else if (lcController === LIMS_APP_PROPERTIES.controllerName.toLowerCase()) {
return LIMS_APP_PROPERTIES;
}
return undefined;
}
export function isApp(): boolean {
return getCurrentAppProperties() !== undefined;
}
/**
* In LKS we use the 'primary' bootstrap class for submit buttons, but in our apps we use 'success', this helper method
* returns the correct class for you.
*/
export function getSubmitButtonClass(): string {
return isApp() ? 'success' : 'primary';
}
export function getPrimaryAppProperties(moduleContext?: ModuleContext): AppProperties {
return APPLICATION_PROPERTIES[getPrimaryAppProductId(moduleContext)];
}
export function isAllProductFoldersFilteringEnabled(moduleContext?: ModuleContext): boolean {
return resolveModuleContext(moduleContext)?.query?.[EXPERIMENTAL_PRODUCT_ALL_FOLDER_LOOKUPS] === true;
}
export function isProductFoldersDataListingScopedToFolder(moduleContext?: ModuleContext): boolean {
return resolveModuleContext(moduleContext)?.query?.[EXPERIMENTAL_PRODUCT_FOLDER_DATA_LISTING_SCOPED] === true;
}
export function getFolderDataExclusion(moduleContext?: ModuleContext): Record<string, number[]> {
return resolveModuleContext(moduleContext)?.samplemanagement?.[FOLDER_DATA_TYPE_EXCLUSIONS];
}
export function setFolderDataExclusion(
moduleContext: ModuleContext,
dataTypeExclusions: Record<string, number[]>
): ModuleContext {
// side-effect set global moduleContext
if (LABKEY?.moduleContext?.samplemanagement) {
LABKEY.moduleContext.samplemanagement.dataTypeExclusions = dataTypeExclusions;
}
return Object.assign(moduleContext ?? {}, {
samplemanagement: Object.assign(moduleContext?.samplemanagement ?? {}, { dataTypeExclusions }),
});
}
export function getArchivedFolders(moduleContext?: ModuleContext): string[] {
return resolveModuleContext(moduleContext)?.samplemanagement?.[ARCHIVED_FOLDERS];
}
export function getFolderDashboardSampleTypeExclusion(moduleContext?: ModuleContext): number[] {
return getFolderDataExclusion(moduleContext)?.['DashboardSampleType'];
}
export function getFolderSampleTypeExclusion(moduleContext?: ModuleContext): number[] {
return getFolderDataExclusion(moduleContext)?.['SampleType'];
}
export function getFolderDataClassExclusion(moduleContext?: ModuleContext): number[] {
return getFolderDataExclusion(moduleContext)?.['DataClass'];
}
export function getFolderAssayDesignExclusion(moduleContext?: ModuleContext): number[] {
return getFolderDataExclusion(moduleContext)?.['AssayDesign'];
}
export function isAssayEnabled(moduleContext?: ModuleContext): boolean {
return (
hasModule('assay', moduleContext) &&
(isCommunityDistribution(moduleContext) || isFeatureEnabled(ProductFeature.Assay, moduleContext))
);
}
export function isAssayQCEnabled(moduleContext?: ModuleContext): boolean {
// NK: The product tiers which include Assay QC are not fully defined.
// For now (v22.11+), we're going to continue offering Assay QC features until
// we can fully define all desired product tiers. Once that is done we can respect
// the associated feature flag instead.
// isFeatureEnabled(ProductFeature.AssayQC, moduleContext)
return isAssayEnabled(moduleContext) && hasPremiumModule(moduleContext);
}
export function isAssayRequestsEnabled(moduleContext?: ModuleContext): boolean {
return (
hasModule('assayRequest', moduleContext) &&
resolveModuleContext(moduleContext)?.biologics?.[EXPERIMENTAL_REQUESTS_MENU] === true
);
}
// Don't enable assay design export unless there is an import capability (which we don't have for LKSM products)
export function isAssayDesignExportEnabled(moduleContext?: ModuleContext): boolean {
return hasPremiumModule(moduleContext);
}
export function isNonstandardAssayEnabled(moduleContext?: ModuleContext): boolean {
// Issue 51775: only LKB has pages for non-standard assays
return biologicsIsPrimaryApp(moduleContext) && isFeatureEnabled(ProductFeature.NonstandardAssay, moduleContext);
}
export function isPlatesEnabled(moduleContext?: ModuleContext): boolean {
return biologicsIsPrimaryApp(moduleContext);
}
export function isChartBuilderEnabled(moduleContext?: ModuleContext): boolean {
return isFeatureEnabled(ProductFeature.ChartBuilding, moduleContext);
}
// Should be enabled for LKS Community & LKS Starter, but in the apps only if the feature is enabled
export function isTransformScriptsEnabled(moduleContext?: ModuleContext): boolean {
return isApp() ? isFeatureEnabled(ProductFeature.TransformScripts, moduleContext) : true;
}
export function isRReportsEnabled(moduleContext?: ModuleContext): boolean {
return biologicsIsPrimaryApp(moduleContext);
}
export function isLKSSupportEnabled(moduleContext?: ModuleContext): boolean {
return isBiologicsEnabled(moduleContext) || hasPremiumModule(moduleContext);
}
export function isAssayFileUploadEnabled(moduleContext?: ModuleContext): boolean {
return isLIMSProduct(moduleContext);
}
export function isELNEnabled(moduleContext?: ModuleContext): boolean {
return hasModule('LabBook', moduleContext) && isFeatureEnabled(ProductFeature.ELN, moduleContext);
}
export function isProtectedDataEnabled(moduleContext?: ModuleContext): boolean {
return hasComplianceModule(moduleContext) && hasModule('complianceActivities', moduleContext);
}
export function isNamingPrefixEnabled(moduleContext?: ModuleContext): boolean {
return isBiologicsEnabled(moduleContext);
}
export function isMediaEnabled(moduleContext?: ModuleContext): boolean {
return isBiologicsEnabled(moduleContext) && isFeatureEnabled(ProductFeature.Media, moduleContext);
}
export function isRegistryEnabled(moduleContext?: ModuleContext): boolean {
return isBiologicsEnabled(moduleContext) && isFeatureEnabled(ProductFeature.BiologicsRegistry, moduleContext);
}
export function isSourceTypeEnabled(moduleContext?: ModuleContext): boolean {
return isSampleManagerEnabled(moduleContext) && !isRegistryEnabled(moduleContext);
}
export function isAdvancedDomainPropertiesEnabled(moduleContext?: ModuleContext): boolean {
return !sampleManagerIsPrimaryApp(moduleContext) || hasPremiumModule(moduleContext);
}
export function isNotebookTagsEnabled(moduleContext?: ModuleContext): boolean {
return isBiologicsEnabled(moduleContext);
}
export function isWorkflowEnabled(moduleContext?: ModuleContext): boolean {
return (
hasModule(SAMPLE_MANAGER_APP_PROPERTIES.moduleName, moduleContext) &&
isFeatureEnabled(ProductFeature.Workflow, moduleContext)
);
}
export function isDataChangeCommentRequirementFeatureEnabled(moduleContext?: ModuleContext): boolean {
return isFeatureEnabled(ProductFeature.DataChangeCommentRequirement, moduleContext);
}
// should be enabled via ProductFeature for LKSM Professional, LIMS, LKB AND via distribution for LKS Professional, LKS Enterprise
export function isCalculatedFieldsEnabled(moduleContext?: ModuleContext): boolean {
return isApp()
? isFeatureEnabled(ProductFeature.CalculatedFields, moduleContext)
: isProfessionalDistribution(moduleContext) || isEnterpriseDistribution(moduleContext);
}
export function isCustomImportTemplatesEnabled(moduleContext?: ModuleContext): boolean {
return isFeatureEnabled(ProductFeature.CustomImportTemplates, moduleContext);
}
// This is enabled for all distributions except sample manager-only distributions. LKS distributions don't
// currently supply feature flags, so a pure flag check is not sufficient.
export function isConditionalFormattingEnabled(moduleContext?: ModuleContext): boolean {
return (
isFeatureEnabled(ProductFeature.ConditionalFormatting, moduleContext) ||
!isSampleManagerDistribution(moduleContext)
);
}
export function isFeatureEnabled(flag: ProductFeature, moduleContext?: ModuleContext): boolean {
return resolveModuleContext(moduleContext)?.core?.productFeatures?.indexOf(flag) >= 0;
}
export function isSampleAliquotSelectorEnabled(moduleContext?: ModuleContext): boolean {
return resolveModuleContext(moduleContext)?.samplemanagement?.[EXPERIMENTAL_SAMPLE_ALIQUOT_SELECTOR] === true;
}
export function hasModule(moduleName: string, moduleContext?: ModuleContext): boolean {
return resolveModuleContext(moduleContext).api?.moduleNames?.indexOf(moduleName.toLowerCase()) >= 0;
}
export function hasPremiumModule(moduleContext?: ModuleContext): boolean {
return hasModule('Premium', moduleContext);
}
export function hasProfessionalModule(moduleContext?: ModuleContext): boolean {
return hasModule('Professional', moduleContext);
}
export function hasComplianceModule(moduleContext?: ModuleContext): boolean {
return hasModule('Compliance', moduleContext);
}
export function hasSampleManagementModule(moduleContext?: ModuleContext): boolean {
return hasModule('SampleManagement', moduleContext);
}
export function isEnterpriseDistribution(moduleContext?: ModuleContext): boolean {
return (
hasPremiumModule(moduleContext) && hasProfessionalModule(moduleContext) && hasComplianceModule(moduleContext)
);
}
export function isProfessionalDistribution(moduleContext?: ModuleContext): boolean {
return (
hasPremiumModule(moduleContext) && hasProfessionalModule(moduleContext) && !hasComplianceModule(moduleContext)
);
}
export function isStarterDistribution(moduleContext?: ModuleContext): boolean {
return (
hasPremiumModule(moduleContext) && !hasProfessionalModule(moduleContext) && !hasComplianceModule(moduleContext)
);
}
export function isSampleManagerDistribution(moduleContext?: ModuleContext): boolean {
return hasSampleManagementModule(moduleContext) && !hasPremiumModule(moduleContext);
}
export function isCommunityDistribution(moduleContext?: ModuleContext): boolean {
return !hasSampleManagementModule(moduleContext) && !hasPremiumModule(moduleContext);
}
export function isRestrictedIssueListSupported(moduleContext?: ModuleContext): boolean {
return resolveModuleContext(moduleContext)?.issues?.hasRestrictedIssueList === true;
}
export function isProjectContainer(containerPath?: string): boolean {
return getContainerDepth(containerPath) === 1;
}
function isSubFolderContainer(containerPath?: string): boolean {
return getContainerDepth(containerPath) > 1;
}
export function getContainerDepth(containerPath?: string): number {
let path = containerPath ?? getServerContext().container.path;
if (!path) return 0;
if (!path.endsWith('/')) path = path + '/';
return path.split('/').filter(p => !!p).length;
}
export function getProjectPath(containerPath?: string): string {
const path = containerPath ?? getServerContext().container.path;
if (!path) return undefined;
return path.split('/').filter(p => !!p)[0] + '/';
}
// exported for testing
export function getStorageSectionConfig(user: User, moduleContext: any): MenuSectionConfig {
if (isFreezerManagementEnabled(moduleContext)) {
let locationsMenuConfig = new MenuSectionConfig({
emptyText: 'No storage has been defined',
filteredEmptyText: 'No storage available',
iconURL: imageURL('_images', 'freezer_menu.svg'),
headerURLPart: HOME_KEY,
});
if (user && userCanDesignLocations(user)) {
locationsMenuConfig = locationsMenuConfig.merge({
emptyAppURL: AppURL.create(FREEZERS_KEY, 'new').setProductId(FREEZER_MANAGER_PRODUCT_ID),
emptyURLText: 'Create storage',
}) as MenuSectionConfig;
}
return locationsMenuConfig;
}
return undefined;
}
// exported for testing
export function addSourcesSectionConfig(
user: User,
sectionConfigs: List<Map<string, MenuSectionConfig>>
): List<Map<string, MenuSectionConfig>> {
let sourcesMenuConfig = new MenuSectionConfig({
emptyText: 'No source types have been defined',
filteredEmptyText: 'No source types available',
iconURL: imageURL('_images', 'source_type.svg'),
headerURLParams: { 'sourcetypegrid.sort': 'Name' }, // Issue 52472
});
if (user && userCanDesignSourceTypes(user)) {
sourcesMenuConfig = sourcesMenuConfig.merge({
emptyAppURL: NEW_SOURCE_TYPE_HREF,
emptyURLText: 'Create a source type',
}) as MenuSectionConfig;
}
return sectionConfigs.push(Map({ [SOURCES_KEY]: sourcesMenuConfig }));
}
// exported for testing
export function getSamplesSectionConfig(user: User): MenuSectionConfig {
let samplesMenuConfig = new MenuSectionConfig({
emptyText: 'No sample types have been defined',
filteredEmptyText: 'No sample types available',
iconURL: imageURL('_images', 'samples.svg'),
headerURLParams: { 'samplesetgrid.sort': 'Name' }, // Issue 52472
});
if (user && user.hasDesignSampleTypesPermission()) {
samplesMenuConfig = samplesMenuConfig.merge({
emptyAppURL: NEW_SAMPLE_TYPE_HREF,
emptyURLText: 'Create a sample type',
}) as MenuSectionConfig;
}
return samplesMenuConfig;
}
// exported for testing
export function addAssaysSectionConfig(
user: User,
sectionConfigs: List<Map<string, MenuSectionConfig>>,
standardAssayOnly: boolean
): List<Map<string, MenuSectionConfig>> {
let assaysMenuConfig = new MenuSectionConfig({
emptyText: 'No assays have been defined',
filteredEmptyText: 'No assays available',
iconURL: imageURL('_images', 'assay.svg'),
});
if (user && user.hasDesignAssaysPermission()) {
assaysMenuConfig = assaysMenuConfig.merge({
emptyAppURL: standardAssayOnly ? NEW_STANDARD_ASSAY_DESIGN_HREF : NEW_ASSAY_DESIGN_HREF,
emptyURLText: 'Create an assay design',
}) as MenuSectionConfig;
}
return sectionConfigs.push(Map<string, MenuSectionConfig>().set(ASSAYS_KEY, assaysMenuConfig));
}
export function getPlatesSectionConfig(): MenuSectionConfig {
return new MenuSectionConfig({
iconURL: imageURL('_images', 'plates.svg'),
staticContent: true,
});
}
function getWorkflowSectionConfig(): MenuSectionConfig {
return new MenuSectionConfig({
iconURL: imageURL('_images', 'workflow.svg'),
});
}
function getPicklistsSectionConfig(): MenuSectionConfig {
return new MenuSectionConfig({
iconURL: imageURL('_images', 'picklist.svg'),
});
}
function getNotebooksSectionConfig(): MenuSectionConfig {
return new MenuSectionConfig({
iconURL: imageURL('labbook/images', 'notebook_blue.svg'),
});
}
function getMediaSectionConfig(): MenuSectionConfig {
return new MenuSectionConfig({
iconURL: imageURL('_images', 'mixtures.svg'),
});
}
function getRegistrySectionConfig(): MenuSectionConfig {
return new MenuSectionConfig({
iconURL: imageURL('_images', 'molecule.svg'),
headerURLParams: { 'query.sort': 'Name' }, // Issue 52472
});
}
const USER_SECTION_CONFIG = new MenuSectionConfig({
iconCls: 'fas fa-user-circle ',
});
const REQUESTS_SECTION_CONFIG = new MenuSectionConfig({
iconURL: imageURL('_images', 'default.svg'),
staticContent: true,
useOriginalURL: true,
});
function getBioWorkflowNotebookMediaConfigs(): Map<string, MenuSectionConfig> {
return Map({
[WORKFLOW_KEY]: getWorkflowSectionConfig(),
[MEDIA_KEY]: getMediaSectionConfig(),
[PICKLIST_KEY]: getPicklistsSectionConfig(),
[NOTEBOOKS_KEY]: getNotebooksSectionConfig(),
});
}
// exported for testing
export function getMenuSectionConfigs(user: User, moduleContext?: ModuleContext): List<Map<string, MenuSectionConfig>> {
let sectionConfigs = List<Map<string, MenuSectionConfig>>();
const isBioEnabled = isBiologicsEnabled(moduleContext);
const isSMEnabled = isSampleManagerEnabled(moduleContext);
if (isRegistryEnabled(moduleContext)) {
sectionConfigs = sectionConfigs.push(Map({ [REGISTRY_KEY]: getRegistrySectionConfig() }));
} else if (isSMEnabled) {
sectionConfigs = addSourcesSectionConfig(user, sectionConfigs);
}
if (isSMEnabled) {
let configs = Map<string, MenuSectionConfig>({ [SAMPLES_KEY]: getSamplesSectionConfig(user) });
if (isPlatesEnabled(moduleContext)) {
configs = configs.set(PLATES_KEY, getPlatesSectionConfig());
}
sectionConfigs = sectionConfigs.push(configs);
if (isAssayEnabled(moduleContext)) {
sectionConfigs = addAssaysSectionConfig(user, sectionConfigs, !isNonstandardAssayEnabled(moduleContext));
}
}
const storageConfig = getStorageSectionConfig(user, moduleContext);
if (isBioEnabled) {
if (isAssayRequestsEnabled(moduleContext)) {
// When "Requests" are enabled render as two columns
let requestsCol = Map({
[REQUESTS_KEY]: REQUESTS_SECTION_CONFIG,
});
// ... and put the storage in this same column
if (storageConfig) {
requestsCol = requestsCol.set(FREEZERS_KEY, storageConfig);
}
sectionConfigs = sectionConfigs.push(requestsCol, getBioWorkflowNotebookMediaConfigs());
} else {
if (storageConfig) {
sectionConfigs = sectionConfigs.push(Map({ [FREEZERS_KEY]: storageConfig }));
}
sectionConfigs = sectionConfigs.push(getBioWorkflowNotebookMediaConfigs());
}
} else if (isSMEnabled) {
if (storageConfig) {
sectionConfigs = sectionConfigs.push(Map({ [FREEZERS_KEY]: storageConfig }));
}
let configs = Map<string, MenuSectionConfig>({});
if (isWorkflowEnabled(moduleContext)) {
configs = configs.set(WORKFLOW_KEY, getWorkflowSectionConfig());
}
configs = configs.set(PICKLIST_KEY, getPicklistsSectionConfig());
if (isELNEnabled(moduleContext)) {
configs = configs.set(NOTEBOOKS_KEY, getNotebooksSectionConfig());
}
sectionConfigs = sectionConfigs.push(configs);
} else {
if (storageConfig) {
sectionConfigs = sectionConfigs.push(Map({ [FREEZERS_KEY]: storageConfig }));
}
sectionConfigs = sectionConfigs.push(Map({ [USER_KEY]: USER_SECTION_CONFIG }));
}
return sectionConfigs;
}
export const useMenuSectionConfigs = (
user: User,
moduleContext?: ModuleContext
): List<Map<string, MenuSectionConfig>> => {
return useMemo(() => getMenuSectionConfigs(user, moduleContext), [user, moduleContext]);
};
// Returns the friendly name of the product, primarily for use in help text.
export function getCurrentProductName(moduleContext?: ModuleContext): string {
return getPrimaryAppProperties(moduleContext)?.name || LABKEY_SERVER_PRODUCT_NAME;
}
export function getAppProductIds(appProductId: string): List<string> {
let productIds = List.of(appProductId);
if (
appProductId === SAMPLE_MANAGER_APP_PROPERTIES.productId ||
appProductId === BIOLOGICS_APP_PROPERTIES.productId ||
appProductId === LIMS_APP_PROPERTIES.productId
) {
productIds = productIds.push(FREEZER_MANAGER_APP_PROPERTIES.productId);
}
return productIds;
}