Skip to content

Commit 12deeca

Browse files
committed
feat: new conditional directives and notifyRecordUpdateAvailable
1 parent d0cb651 commit 12deeca

File tree

8 files changed

+130
-35
lines changed

8 files changed

+130
-35
lines changed

src/main/default/lwc/apiEndpoint/apiEndpoint.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{nameWithStatus}
44
</div>
55

6-
<c-formatted-error if:true={error} error={error}></c-formatted-error>
6+
<c-formatted-error lwc:if={error} error={error}></c-formatted-error>
77

88
<div class="slds-grid slds-gutters">
99
<div class="slds-col slds-size_1-of-2">
@@ -42,13 +42,13 @@
4242

4343
<!-- Request spinner -->
4444
<lightning-spinner
45-
if:true={isLoading}
45+
lwc:if={isLoading}
4646
variant="brand"
4747
alternative-text="Waiting for UI API response"
4848
></lightning-spinner>
4949

5050
<!-- Response -->
51-
<div if:true={responseData}>
51+
<div lwc:if={responseData}>
5252
<div class="slds-text-title_caps slds-m-bottom_small">Response</div>
5353
<div class="slds-p-horizontal_small">
5454
<c-json-formatter value={responseData}></c-json-formatter>

src/main/default/lwc/jsonFormatter/jsonFormatter.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="slds-grid slds-gutters">
33
<div class="slds-col slds-size_1-of-2">
4-
<template if:true={gridData}>
4+
<template lwc:if={gridData}>
55
<div class="slds-text-title slds-m-bottom_small">Formatted</div>
66
<div class="slds-theme_shade">
77
<lightning-tree-grid
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div class="slds-form">
3+
<lightning-input
4+
value={recordIds}
5+
onchange={handleRecordIdsChange}
6+
type="text"
7+
label="Record Ids"
8+
min-length="15"
9+
required
10+
field-level-help="A comma-delimited list of of record IDs."
11+
></lightning-input>
12+
</div>
13+
<div class="slds-m-top_small slds-text-align_right">
14+
<lightning-button
15+
variant="brand"
16+
label="Send"
17+
onclick={handleSendRequest}
18+
disabled={isCallApiButtonDisabled}
19+
></lightning-button>
20+
</div>
21+
</template>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { LightningElement } from 'lwc';
2+
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
3+
import { notifyRecordUpdateAvailable } from 'lightning/uiRecordApi';
4+
5+
export default class NotifyRecordUpdateAvailable extends LightningElement {
6+
recordIds = '0010u000005dp2dAAA';
7+
8+
handleRecordIdsChange(event) {
9+
this.recordIds = event.target.value;
10+
}
11+
12+
async handleSendRequest() {
13+
const recordIds = this.recordIds?.replace(' ', '').split(',');
14+
if (!recordIds) {
15+
this.dispatchEvent(
16+
new ShowToastEvent({
17+
title: 'Error',
18+
message:
19+
'Could not build a list of record IDs based on your input.',
20+
variant: 'error'
21+
})
22+
);
23+
return;
24+
}
25+
26+
this.dispatchEvent(new CustomEvent('request', { bubbles: true }));
27+
28+
try {
29+
await notifyRecordUpdateAvailable(recordIds);
30+
this.dispatchEvent(
31+
new CustomEvent('response', {
32+
detail: undefined,
33+
bubbles: true
34+
})
35+
);
36+
this.dispatchEvent(
37+
new ShowToastEvent({
38+
title: 'Success',
39+
message: 'Record update notified.',
40+
variant: 'success'
41+
})
42+
);
43+
} catch (error) {
44+
this.dispatchEvent(
45+
new CustomEvent('response', {
46+
detail: { error },
47+
bubbles: true
48+
})
49+
);
50+
}
51+
}
52+
53+
get isCallApiButtonDisabled() {
54+
return !this.recordIds;
55+
}
56+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>57.0</apiVersion>
4+
<isExposed>false</isExposed>
5+
</LightningComponentBundle>

src/main/default/lwc/uiApiPlayground/api-definitions.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ const API_DEFINITIONS = [
131131
},
132132
{
133133
name: 'getRecordNotifyChange',
134+
status: 'Deprecated',
134135
description:
135-
'Fetch record updates for the specified record IDs and refresh the Lightning Data Service cache, providing your wires with the latest record data. Call this function to notify Lightning Data Service that a record has changed outside its mechanisms, such as via imperative Apex or Visualforce, or by calling User Interface API via a third-party framework.',
136+
'[DEPRECATED] Fetch record updates for the specified record IDs and refresh the Lightning Data Service cache, providing your wires with the latest record data. Call this function to notify Lightning Data Service that a record has changed outside its mechanisms, such as via imperative Apex or Visualforce, or by calling User Interface API via a third-party framework. We recommend using notifyRecordUpdateAvailable(recordIds) instead.',
136137
docUrlKey: 'lwc.reference_get_record_notify'
137138
},
138139
{
@@ -142,6 +143,12 @@ const API_DEFINITIONS = [
142143
'[DEPRECATED] Use this wire adapter to get layout information, metadata, and data to build UI for one or more records.',
143144
docUrlKey: 'lwc.reference_wire_adapters_record'
144145
},
146+
{
147+
name: 'notifyRecordUpdateAvailable',
148+
description:
149+
'Call this function to notify Lightning Data Service that a record has changed outside its mechanisms, such as via imperative Apex or by calling User Interface API via a third-party framework.',
150+
docUrlKey: 'lwc.reference_notify_record_update'
151+
},
145152
{
146153
name: 'updateRecord',
147154
description:

src/main/default/lwc/uiApiPlayground/uiApiPlayground.html

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,83 +25,86 @@
2525
</lightning-button-group>
2626

2727
<!-- Currently selected endpoint -->
28-
<template if:true={selectedEndpoint}>
28+
<template lwc:if={selectedEndpoint}>
2929
<c-api-endpoint
3030
name={selectedEndpoint.fullname}
3131
status={selectedEndpoint.status}
3232
description={selectedEndpoint.description}
3333
doc-url-key={selectedEndpoint.docUrlKey}
3434
>
35-
<c-get-list-ui if:true={isGetListUi}></c-get-list-ui>
35+
<c-get-list-ui lwc:if={isGetListUi}></c-get-list-ui>
3636
<c-get-list-info-by-name
37-
if:true={isGetListInfoByName}
37+
lwc:if={isGetListInfoByName}
3838
></c-get-list-info-by-name>
3939
<c-get-list-infos-by-name
40-
if:true={isGetListInfosByName}
40+
lwc:if={isGetListInfosByName}
4141
></c-get-list-infos-by-name>
4242
<c-get-object-info
43-
if:true={isGetObjectInfo}
43+
lwc:if={isGetObjectInfo}
4444
></c-get-object-info>
4545
<c-get-object-infos
46-
if:true={isGetObjectInfos}
46+
lwc:if={isGetObjectInfos}
4747
></c-get-object-infos>
4848
<c-get-picklist-values
49-
if:true={isGetPicklistValues}
49+
lwc:if={isGetPicklistValues}
5050
></c-get-picklist-values>
5151
<c-get-picklist-values-by-record-type
52-
if:true={isGetPicklistValuesByRecordType}
52+
lwc:if={isGetPicklistValuesByRecordType}
5353
></c-get-picklist-values-by-record-type>
54-
<c-create-record if:true={isCreateRecord}></c-create-record>
54+
<c-create-record lwc:if={isCreateRecord}></c-create-record>
5555
<c-create-record-input-filtered-by-edited-fields
56-
if:true={isCreateRecordInputFilteredByEditedFields}
56+
lwc:if={isCreateRecordInputFilteredByEditedFields}
5757
></c-create-record-input-filtered-by-edited-fields>
58-
<c-delete-record if:true={isDeleteRecord}></c-delete-record>
58+
<c-delete-record lwc:if={isDeleteRecord}></c-delete-record>
5959
<c-generate-record-input-for-create
60-
if:true={isGenerateRecordInputForCreate}
60+
lwc:if={isGenerateRecordInputForCreate}
6161
></c-generate-record-input-for-create>
6262
<c-generate-record-input-for-update
63-
if:true={isGenerateRecordInputForUpdate}
63+
lwc:if={isGenerateRecordInputForUpdate}
6464
></c-generate-record-input-for-update>
6565
<c-get-field-value
66-
if:true={isGetFieldValue}
66+
lwc:if={isGetFieldValue}
6767
></c-get-field-value>
6868
<c-get-field-display-value
69-
if:true={isGetFieldDisplayValue}
69+
lwc:if={isGetFieldDisplayValue}
7070
></c-get-field-display-value>
71-
<c-get-record if:true={isGetRecord}></c-get-record>
72-
<c-get-records if:true={isGetRecords}></c-get-records>
71+
<c-get-record lwc:if={isGetRecord}></c-get-record>
72+
<c-get-records lwc:if={isGetRecords}></c-get-records>
7373
<c-get-record-create-defaults
74-
if:true={isGetRecordCreateDefaults}
74+
lwc:if={isGetRecordCreateDefaults}
7575
></c-get-record-create-defaults>
7676
<c-get-record-notify-change
77-
if:true={isGetRecordNotifyChange}
77+
lwc:if={isGetRecordNotifyChange}
7878
></c-get-record-notify-change>
79-
<c-get-record-ui if:true={isGetRecordUi}></c-get-record-ui>
80-
<c-update-record if:true={isUpdateRecord}></c-update-record>
81-
<c-get-nav-items if:true={isGetNavItems}></c-get-nav-items>
79+
<c-get-record-ui lwc:if={isGetRecordUi}></c-get-record-ui>
80+
<c-notify-record-update-available
81+
lwc:if={isNotifyRecordUpdateAvailable}
82+
></c-notify-record-update-available>
83+
<c-update-record lwc:if={isUpdateRecord}></c-update-record>
84+
<c-get-nav-items lwc:if={isGetNavItems}></c-get-nav-items>
8285
<c-get-related-list-records
83-
if:true={isGetRelatedListRecords}
86+
lwc:if={isGetRelatedListRecords}
8487
></c-get-related-list-records>
8588
<c-get-related-list-records-batch
86-
if:true={isGetRelatedListRecordsBatch}
89+
lwc:if={isGetRelatedListRecordsBatch}
8790
></c-get-related-list-records-batch>
8891
<c-get-related-list-info
89-
if:true={isGetRelatedListInfo}
92+
lwc:if={isGetRelatedListInfo}
9093
></c-get-related-list-info>
9194
<c-get-related-list-info-batch
92-
if:true={isGetRelatedListInfoBatch}
95+
lwc:if={isGetRelatedListInfoBatch}
9396
></c-get-related-list-info-batch>
9497
<c-get-related-lists-info
95-
if:true={isGetRelatedListsInfo}
98+
lwc:if={isGetRelatedListsInfo}
9699
></c-get-related-lists-info>
97100
<c-get-related-list-count
98-
if:true={isGetRelatedListCount}
101+
lwc:if={isGetRelatedListCount}
99102
></c-get-related-list-count>
100103
</c-api-endpoint>
101104
</template>
102105

103106
<!-- No endpoint selected -->
104-
<template if:false={selectedEndpoint}>
107+
<template lwc:else>
105108
<div
106109
class="slds-illustration slds-illustration_large"
107110
aria-hidden="true"

src/main/default/lwc/uiApiPlayground/uiApiPlayground.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { api, LightningElement } from 'lwc';
1+
import { LightningElement } from 'lwc';
22
import API_DEFINITIONS from './api-definitions.js';
33

44
export default class UiApiPlayground extends LightningElement {
@@ -87,6 +87,9 @@ export default class UiApiPlayground extends LightningElement {
8787
get isGetRecordUi() {
8888
return this.selectedEndpoint.name === 'getRecordUi';
8989
}
90+
get isNotifyRecordUpdateAvailable() {
91+
return this.selectedEndpoint.name === 'notifyRecordUpdateAvailable';
92+
}
9093
get isUpdateRecord() {
9194
return this.selectedEndpoint.name === 'updateRecord';
9295
}

0 commit comments

Comments
 (0)