@topconsultnpm/sdkui-react 6.20.0-dev2.34 → 6.20.0-dev2.36
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.
|
@@ -26,9 +26,6 @@ export declare class UserSettings {
|
|
|
26
26
|
static LoadSettings(userID: number | undefined, archiveID: string | undefined): UserSettings;
|
|
27
27
|
/** Save settings to local storage or other sources */
|
|
28
28
|
static SaveSettings(settings: UserSettings): void;
|
|
29
|
-
/** Save default settings for properties that don't exist in localStorage yet.*/
|
|
30
|
-
static SaveDefaultSettings(//nosonar
|
|
31
|
-
userID: number | undefined, archiveID: string | undefined, defaultProperties?: string[]): void;
|
|
32
29
|
}
|
|
33
30
|
export declare class DataGridSettings {
|
|
34
31
|
showColumnLines: number;
|
|
@@ -35,15 +35,6 @@ export class UserSettings {
|
|
|
35
35
|
// Merge loaded settings with default settings
|
|
36
36
|
const defaultSettings = new UserSettings(true);
|
|
37
37
|
const settings = Object.assign(defaultSettings, loadedSettings);
|
|
38
|
-
// Ensure devSettings is properly initialized
|
|
39
|
-
if (settings.devSettings) {
|
|
40
|
-
// Ensure all devSettings properties exist
|
|
41
|
-
const defaultDevSettings = new DevSettings();
|
|
42
|
-
settings.devSettings = Object.assign(defaultDevSettings, settings.devSettings);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
settings.devSettings = new DevSettings();
|
|
46
|
-
}
|
|
47
38
|
// Ensure userID and archiveID are set
|
|
48
39
|
settings.userID = userID;
|
|
49
40
|
settings.archiveID = archiveID;
|
|
@@ -61,73 +52,13 @@ export class UserSettings {
|
|
|
61
52
|
if (!settings.userID || !settings.archiveID) {
|
|
62
53
|
throw new Error('User ID and Archive ID are required to save settings.');
|
|
63
54
|
}
|
|
64
|
-
// Properties that should always be saved, even if they match defaults
|
|
65
|
-
const alwaysSaveProperties = new Set(['userID', 'archiveID', 'devSettings']);
|
|
66
55
|
const defaultSettings = new UserSettings(true);
|
|
67
56
|
const filteredSettings = Object.fromEntries(Object.entries(settings).filter(([key, value]) => {
|
|
68
|
-
// Always save certain properties
|
|
69
|
-
if (alwaysSaveProperties.has(key)) {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
// For other properties, only save if different from default
|
|
73
57
|
const defaultValue = defaultSettings[key];
|
|
74
58
|
return JSON.stringify(value) !== JSON.stringify(defaultValue);
|
|
75
59
|
}));
|
|
76
60
|
LocalStorageService.setItem(`userSettings_${settings.archiveID}_${settings.userID}`, JSON.stringify(filteredSettings));
|
|
77
61
|
}
|
|
78
|
-
/** Save default settings for properties that don't exist in localStorage yet.*/
|
|
79
|
-
static SaveDefaultSettings(//nosonar
|
|
80
|
-
userID, archiveID, defaultProperties = ['devSettings.betaFeatures']) {
|
|
81
|
-
if (!userID || !archiveID) {
|
|
82
|
-
throw new Error('User ID and Archive ID are required to save default settings.');
|
|
83
|
-
}
|
|
84
|
-
// Load existing settings from local storage
|
|
85
|
-
const loadedSettings = LocalStorageService.getItem(`userSettings_${archiveID}_${userID}`);
|
|
86
|
-
// If no settings exist yet, save all defaults
|
|
87
|
-
if (!loadedSettings) {
|
|
88
|
-
const defaultSettings = new UserSettings(true);
|
|
89
|
-
const settingsToSave = {
|
|
90
|
-
userID: userID,
|
|
91
|
-
archiveID: archiveID,
|
|
92
|
-
devSettings: defaultSettings.devSettings
|
|
93
|
-
};
|
|
94
|
-
LocalStorageService.setItem(`userSettings_${archiveID}_${userID}`, JSON.stringify(settingsToSave));
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
// Check if any of the default properties are missing
|
|
98
|
-
let needsUpdate = false;
|
|
99
|
-
const defaultSettings = new UserSettings(true);
|
|
100
|
-
for (const propertyPath of defaultProperties) {
|
|
101
|
-
const pathParts = propertyPath.split('.');
|
|
102
|
-
let current = loadedSettings;
|
|
103
|
-
let exists = true;
|
|
104
|
-
// Check if the property exists in loaded settings
|
|
105
|
-
for (const part of pathParts) {
|
|
106
|
-
if (current && typeof current === 'object' && part in current) {
|
|
107
|
-
current = current[part];
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
exists = false;
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// If property doesn't exist, we need to add it
|
|
115
|
-
if (!exists) {
|
|
116
|
-
needsUpdate = true;
|
|
117
|
-
// Add the missing property from defaults
|
|
118
|
-
const [topLevel] = pathParts;
|
|
119
|
-
if (!loadedSettings[topLevel]) {
|
|
120
|
-
loadedSettings[topLevel] = defaultSettings[topLevel];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// Save updated settings if needed
|
|
125
|
-
if (needsUpdate) {
|
|
126
|
-
loadedSettings.userID = userID;
|
|
127
|
-
loadedSettings.archiveID = archiveID;
|
|
128
|
-
LocalStorageService.setItem(`userSettings_${archiveID}_${userID}`, JSON.stringify(loadedSettings));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
62
|
}
|
|
132
63
|
export class DataGridSettings {
|
|
133
64
|
constructor() {
|
package/lib/helper/helpers.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ declare const getColor: (color: ColorsType) => string;
|
|
|
15
15
|
* @returns {string} Un UUID in formato stringa.
|
|
16
16
|
*/
|
|
17
17
|
export declare const generateUUID: () => string;
|
|
18
|
+
/** Checks if beta features are enabled for a specific user and archive.*/
|
|
19
|
+
export declare const isBetaFeatureEnabled: (archiveId: string | undefined, userId: number | undefined) => boolean;
|
|
18
20
|
declare const makeID: (length: number) => string;
|
|
19
21
|
export declare const truncateText: (text: string, maxLength: number) => string;
|
|
20
22
|
declare function genUniqueId(): string;
|
package/lib/helper/helpers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Colors } from "../utils/theme";
|
|
3
3
|
import { ButtonNames, DeviceType, TMExceptionBoxManager, TMMessageBoxManager, TMSpinner } from "../components";
|
|
4
|
-
import { AccessLevels, MetadataDataDomains, MetadataDataTypes, MetadataDescriptor, MetadataFormatDescriptor, MetadataFormats, MetadataPermission, SDK_Globals, SetGlobalsInfoAsync, SystemMIDs, SystemMIDsAsNumber, Task_States, TopMediaServer, WorkItemMetadataNames } from "@topconsultnpm/sdk-ts";
|
|
4
|
+
import { AccessLevels, LocalStorageService, MetadataDataDomains, MetadataDataTypes, MetadataDescriptor, MetadataFormatDescriptor, MetadataFormats, MetadataPermission, SDK_Globals, SetGlobalsInfoAsync, SystemMIDs, SystemMIDsAsNumber, Task_States, TopMediaServer, WorkItemMetadataNames } from "@topconsultnpm/sdk-ts";
|
|
5
5
|
import { Buffer } from 'buffer';
|
|
6
6
|
import { buildTypes, FileExtensionHandler, FormModes, moduleTypes } from "../ts";
|
|
7
7
|
import { SDKUI_Localizator } from "./SDKUI_Localizator";
|
|
@@ -93,6 +93,25 @@ const getColor = (color) => {
|
|
|
93
93
|
export const generateUUID = () => {
|
|
94
94
|
return crypto.randomUUID();
|
|
95
95
|
};
|
|
96
|
+
/** Checks if beta features are enabled for a specific user and archive.*/
|
|
97
|
+
export const isBetaFeatureEnabled = (archiveId, userId) => {
|
|
98
|
+
if (!archiveId || !userId)
|
|
99
|
+
return false;
|
|
100
|
+
const localStorageKey = `FEATURES_${archiveId}_${userId}`;
|
|
101
|
+
let raw = LocalStorageService.getItem(localStorageKey);
|
|
102
|
+
if (typeof raw === 'string') {
|
|
103
|
+
try {
|
|
104
|
+
raw = JSON.parse(raw);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
raw = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (raw && typeof raw === 'object' && 'devSettings' in raw) {
|
|
111
|
+
return raw.devSettings.betaFeatures === 1;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
};
|
|
96
115
|
const makeID = (length) => {
|
|
97
116
|
let result = '';
|
|
98
117
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|