-
-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathoptions.js
More file actions
2219 lines (2029 loc) · 91 KB
/
options.js
File metadata and controls
2219 lines (2029 loc) · 91 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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* global React ReactDOM */
import {sfConn, apiVersion, defaultApiVersion} from "./inspector.js";
import {nullToEmptyString, getLatestApiVersionFromOrg, Constants, UserInfoModel, createSpinForMethod, DataCache, applyProductionStyling} from "./utils.js";
import {getFlowScannerRules, FLOW_SCANNER_RULES_STORAGE_KEY} from "./flow-scanner-rules.js";
/* global initButton, lightningflowscanner */
import {DescribeInfo} from "./data-load.js";
import Toast from "./components/Toast.js";
import Tooltip from "./components/Tooltip.js";
import ColorPicker from "./components/ColorPicker.js";
import {PageHeader} from "./components/PageHeader.js";
class Model {
constructor(sfHost) {
this.sfHost = sfHost;
this.sfLink = "https://" + this.sfHost;
this.orgName = this.sfHost.split(".")[0]?.toUpperCase() || "";
this.spinnerCount = 0;
applyProductionStyling(sfHost);
// Initialize spinFor method
this.spinFor = createSpinForMethod(this);
this.describeInfo = new DescribeInfo(this.spinFor.bind(this), () => { });
// Initialize user info model - handles all user-related properties
this.userInfoModel = new UserInfoModel(this.spinFor.bind(this));
}
/**
* Notify React that we changed something, so it will rerender the view.
* Should only be called once at the end of an event or asynchronous operation, since each call can take some time.
* All event listeners (functions starting with "on") should call this function if they update the model.
* Asynchronous operations should use the spinFor function, which will call this function after the asynchronous operation completes.
* Other functions should not call this function, since they are called by a function that does.
* @param cb A function to be called once React has processed the update.
*/
didUpdate(cb) {
if (this.reactCallback) {
this.reactCallback(cb);
}
if (this.testCallback) {
this.testCallback();
}
}
}
class OptionsTabSelector extends React.Component {
constructor(props) {
super(props);
this.model = props.model;
this.appRef = props.appRef;
this.sfHost = this.model.sfHost;
// Get the tab from the URL or default to "user-experience"
const urlParams = new URLSearchParams(window.location.search);
const initialTabId = urlParams.get("selectedTab") || "user-experience";
this.state = {
selectedTabId: initialTabId
};
const flowScannerVersion = window.lightningflowscanner?.version || "";
const flowScannerTitle = flowScannerVersion ? `Enabled Rules (v${flowScannerVersion})` : "Enabled Rules";
this.tabs = [
{
id: "user-experience",
tabTitle: "User Experience",
content: [
{option: ArrowButtonOption, props: {key: 1}},
{option: Option, props: {type: "toggle", title: "Inspect page - Show table borders", key: "displayInspectTableBorders"}},
{option: Option, props: {type: "toggle", title: "Always open links in a new tab", key: "openLinksInNewTab", tooltip: "Enabling this option will prevent Lightning Navigation (faster loading) to be used"}},
{option: Option, props: {type: "toggle", title: "Open Permission Set / Permission Set Group summary from shortcuts", key: "enablePermSetSummary"}},
{option: MultiCheckboxButtonGroup,
props: {title: "Searchable metadata from Shortcut tab",
key: "metadataShortcutSearchOptions",
checkboxes: [
{label: "Flows", name: "flows", checked: true},
{label: "Profiles", name: "profiles", checked: true},
{label: "PermissionSets", name: "permissionSets", checked: true},
{label: "Apex Classes", name: "classes", checked: false}
]}
},
{option: Option, props: {type: "toggle", title: "Popup Dark theme", key: "popupDarkTheme"}},
{option: MultiCheckboxButtonGroup,
props: {title: "Show buttons",
key: "hideButtonsOption",
length: 8,
checkboxes: [
{label: "New", name: "new", checked: true},
{label: "Explore API", name: "explore-api", checked: true},
{label: "Org Limits", name: "org-limits", checked: true},
{label: "Options", name: "options", checked: true},
{label: "Generate Access Token", name: "generate-token", checked: true},
{label: "Copy User Id", name: "copy-userId", checked: true},
{label: "Reset Password", name: "reset-password", checked: true}
]}
},
{option: FaviconOption, props: {key: this.sfHost + FaviconOption.CUSTOM_FAVICON_KEY, tooltip: "You may need to add this domain to CSP trusted domains to see the favicon in Salesforce."}},
{option: Option, props: {type: "toggle", title: "Use favicon color on sandbox banner", key: "colorizeSandboxBanner"}},
{option: Option, props: {type: "toggle", title: "Highlight PROD (color from favicon)", key: "colorizeProdBanner", tooltip: "Top border in extension pages and banner on Salesforce"}},
{option: Option, props: {type: "text", title: "Banner text", inputSize: "6", key: this.sfHost + "_prodBannerText", tooltip: "Text that will be displayed in the banner (if enabled)", placeholder: "WARNING: THIS IS PRODUCTION"}},
{option: Option, props: {type: "toggle", title: "Enable Lightning Navigation", key: "lightningNavigation", default: true, tooltip: "Enable faster navigation by using standard e.force:navigateToURL method"}},
{option: MultiCheckboxButtonGroup,
props: {title: "Exclude users from search (org specific)",
key: this.sfHost + Constants.USER_SEARCH_EXCLUSIONS_KEY,
checkboxes: Constants.USER_SEARCH_EXCLUSIONS_CHECKBOXES.map(({label, name}) => ({label, name, checked: false}))}
},
{option: MultiCheckboxButtonGroup,
props: {title: "User Default Search Fields",
key: "userDefaultSearchFieldsOptions",
checkboxes: [
{label: "Username", name: "username", checked: true},
{label: "Email", name: "email", checked: true},
{label: "Alias", name: "alias", checked: true},
{label: "Name", name: "name", checked: true},
{label: "Profile Name", name: "profile.name"}
]}
},
{option: MultiCheckboxButtonGroup,
props: {title: "Default Popup Tab",
key: "defaultPopupTab",
unique: true,
checkboxes: [
{label: "Object", name: "sobject", checked: true},
{label: "Users", name: "users"},
{label: "Shortcuts", name: "shortcuts"},
{label: "Org", name: "org"}
]}
},
{option: Option, props: {type: "toggle", title: "Enable Dynamic Popup Height", key: "popupHeighDynamictMode", default: false, tooltip: "When enabled, the popup height will be dynamically adjusted based on the content."}},
{option: Option, props: {type: "toggle", title: "Show recently viewed records in popup", key: Constants.ENABLE_RECENTLY_VIEWED_RECORDS, default: true, tooltip: "When enabled, queries and displays recently viewed records when focusing the Object search field in the popup."}},
]
},
{
id: "api",
tabTitle: "API",
content: [
{option: APIVersionOption, props: {key: 1}},
{option: Option,
props: {type: "text",
title: "API Consumer Key",
placeholder: "Consumer Key",
key: this.sfHost + Constants.CLIENT_ID,
inputSize: "5",
actionButton: {
label: "Delete Token",
title: "Delete the connected app generated token",
disabled: localStorage.getItem(this.sfHost + Constants.ACCESS_TOKEN) == null,
onClick: (e, model) => {
localStorage.removeItem(model.sfHost + Constants.ACCESS_TOKEN);
e.target.disabled = true;
}
}}},
{option: Option, props: {type: "text", title: "Rest Header", placeholder: "Rest Header", key: "createUpdateRestCalloutHeaders", inputSize: "6"}},
{option: Option, props: {type: "toggle", title: "Enable API Stats Debug Mode", key: Constants.API_DEBUG_STATISTICS_MODE, default: false, tooltip: "When enabled, tracks API call statistics (REST and SOAP) to help monitor API usage. Statistics can be viewed on the API Debug Statistics page."}},
{option: Option, props: {type: "toggle", title: "Preload SObjects before popup opens", key: Constants.PRELOAD_SOBJECTS_BEFORE_POPUP, default: true, tooltip: "When enabled, loads the SObjects list from cache before the popup is opened for faster context detection. Disable to reduce initial load time and only load when the Objects tab is accessed."}},
]
},
{
id: "cache",
tabTitle: "Cache",
content: [
{option: Option,
props: {
type: "button",
title: "Clear All Extension Cache",
key: "clearAllCache",
tooltip: "Clear all cache entries from both localStorage and browser.storage.local. This will remove all cached data including User Field Names, SObjects List, and any other cached information.",
actionButtonVariant: "destructive",
actionButton: {
label: "Clear All Cache",
title: "Clear all extension cache",
onClick: async (e, model, appRef) => {
await DataCache.clearAllExtensionCache();
if (appRef) {
appRef.setState({
showToast: true,
toastMessage: "All extension cache cleared successfully.",
toastVariant: "success",
toastTitle: "Success"
});
setTimeout(() => appRef.hideToast(), 3000);
}
}
}
}
},
{option: Option,
props: {
type: "number",
title: "User Field Names Cache Duration (hours)",
key: "cacheDuration_userFieldNames",
default: 168,
min: 1,
inputSize: "3",
tooltip: "Duration in hours for caching User field names. This cache stores User object field metadata to improve performance.",
actionButton: {
label: "Clear Cache",
title: "Clear User Field Names cache",
onClick: async (e, model, appRef) => {
await DataCache.clearCache("userFieldNames", model.sfHost, false, false);
if (appRef) {
appRef.setState({
showToast: true,
toastMessage: "User Field Names cache cleared successfully.",
toastVariant: "success",
toastTitle: "Success"
});
setTimeout(() => appRef.hideToast(), 3000);
}
}
}
}
},
{option: SObjectsCacheOptions, props: {key: "sobjectsCacheOptions"}}
]
},
{
id: "data-export",
tabTitle: "Data Export",
content: [
{option: CSVSeparatorOption, props: {key: 1}},
{option: Option, props: {type: "toggle", title: "Display Query Execution Time", key: "displayQueryPerformance", default: true}},
{option: MultiCheckboxButtonGroup,
props: {
title: "Date/Time Display Format",
key: "dateTimeFormat",
unique: true,
requireSelection: true,
tooltip: "Choose how date and time values are displayed in the data export table",
checkboxes: [
{label: "Salesforce Default (ISO 8601)", name: "iso8601", checked: true, tooltip: "YYYY-MM-DDTHH:MM:SS.sss+0000"},
{label: "American", name: "us", tooltip: "MM/DD/YYYY HH:MM:SS AM/PM"},
{label: "European", name: "european", tooltip: "DD/MM/YYYY HH:MM:SS"},
{label: "Asian", name: "asian", tooltip: "YYYY/MM/DD HH:MM:SS"}
]
}
},
{option: Option, props: {type: "toggle", title: "Use Local Timezone", key: "showLocalTime", default: false, tooltip: "When enabled, converts date/time values to your local timezone instead of UTC"}},
{option: Option, props: {type: "toggle", title: "Display Timezone", key: "displayTimezone", default: false, tooltip: "When enabled, displays the timezone abbreviation (e.g., PST, UTC) after the time"}},
{option: Option, props: {type: "toggle", title: "Use SObject context on Data Export ", key: "useSObjectContextOnDataImpoltrink", default: true}},
{option: Option, props: {type: "toggle", title: "Enable List View Export", key: "enableListViewExport", default: false, tooltip: "If enabled, Data Export link will be automatically populated with current ListView"}},
{option: MultiCheckboxButtonGroup,
props: {title: "Show buttons",
key: "hideExportButtonsOption",
checkboxes: [
{label: "Delete Records", name: "delete", checked: true},
{label: "Export Query", name: "export-query", checked: false},
{label: "Agentforce", name: "export-agentforce", checked: false}
]}
},
{option: Option, props: {type: "toggle", title: "Hide Object columns by default on Data Export", key: "hideObjectNameColumnsDataExport", default: false}},
{option: Option, props: {type: "toggle", title: "Prevent line wrap in Data Export table cells", key: "preventLineWrapDataExport", default: true, tooltip: "When enabled, prevents text from wrapping in table cells (matches v1.27 behavior)"}},
{option: Option, props: {type: "toggle", title: "Include formula fields from suggestion", key: "includeFormulaFieldsFromExportAutocomplete", default: true}},
{option: Option, props: {type: "toggle", title: "Disable query input autofocus", key: "disableQueryInputAutoFocus"}},
{option: Option, props: {type: "number", title: "Number of queries stored in the history", key: "numberOfQueriesInHistory", default: 100, inputSize: "1"}},
{option: Option, props: {type: "number", title: "Number of saved queries", key: "numberOfQueriesSaved", default: 50, inputSize: "1"}},
{option: Option, props: {type: "textarea", title: "Query Templates", key: "queryTemplates", inputSize: "6", placeholder: "SELECT Id FROM// SELECT Id FROM WHERE//SELECT Id FROM WHERE IN//SELECT Id FROM WHERE LIKE//SELECT Id FROM ORDER BY//SELECT ID FROM MYTEST__c//SELECT ID WHERE"}},
{option: Option, props: {type: "toggle", title: "Enable Query Typo Fix", key: "enableQueryTypoFix", default: false, tooltip: "Enable automation that removes typos from query input"}},
{option: Option, props: {type: "text", title: "Prompt Template Name", key: this.sfHost + "_exportAgentForcePrompt", default: Constants.PromptTemplateSOQL, tooltip: "Developer name of the prompt template to use for SOQL query builder"}},
//This option is created to disable BOM for CSV in case of errors appearing during export, created in v2.0.0, can be deleted in two releases if no issues are reported
{option: Option, props: {type: "toggle", default: true, title: "Use BOM for CSV export", key: "useBomForCsvExport", tooltip: "Add UTF-8 BOM (Byte Order Mark) for Excel compatibility with non-Latin characters."}}
]
},
{
id: "data-import",
tabTitle: "Data Import",
content: [
{option: Option, props: {type: "text", title: "Default batch size", key: "defaultBatchSize", placeholder: "200", inputSize: "1"}},
{option: Option, props: {type: "text", title: "Default thread size", key: "defaultThreadSize", placeholder: "6", inputSize: "1"}},
{option: Option, props: {type: "toggle", title: "Grey Out Skipped Columns in Data Import", key: "greyOutSkippedColumns", tooltip: "Control if skipped columns are greyed out or not in data import"}}
]
},
{
id: "field-creator",
tabTitle: "Field Creator",
content: [
{option: Option,
props: {
type: "select",
title: "Field Naming Convention",
key: "fieldNamingConvention",
default: "pascal",
tooltip: "Controls how API names are auto-generated from field labels. PascalCase: 'My Field' -> 'MyField'. Underscores: 'My Field' -> 'My_Field'",
options: [
{label: "PascalCase", value: "pascal"},
{label: "Underscores", value: "underscore"}
]
}},
{option: Option, props: {type: "toggle", title: "Include managed packages objects", key: "fieldCreatorIncludeManaged", default: false, tooltip: "Show objects from managed packages in the object selector"}}
]
},
{
id: "enable-logs",
tabTitle: "Enable Logs",
content: [
{option: enableLogsOption, props: {key: 1}}
]
},
{
id: "metadata",
tabTitle: "Metadata",
content: [
{option: Option, props: {type: "toggle", title: "Include managed packages metadata", key: "includeManagedMetadata"}},
{option: Option,
props: {type: "select",
title: "Sort metadata components",
key: "sortMetadataBy",
default: "fullName",
options: [
{label: "A-Z", value: "fullName"},
{label: "Last Modified Date DESC", value: "lastModifiedDate"}
]
}
},
{option: Option, props: {type: "toggle", title: "Use legacy version", key: "useLegacyDlMetadata", default: false}},
]
},
{
id: "flow-scanner",
tabTitle: "Flow Scanner",
title: flowScannerTitle,
description: "Configure which Flow Scanner rules are enabled and their settings. Only enabled rules will be used when scanning flows.",
descriptionTooltip: "Flow Scanner rules help identify potential issues, best practices violations, and improvements opportunities in your Salesforce Flows. Each rule can be individually enabled or disabled, and some rules have configurable parameters like thresholds or expressions.",
actionButtons: [
{
type: "brand",
label: "Check All",
title: "Enable all Flow Scanner rules",
method: this.handleCheckAll.bind(this)
},
{
type: "neutral",
label: "Uncheck All",
title: "Disable all Flow Scanner rules",
method: this.handleUncheckAll.bind(this)
},
{
type: "neutral",
label: "Reset to Defaults",
title: "Reset all rules to their default settings",
method: this.handleResetToDefaults.bind(this)
},
{
type: "icon",
icon: "download",
title: "Export Flow Scanner rules configuration to file",
method: this.handleExportRules.bind(this)
},
{
type: "icon",
icon: "upload",
title: "Import Flow Scanner rules configuration from file",
method: this.handleImportRules.bind(this)
}
],
content: [
{option: Option, props: {type: "number", title: "Flow History Size", key: "flowScannerHistorySize", default: 5, tooltip: "Number of old flow versions to keep when purging (in addition to the latest version)."}},
{option: MultiCheckboxButtonGroup,
props: {title: "Show buttons",
key: "hideFlowScannerButtonsOption",
checkboxes: [
{label: "Agentforce", name: "flow-agentforce", checked: false},
{label: "Settings", name: "flow-settings", checked: true}
]}
},
{option: Option, props: {type: "text", title: "Prompt Template Name", key: this.sfHost + "_flowScannerAgentForcePrompt", default: Constants.PromptTemplateFlow, tooltip: "Developer name of the prompt template to use for Flow Scanner"}},
{option: FlowScannerRules, props: {model: this.model}}
]
},
{
id: "logs-viewer",
tabTitle: "Log Viewer",
content: [
{option: Option, props: {type: "text", title: "Prompt Template Name", key: this.sfHost + "_debugLogAgentForcePrompt", default: Constants.PromptTemplateDebugLog, tooltip: "Developer name of the prompt template to use for Debug Log Analysis"}},
{option: Option, props: {type: "toggle", title: "Fetch log bodies for action details", key: "debugLogFetchBodies", default: true, tooltip: "When enabled, fetches log bodies to derive detailed action information. Disable to reduce API calls and improve performance."}},
{option: Option, props: {type: "toggle", title: "Show profile names as suffix in user filter", key: "debugLogShowProfileNames", default: false, tooltip: "When enabled, displays user profile names as a suffix in the format 'Name (ProfileName)' in the user filter picklist and logs table."}},
{option: MultiCheckboxButtonGroup,
props: {title: "Show buttons",
key: "hideDebugLogButtonsOption",
checkboxes: [
{label: "Share Logs", name: "share-logs", checked: true},
{label: "Agentforce", name: "logs-agentforce", checked: false}
]}
},
]
},
{
id: "custom-shortcuts",
tabTitle: "Custom Shortcuts",
content: [
{option: CustomShortcuts, props: {}}
]
},
{
id: "rest-explore",
tabTitle: "REST Explorer",
content: [
{option: MultiCheckboxButtonGroup,
props: {title: "Display response information",
key: "restExploreDisplayOptions",
checkboxes: [
{label: "Response Size", name: "responseSize", checked: true},
{label: "Response Duration", name: "responseDuration", checked: true}
]}
}
]
},
{
id: "show-all",
tabTitle: "Show All",
content: [
{option: Option, props: {type: "toggle", title: "Enable Agentforce Helper for formula fields", key: "showAgentforceHelperInspect", default: true, tooltip: "When enabled, shows the 'Agentforce Helper' link in the field actions menu for calculated/formula fields."}},
{option: Option, props: {type: "text", title: "Formula Helper Prompt Template Name", key: this.sfHost + "_formulaAgentForcePrompt", default: "FormulaHelper", tooltip: "Developer name of the prompt template to use for Formula Field Analysis in the Inspect page"}},
]
}
];
this.onTabSelect = this.onTabSelect.bind(this);
}
handleCheckAll() {
// Implementation to check all Flow Scanner rules
if (this.model.flowScannerRulesRef) {
this.model.flowScannerRulesRef.checkAllRules();
}
}
handleUncheckAll() {
// Implementation to uncheck all Flow Scanner rules
if (this.model.flowScannerRulesRef) {
this.model.flowScannerRulesRef.uncheckAllRules();
}
}
handleResetToDefaults() {
// Implementation to reset Flow Scanner rules to defaults
if (this.model.flowScannerRulesRef) {
this.model.flowScannerRulesRef.resetToDefaults();
}
}
handleExportRules() {
// Export only Flow Scanner related localStorage keys
const flowScannerFilters = [FLOW_SCANNER_RULES_STORAGE_KEY];
// Get reference to App component to call its exportOptions method
if (this.appRef) {
this.appRef.exportOptions(flowScannerFilters);
}
}
handleImportRules() {
if (this.appRef) {
this.appRef.pendingImportFilters = [FLOW_SCANNER_RULES_STORAGE_KEY];
this.appRef.refs.fileInput.click();
}
}
onTabSelect(e) {
e.preventDefault();
const selectedTabId = e.currentTarget.dataset.tabId;
// Update the URL with the selected tab
const url = new URL(window.location);
url.searchParams.set("selectedTab", selectedTabId);
window.history.pushState({}, "", url);
this.setState({selectedTabId});
}
render() {
return h("div", {className: "slds-tabs_default"},
h("ul", {className: "sfir-options-tab-container slds-tabs_default__nav", role: "tablist"},
this.tabs.map((tab) => h(OptionsTab, {key: tab.id, title: tab.tabTitle || tab.title, id: tab.id, selectedTabId: this.state.selectedTabId, onTabSelect: this.onTabSelect}))
),
this.tabs.map((tab) => h(OptionsContainer, {
key: tab.id,
id: tab.id,
title: tab.title,
description: tab.description,
descriptionTooltip: tab.descriptionTooltip,
actionButtons: tab.actionButtons,
content: tab.content,
selectedTabId: this.state.selectedTabId,
model: this.model,
appRef: this.appRef
}))
);
}
}
class OptionsTab extends React.Component {
getClass() {
return "options-tab slds-text-align_center slds-tabs_default__item" + (this.props.selectedTabId === this.props.id ? " slds-is-active" : "");
}
render() {
return h("li", {key: this.props.id, className: this.getClass(), title: this.props.title, "data-tab-id": this.props.id, role: "presentation", onClick: this.props.onTabSelect},
h("a", {className: "slds-tabs_default__link", href: "#", role: "tab", tabIndex: "0", id: "tab-default-" + this.props.id + "__item"},
this.props.title)
);
}
}
class OptionsContainer extends React.Component {
constructor(props) {
super(props);
this.model = props.model;
this.appRef = props.appRef;
}
getClass() {
return (this.props.selectedTabId === this.props.id ? "slds-show" : " slds-hide");
}
renderTabHeader() {
const {title, description, descriptionTooltip, actionButtons} = this.props;
if (!title && !description && !actionButtons) {
return null;
}
return h("div", {className: "slds-p-horizontal_medium slds-p-top_small slds-p-bottom_x-small slds-border_bottom"},
(title || (actionButtons && actionButtons.length > 0)) && h("div", {className: "slds-grid"},
title && h("div", {className: "slds-col"}, h("h2", {className: "slds-text-heading_large slds-text-title_bold"}, title)),
actionButtons && actionButtons.length > 0 && h("div", {className: "slds-col_bump-left"},
h("div", {className: "slds-button-group", role: "group"},
actionButtons.map((button, index) => {
if (button.type === "icon") {
return h("button", {
key: index,
className: `slds-button slds-button_icon slds-button_icon-border-filled${index > 0 ? " slds-m-left_x-small" : ""}`,
onClick: button.method,
title: button.title
}, h("svg", {className: "slds-button__icon"},
h("use", {xlinkHref: `symbols.svg#${button.icon}`})
));
}
return h("button", {
key: index,
className: `slds-button ${button.type === "brand" ? "slds-button_brand" : "slds-button_neutral"}`,
onClick: button.method,
title: button.title || button.label
}, button.label);
})
)
)
),
description && h("div", {className: "slds-m-bottom_xx-small"},
h("div", {className: "slds-text-body_regular slds-text-color_weak"},
h("span", {}, description),
descriptionTooltip && h(Tooltip, {tooltip: descriptionTooltip, idKey: `${this.props.id}_description`})
)
)
);
}
render() {
return h("div", {id: this.props.id, key: this.props.id, className: this.getClass(), role: "tabpanel"},
this.renderTabHeader(),
h("div", {},
this.props.content.map((c, index) =>
h(c.option, {
key: c.props?.key || `option-${index}`,
storageKey: c.props?.key,
...c.props,
model: this.model,
appRef: this.appRef
})
)
)
);
}
}
class ArrowButtonOption extends React.Component {
constructor(props) {
super(props);
this.onChangeArrowOrientation = this.onChangeArrowOrientation.bind(this);
this.onChangeArrowPosition = this.onChangeArrowPosition.bind(this);
this.state = {
arrowButtonOrientation: localStorage.getItem("popupArrowOrientation") ? localStorage.getItem("popupArrowOrientation") : "vertical",
arrowButtonPosition: localStorage.getItem("popupArrowPosition") ? localStorage.getItem("popupArrowPosition") : "20"
};
this.timeout;
}
onChangeArrowOrientation(e) {
let orientation = e.target.value;
this.setState({arrowButtonOrientation: orientation});
localStorage.setItem("popupArrowOrientation", orientation);
window.location.reload();
}
onChangeArrowPosition(e) {
let position = e.target.value;
this.setState({arrowButtonPosition: position});
console.log("[SFInspector] New Arrow Position Value: ", position);
if (this.timeout) {
clearTimeout(this.timeout);
}
this.timeout = setTimeout(() => {
console.log("[SFInspector] Setting Arrow Position: ", position);
localStorage.setItem("popupArrowPosition", position);
window.location.reload();
}, 1000);
}
render() {
return h("div", {className: "slds-grid slds-border_bottom slds-p-horizontal_small slds-p-vertical_x-small"},
h("div", {className: "slds-col slds-size_3-of-12 text-align-middle"},
h("span", {}, "Popup arrow button orientation and position")
),
h("div", {className: "slds-col slds-size_9-of-12 slds-form-element slds-grid slds-grid_align-start slds-grid_vertical-align-center slds-gutters_small"},
h("label", {className: "slds-text-align_right slds-m-left_medium slds-m-right_small"}, "Orientation:"),
h("div", {className: "slds-form-element__control slds-col slds-size_2-of-12"},
h("div", {className: "slds-select_container"},
h("select", {className: "slds-select", defaultValue: this.state.arrowButtonOrientation, name: "arrowPosition", id: "arrowPosition", onChange: this.onChangeArrowOrientation},
h("option", {value: "horizontal"}, "Horizontal"),
h("option", {value: "vertical"}, "Vertical")
))),
h("label", {className: "slds-m-left_medium slds-col slds-size_2-of-12 slds-text-align_right", htmlFor: "arrowPositionSlider"}, "Position (%):"),
h("div", {className: "slds-form-element__control slider-container slds-col slds-size_3-of-12"},
h("div", {className: "slds-slider"},
h("input", {type: "range", id: "arrowPositionSlider", className: "slds-slider__range", value: nullToEmptyString(this.state.arrowButtonPosition), min: "0", max: "100", step: "1", onChange: this.onChangeArrowPosition}),
h("span", {className: "slds-slider__value", "aria-hidden": true}, this.state.arrowButtonPosition)
)
)
)
);
}
}
class APIVersionOption extends React.Component {
constructor(props) {
super(props);
this.onChangeApiVersion = this.onChangeApiVersion.bind(this);
this.onRestoreDefaultApiVersion = this.onRestoreDefaultApiVersion.bind(this);
this.state = {apiVersion: localStorage.getItem("apiVersion") ? localStorage.getItem("apiVersion") : apiVersion};
}
async onChangeApiVersion(e) {
let {sfHost} = this.props.model;
const inputElt = e.target;
const newApiVersion = e.target.value;
if (this.state.apiVersion < newApiVersion) {
const latestApiVersion = await getLatestApiVersionFromOrg(sfHost);
if (latestApiVersion >= newApiVersion) {
localStorage.setItem("apiVersion", newApiVersion + ".0");
this.setState({apiVersion: newApiVersion + ".0"});
} else {
inputElt.setAttribute("max", latestApiVersion);
inputElt.setCustomValidity("Maximum version available: " + latestApiVersion);
inputElt.reportValidity();
}
} else {
localStorage.setItem("apiVersion", newApiVersion + ".0");
this.setState({apiVersion: newApiVersion + ".0"});
}
}
onRestoreDefaultApiVersion(){
localStorage.removeItem("apiVersion");
this.setState({apiVersion: defaultApiVersion});
}
render() {
return h("div", {className: "slds-grid slds-border_bottom slds-p-horizontal_small slds-p-vertical_xx-small"},
h("div", {className: "slds-col slds-size_3-of-12 text-align-middle"},
h("span", {}, "API Version",
h(Tooltip, {tooltip: "Update api version", idKey: "APIVersion"})
),
),
h("div", {className: "slds-col slds-size_10-of-12 slds-form-element"},
h("div", {className: "slds-grid slds-grid_align-start slds-grid_vertical-align-center slds-gutters_small"},
h("div", {className: "slds-col slds-size_1-of-12"},
h("div", {className: "slds-form-element__control"},
h("input", {type: "number", required: true, className: "slds-input", value: nullToEmptyString(this.state.apiVersion.split(".0")[0]), onChange: this.onChangeApiVersion}),
)
),
this.state.apiVersion != defaultApiVersion ? h("div", {className: "slds-col"},
h("button", {className: "slds-button slds-button_brand", onClick: this.onRestoreDefaultApiVersion, title: "Restore Extension's default version"}, "Restore Default")
) : null
)
)
);
}
}
class Option extends React.Component {
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
this.onChangeToggle = this.onChangeToggle.bind(this);
this.onChangeConfig = this.onChangeConfig.bind(this);
this.toggleDescriptionExpanded = this.toggleDescriptionExpanded.bind(this);
this.checkForTruncation = this.checkForTruncation.bind(this);
this.descriptionRef = {current: null};
this.key = props.storageKey;
this.type = props.type;
this.label = props.label;
this.tooltip = props.tooltip;
this.placeholder = props.placeholder;
this.actionButton = props.actionButton;
this.actionButtonVariant = props.actionButtonVariant || "brand"; // Default to "brand" variant (blue button)
this.inputSize = props.inputSize || "3";
this.min = props.min; // Minimum value for number input type (sets HTML min attribute)
this.readOnly = props.readOnly || false;
// Enhanced properties
this.enhancedTitle = props.enhancedTitle;
this.badge = props.badge; // {label: "Beta", type: "beta|custom"}
this.severity = props.severity; // "info|warning|error"
this.description = props.description; // Enhanced description display
// Configurable rule properties
this.isConfigurable = props.isConfigurable;
this.configType = props.configType;
this.configStorageKey = props.configStorageKey;
this.onConfigChange = props.onConfigChange;
this.onToggleChange = props.onToggleChange;
// Handle Flow Scanner rules (no storageKey, managed by parent)
const isFlowScannerRule = !this.key && this.onToggleChange;
let value;
if (isFlowScannerRule) {
// Use checked prop from parent for Flow Scanner rules
value = props.checked;
} else {
// Use localStorage for regular options
value = localStorage.getItem(this.key);
if (props.default !== undefined && value === null) {
value = props.type != "text" ? JSON.stringify(props.default) : props.default;
localStorage.setItem(this.key, value);
}
}
// Initialize config value if configurable (value comes from props)
let configValue = props.configValue || null;
this.state = {
[this.key || "checked"]: isFlowScannerRule ? value
: this.type == "toggle" ? !!JSON.parse(value)
: this.type == "select" ? (value || props.default || props.options?.[0]?.value)
: value,
configValue,
descriptionExpanded: false,
showExpandButton: false
};
this.title = props.title;
}
onChangeToggle(e) {
const enabled = e.target.checked;
const stateKey = this.key || "checked";
this.setState({[stateKey]: enabled});
// Handle Flow Scanner rules vs regular options
if (this.onToggleChange) {
// Flow Scanner rule - call parent callback
this.onToggleChange(enabled);
} else {
// Regular option - use localStorage
localStorage.setItem(this.key, JSON.stringify(enabled));
}
}
onChangeConfig(e) {
const configValue = e.target.value;
this.setState({configValue});
if (this.onConfigChange) {
this.onConfigChange(this.key, configValue);
}
}
onChange(e) {
let inputValue = e.target.value;
this.setState({[this.key]: inputValue});
localStorage.setItem(this.key, inputValue);
}
toggleDescriptionExpanded() {
this.setState(prevState => ({
descriptionExpanded: !prevState.descriptionExpanded
}));
}
isDescriptionTruncated() {
if (!this.descriptionRef.current || !this.description) {
return false;
}
const element = this.descriptionRef.current;
return element.scrollWidth > element.clientWidth;
}
checkForTruncation() {
const isTruncated = this.isDescriptionTruncated();
if (this.state.showExpandButton !== isTruncated) {
this.setState({showExpandButton: isTruncated});
}
}
renderInputControl(id, isEnhanced = false) {
const isTextOrNumber = this.type == "text" || this.type == "number";
const isTextArea = this.type == "textarea";
const isSelect = this.type == "select";
const isToggle = this.type == "toggle";
if (isToggle) {
return isEnhanced ? null : (
h("div", {dir: "ltr", className: "slds-form-element__control slds-col slds-size_1-of-12 slds-p-right_medium"},
h("label", {className: "slds-checkbox_toggle slds-grid"},
h("input", {type: "checkbox", required: true, id, "aria-describedby": id, className: "slds-input", checked: this.state[this.key || "checked"], onChange: this.onChangeToggle}),
h("span", {id, className: "slds-checkbox_faux_container center-label"},
h("span", {className: "slds-checkbox_faux"}),
h("span", {className: "slds-checkbox_on"}, "Enabled"),
h("span", {className: "slds-checkbox_off"}, "Disabled"),
)
)
)
);
}
const inputElement = isTextOrNumber ? h("input", {
type: this.type,
id,
className: isEnhanced ? "slds-input enhanced-option-input" : "slds-input",
placeholder: this.placeholder,
value: nullToEmptyString(this.state[this.key]),
onChange: this.onChange,
readOnly: this.readOnly,
...(this.type === "number" && this.min !== undefined ? {min: this.min} : {})
})
: isTextArea ? h("textarea", {
id,
className: isEnhanced ? "slds-input enhanced-option-input" : "slds-input",
placeholder: this.placeholder,
value: nullToEmptyString(this.state[this.key]),
onChange: this.onChange,
readOnly: this.readOnly
})
: isSelect ? h("select", {
className: isEnhanced ? "slds-select enhanced-option-input" : "slds-select slds-m-right_small",
value: this.state[this.key],
onChange: this.onChange
},
this.props.options.map(opt =>
h("option", {key: opt.value, value: opt.value}, opt.label)
))
: null;
if (isEnhanced) {
return inputElement;
} else {
// Standard layout wrapping - returns just the input wrapper
return h("div", {className: "slds-form-element__control"},
inputElement
);
}
}
renderConfigInput() {
if (!this.isConfigurable || !this.configType) {
return null;
}
const configId = this.configStorageKey || `${this.key}_config`;
const inputType = this.configType === "threshold" ? "number" : "text";
const placeholder = this.configType === "threshold" ? "Enter threshold value"
: this.configType === "expression" ? "Enter regex pattern"
: "Enter configuration value";
return h("input", {
type: inputType,
id: configId,
className: "slds-input enhanced-option-input",
placeholder,
value: this.state.configValue || "",
onChange: this.onChangeConfig,
title: `Configure ${this.enhancedTitle || this.title} (${this.configType})`
});
}
render() {
const id = this.key;
const isToggle = this.type == "toggle";
const isButton = this.type == "button";
const isEnhanced = this.enhancedTitle || this.badge || this.severity || this.description;
if (isEnhanced) {
// Enhanced layout
return h("div", {className: "enhanced-option-row"},
// Main content area
h("div", {className: "enhanced-option-content"},
// Enhanced title with badge
h("div", {className: "enhanced-option-title"},
h("h4", {className: "enhanced-option-title-text"}, this.enhancedTitle || this.title),
this.badge && h("span", {
className: `${this.badge.type || "beta"}-badge`
}, this.badge.label)
),
// Description on the same line with expand functionality
this.description && h("div", {className: "enhanced-option-description-container"},
h("span", {
className: `enhanced-option-description ${this.state.descriptionExpanded ? "expanded" : ""}`,
ref: (el) => {
this.descriptionRef.current = el;
if (el) {
setTimeout(() => this.checkForTruncation(), 0);
}
}
}, this.description),
// Expand icon (only show when text is truncated)
this.state.showExpandButton && h("button", {
className: "enhanced-option-expand-btn",
onClick: this.toggleDescriptionExpanded,
title: this.state.descriptionExpanded ? "Collapse description" : "Expand description"
},
h("svg", {className: `expand-icon ${this.state.descriptionExpanded ? "expanded" : ""}`, viewBox: "0 0 24 24", width: "16", height: "16"},
h("path", {d: "M7 10l5 5 5-5z"})
)
)
)
),
// Controls on the right
h("div", {className: "enhanced-option-controls"},
// Configuration input (for configurable rules)
this.renderConfigInput(),
// Severity selector
this.severity && h("select", {
className: `severity-select severity-${this.severity}`,
value: this.severity,
onChange: (e) => {
const newSeverity = e.target.value;
this.severity = newSeverity;
this.setState({}); // Force re-render
if (this.props.onSeverityChange) {
this.props.onSeverityChange(this.key, newSeverity);
}
}
},
h("option", {value: "info"}, "Info"),
h("option", {value: "warning"}, "Warning"),
h("option", {value: "error"}, "Error")
),
// Toggle control for all enhanced options (positioned at the end)
isToggle && h("div", {className: "slds-form-element__control"},
h("label", {className: "slds-checkbox_toggle slds-grid"},
h("input", {type: "checkbox", required: true, id, "aria-describedby": id, className: "slds-input", checked: this.state[this.key || "checked"], onChange: this.onChangeToggle}),
h("span", {id, className: "slds-checkbox_faux_container center-label"},
h("span", {className: "slds-checkbox_faux"}),
h("span", {className: "slds-checkbox_on"}, "Enabled"),
h("span", {className: "slds-checkbox_off"}, "Disabled"),
)
)
),
// Input controls for non-toggle and non-button types
!isToggle && !isButton && this.renderInputControl(id, true)
)
);
} else {
// Standard layout with responsive grid
return h("div", {className: "slds-grid slds-border_bottom slds-p-horizontal_small slds-p-vertical_xx-small"},
h("div", {className: "slds-col slds-size_3-of-12 text-align-middle"},
h("span", {}, this.title,
h(Tooltip, {tooltip: this.tooltip, idKey: this.key || `option_${this.title || "unnamed"}`})
)
),
h("div", {className: "slds-col slds-size_9-of-12"},
h("div", {className: "slds-grid slds-grid_vertical-align-center slds-gutters_small"},
// Input field container with configurable size (not for toggle or button types)
!isToggle && !isButton && h("div", {className: "slds-col slds-size_" + this.inputSize + "-of-12"},
this.renderInputControl(id, false)
),
// Action button (if present)
// appRef is passed to allow actionButton handlers to show toast notifications via appRef.setState()
this.actionButton && h("div", {className: "slds-col"},
h("button", {
className: `slds-button slds-button_${this.actionButtonVariant}`,
onClick: (e) => this.actionButton.onClick(e, this.props.model, this.props.appRef),
title: this.actionButton.title || "Action"
}, this.actionButton.label || "Action")
),
// Toggle control aligned to the right
isToggle && h("div", {className: "slds-col slds-grid slds-grid_align-end"},