@salesforcedevs/dw-components 1.3.148-canary.0 → 1.3.148-canary.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dw-components",
3
- "version": "1.3.148-canary.0",
3
+ "version": "1.3.148-canary.1",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -52,6 +52,7 @@
52
52
  <dx-button
53
53
  class="primary-action"
54
54
  disabled={isJ2sFormInvalid}
55
+ href={stepDatum.primaryAction.link}
55
56
  icon-sprite={stepDatum.primaryAction.iconSprite}
56
57
  icon-symbol={stepDatum.primaryAction.iconSymbol}
57
58
  loading={isLoading}
@@ -4,6 +4,12 @@ import { getListWithUuids } from "dxUtils/list";
4
4
  import { toJson } from "dxUtils/normalizers";
5
5
  import Button from "dx/button";
6
6
 
7
+ function isNoAnimationCookieSet() {
8
+ return document.cookie
9
+ .split(";")
10
+ .some((ck) => ck.trim() === "no_j2s_animation=true");
11
+ }
12
+
7
13
  export type StepDatum = {
8
14
  bodyHtml?: string;
9
15
  formData?: {
@@ -25,10 +31,11 @@ export type StepDatum = {
25
31
  textColor?: string;
26
32
  };
27
33
  primaryAction: {
28
- text: string;
29
- variant?: string;
30
34
  iconSprite?: string;
31
35
  iconSymbol?: string;
36
+ link?: string;
37
+ text: string;
38
+ variant?: string;
32
39
  };
33
40
  secondaryActionHtml?: string;
34
41
  showStepNumber?: boolean;
@@ -36,6 +43,7 @@ export type StepDatum = {
36
43
  };
37
44
 
38
45
  export default class J2sCardSequence extends LightningElement {
46
+ _didRenderStaticInnerHtml = false;
39
47
  _isDrmLoading = false;
40
48
  _isJ2sFormInvalid = false;
41
49
  _isTbidLoading = false;
@@ -50,9 +58,9 @@ export default class J2sCardSequence extends LightningElement {
50
58
  return this._stepsData;
51
59
  }
52
60
  set stepsData(value) {
61
+ // normalize incoming value with uuid keys and non-required props (for cleaner HTML template), etc.
53
62
  this._stepsData = getListWithUuids<StepDatum>(toJson(value)).map(
54
63
  (stepDatum) => {
55
- // small bit of normalization for cleaner HTML templates with non-required props, etc.
56
64
  const normalizedStepDatum = {
57
65
  ...stepDatum,
58
66
  headerData: stepDatum.headerData || {},
@@ -150,6 +158,10 @@ export default class J2sCardSequence extends LightningElement {
150
158
  // This has to be defined here since it depends on a variable that depends on sessionStorage.
151
159
  this.currentSequenceStep = this.initialStepIndex;
152
160
  this.resetCustomButtonColors();
161
+ if (isNoAnimationCookieSet()) {
162
+ /* eslint-disable-next-line @lwc/lwc/no-api-reassignments */
163
+ this.animateTransitions = false;
164
+ }
153
165
  }
154
166
 
155
167
  renderedCallback() {
@@ -157,21 +169,9 @@ export default class J2sCardSequence extends LightningElement {
157
169
  return;
158
170
  }
159
171
 
160
- const { bodyHtml, secondaryActionHtml } =
161
- this.stepsData[this.currentSequenceStep];
162
- const bodyMarkupContainer =
163
- this.template.querySelectorAll("span.body-markup")[
164
- this.currentSequenceStep
165
- ];
166
- const secondaryActionMarkupContainer = this.template.querySelectorAll(
167
- "span.secondary-action-markup"
168
- )[this.currentSequenceStep];
169
- if (bodyMarkupContainer) {
170
- bodyMarkupContainer.innerHTML = bodyHtml || "";
171
- }
172
- if (secondaryActionMarkupContainer) {
173
- secondaryActionMarkupContainer.innerHTML =
174
- secondaryActionHtml || "";
172
+ if (!this._didRenderStaticInnerHtml) {
173
+ this.updateStaticInnerHtml();
174
+ this._didRenderStaticInnerHtml = true;
175
175
  }
176
176
  }
177
177
 
@@ -182,6 +182,7 @@ export default class J2sCardSequence extends LightningElement {
182
182
  if (!this.isLoggedIn) {
183
183
  evt.preventDefault();
184
184
  this.initialStepIndex = 1;
185
+ this._isTbidLoading = true;
185
186
  // @ts-ignore: call out to the tbid-controller on DSC
186
187
  window.__startTbidLogin();
187
188
  }
@@ -206,8 +207,6 @@ export default class J2sCardSequence extends LightningElement {
206
207
  this.handleGetStarted(evt);
207
208
  } else if (this.currentSequenceStep === 2) {
208
209
  // TODO: send data to DRM
209
- } else if (this.currentSequenceStep === 3) {
210
- // TODO: Join Slack
211
210
  }
212
211
  }
213
212
 
@@ -237,6 +236,39 @@ export default class J2sCardSequence extends LightningElement {
237
236
  );
238
237
  }
239
238
 
239
+ private jumpToStepOne() {
240
+ this.initialStepIndex = 0; // update sessionStorage value
241
+ (
242
+ this.template.querySelector(
243
+ "dx-step-sequence"
244
+ ) as unknown as StepSequence
245
+ )?.jumpToStep(0);
246
+ }
247
+
248
+ // HTML is received via config from DSC and should be static after initial render.
249
+ private updateStaticInnerHtml() {
250
+ const bodyMarkupContainers =
251
+ this.template.querySelectorAll("span.body-markup");
252
+ const secondaryActionMarkupContainers = this.template.querySelectorAll(
253
+ "span.secondary-action-markup"
254
+ );
255
+
256
+ this.stepsData.forEach((step, stepIndex) => {
257
+ const { bodyHtml, secondaryActionHtml } = step;
258
+ const bodyMarkupContainer = bodyMarkupContainers[stepIndex];
259
+ const secondaryActionMarkupContainer =
260
+ secondaryActionMarkupContainers[stepIndex];
261
+
262
+ if (bodyMarkupContainer) {
263
+ bodyMarkupContainer.innerHTML = bodyHtml || "";
264
+ }
265
+ if (secondaryActionMarkupContainer) {
266
+ secondaryActionMarkupContainer.innerHTML =
267
+ secondaryActionHtml || "";
268
+ }
269
+ });
270
+ }
271
+
240
272
  private async getCountryList() {
241
273
  this._isDrmLoading = true;
242
274
 
@@ -252,6 +284,11 @@ export default class J2sCardSequence extends LightningElement {
252
284
  this.countries = JSON.stringify(data);
253
285
  } catch (error) {
254
286
  console.error(error);
287
+ if (this.initialStepIndex > 0) {
288
+ // Page loaded on a step higher than the first, but we can't get data for the form;
289
+ // send user back to the start for now.
290
+ this.jumpToStepOne();
291
+ }
255
292
  }
256
293
 
257
294
  this._isDrmLoading = false;
@@ -272,12 +309,7 @@ export default class J2sCardSequence extends LightningElement {
272
309
  if (!this.tbidUserInfo && this.initialStepIndex > 0) {
273
310
  // login failed and the user was previously beyond the start step; need to send them
274
311
  // back to the start:
275
- this.initialStepIndex = 0;
276
- (
277
- this.template.querySelector(
278
- "dx-step-sequence"
279
- ) as unknown as StepSequence
280
- )?.jumpToStep(0);
312
+ this.jumpToStepOne();
281
313
  }
282
314
 
283
315
  this._isTbidLoading = false;
@@ -141,7 +141,7 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
141
141
  if (this.state.learnMore) {
142
142
  this.updateInnerHtml(
143
143
  "span.legal-terms-learn-more",
144
- this.state.learnMore
144
+ `&nbsp;${this.state.learnMore}`
145
145
  );
146
146
  } else {
147
147
  this.updateInnerHtml("span.legal-terms-learn-more", "");
@@ -185,7 +185,7 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
185
185
  }
186
186
 
187
187
  handleRequiredFieldUpdate() {
188
- const isFormNowValid = this.checkValidity(this.state.country);
188
+ const isFormNowValid = this.checkValidity();
189
189
  if (this.state.isFormValid !== isFormNowValid) {
190
190
  this.setState({
191
191
  isFormValid: isFormNowValid
@@ -196,14 +196,22 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
196
196
  handleCountryChange({ detail }: CustomEvent) {
197
197
  const { value } = detail;
198
198
  const countryData = this._countriesLookup[value];
199
+
199
200
  this.setState({
200
201
  country: value,
201
- isFormValid: this.checkValidity(value),
202
202
  learnMore: countryData.learnMore,
203
203
  legalText: countryData.legalText,
204
204
  marketingText: countryData.marketingText,
205
205
  showLegalCheckbox: countryData.showLegalCheckbox
206
206
  });
207
+
208
+ // Because updating the country can update the required fields, we need to re-set form
209
+ // validity after render
210
+ requestAnimationFrame(() =>
211
+ this.setState({
212
+ isFormValid: this.checkValidity()
213
+ })
214
+ );
207
215
  }
208
216
 
209
217
  handleLearnMore() {
@@ -212,9 +220,9 @@ export default class J2sForm extends LightningElementWithState<J2sFormState> {
212
220
  ?.classList.toggle("hidden");
213
221
  }
214
222
 
215
- private checkValidity(country: string) {
223
+ private checkValidity() {
216
224
  return (
217
- this.isParticipatingCountry(country) &&
225
+ this.isParticipatingCountry(this.state.country) &&
218
226
  this.requiredFormFields.every(
219
227
  (requiredFormField) =>
220
228
  // @ts-ignore