Skip to content

Commit 08d52ca

Browse files
Merge subscriptions mechanism (#30979)
1 parent e2e05b9 commit 08d52ca

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

packages/devextreme/js/__internal/core/license/trial_panel.client.ts

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class DxLicense extends SafeHTMLElement {
111111

112112
private readonly _buttonStyles: string;
113113

114+
private _subscriptionsSpan?: HTMLSpanElement;
115+
114116
constructor() {
115117
super();
116118

@@ -133,6 +135,48 @@ class DxLicense extends SafeHTMLElement {
133135
);
134136
}
135137

138+
private _getSubscriptionsArray(subscriptions: string | null): string[] {
139+
return subscriptions?.split(',').map((x) => x.trim()) ?? [];
140+
}
141+
142+
public updateSubscriptions(newSubscriptions: string): void {
143+
if (!this._subscriptionsSpan || !newSubscriptions) return;
144+
const currentSubscriptionsStr = this.getAttribute(attributeNames.subscriptions);
145+
const currentSubscriptions = this._getSubscriptionsArray(currentSubscriptionsStr);
146+
if (!currentSubscriptions.length) {
147+
this._updateSubscriptionsText(newSubscriptions);
148+
return;
149+
}
150+
151+
const newSubscriptionsArray = this._getSubscriptionsArray(newSubscriptions);
152+
const mergedSubscriptions: string[] = [];
153+
154+
newSubscriptionsArray.forEach((subscription) => {
155+
if (currentSubscriptions.some((x) => x === subscription)) {
156+
mergedSubscriptions.push(subscription);
157+
}
158+
});
159+
160+
this._updateSubscriptionsText(
161+
mergedSubscriptions.length !== 0
162+
? mergedSubscriptions.join(', ')
163+
: [...currentSubscriptions, ...newSubscriptionsArray].join(', '),
164+
);
165+
}
166+
167+
private _updateSubscriptionsText(subscriptions: string | null): void {
168+
if (subscriptions && this._subscriptionsSpan) {
169+
this.setAttribute(attributeNames.subscriptions, subscriptions);
170+
this._subscriptionsSpan.innerText = ` Included in Subscriptions: ${subscriptions}`;
171+
}
172+
}
173+
174+
private _createSubscriptionsSpan(): HTMLSpanElement {
175+
this._subscriptionsSpan = this._createSpan('');
176+
this._updateSubscriptionsText(this.getAttribute(attributeNames.subscriptions));
177+
return this._subscriptionsSpan;
178+
}
179+
136180
private _createSpan(text: string): HTMLSpanElement {
137181
const span = document.createElement('span');
138182
span.innerText = text;
@@ -186,21 +230,15 @@ class DxLicense extends SafeHTMLElement {
186230
private _createContentContainer(): HTMLElement {
187231
const contentContainer = document.createElement('div');
188232
contentContainer.style.cssText = this._contentStyles;
189-
const subscriptions = this.getAttribute(attributeNames.subscriptions);
190233
contentContainer.append(
191234
this._createSpan('For evaluation purposes only. Redistribution prohibited. Please '),
192235
this._createLink('register', this.getAttribute(attributeNames.licensingDoc) as string),
193236
this._createSpan(' an existing license or '),
194237
this._createLink('purchase a new license', this.getAttribute(attributeNames.buyNow) as string),
195238
this._createSpan(` to continue use of DevExpress product libraries (v${this.getAttribute(attributeNames.version)}).`),
239+
this._createSubscriptionsSpan(),
196240
);
197241

198-
if (subscriptions) {
199-
contentContainer.append(
200-
this._createSpan(` Included in Subscriptions: ${subscriptions}.`),
201-
);
202-
}
203-
204242
return contentContainer;
205243
}
206244

@@ -261,7 +299,8 @@ class DxLicenseTrigger extends SafeHTMLElement {
261299
});
262300

263301
const licensePanel = document.getElementsByTagName(componentNames.panel);
264-
if (!licensePanel.length && !DxLicense.closed) {
302+
if (DxLicense.closed) return;
303+
if (!licensePanel.length) {
265304
const license = document.createElement(componentNames.panel);
266305

267306
Object.values(attributeNames).forEach((attrName) => {
@@ -274,6 +313,9 @@ class DxLicenseTrigger extends SafeHTMLElement {
274313
license.setAttribute(DATA_PERMANENT_ATTRIBUTE, '');
275314

276315
document.body.prepend(license);
316+
} else {
317+
const subscriptions = this.getAttribute(attributeNames.subscriptions) as string;
318+
(licensePanel[0] as DxLicense).updateSubscriptions(subscriptions);
277319
}
278320
}
279321
}

0 commit comments

Comments
 (0)