@schandlergarcia/sf-web-components 1.0.0
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/.a4drules/skills/building-data-visualization/SKILL.md +72 -0
- package/.a4drules/skills/building-data-visualization/implementation/bar-line-chart.md +316 -0
- package/.a4drules/skills/building-data-visualization/implementation/dashboard-layout.md +189 -0
- package/.a4drules/skills/building-data-visualization/implementation/donut-chart.md +181 -0
- package/.a4drules/skills/building-data-visualization/implementation/stat-card.md +150 -0
- package/.a4drules/skills/building-react-components/SKILL.md +96 -0
- package/.a4drules/skills/building-react-components/implementation/component.md +78 -0
- package/.a4drules/skills/building-react-components/implementation/header-footer.md +132 -0
- package/.a4drules/skills/building-react-components/implementation/page.md +93 -0
- package/.a4drules/skills/configuring-csp-trusted-sites/SKILL.md +90 -0
- package/.a4drules/skills/configuring-csp-trusted-sites/implementation/metadata-format.md +281 -0
- package/.a4drules/skills/configuring-webapp-metadata/SKILL.md +158 -0
- package/.a4drules/skills/creating-webapp/SKILL.md +140 -0
- package/.a4drules/skills/deploying-to-salesforce/SKILL.md +226 -0
- package/.a4drules/skills/implementing-file-upload/SKILL.md +396 -0
- package/.a4drules/skills/installing-webapp-features/SKILL.md +210 -0
- package/.a4drules/skills/managing-agentforce-conversation-client/SKILL.md +186 -0
- package/.a4drules/skills/managing-agentforce-conversation-client/references/constraints.md +134 -0
- package/.a4drules/skills/managing-agentforce-conversation-client/references/examples.md +132 -0
- package/.a4drules/skills/managing-agentforce-conversation-client/references/style-tokens.md +101 -0
- package/.a4drules/skills/managing-agentforce-conversation-client/references/troubleshooting.md +57 -0
- package/.a4drules/skills/using-salesforce-data/SKILL.md +363 -0
- package/.a4drules/skills/using-salesforce-data/graphql-search.sh +139 -0
- package/.a4drules/webapp-data.md +353 -0
- package/.a4drules/webapp-ui.md +16 -0
- package/README.md +124 -0
- package/dist/components/library/cards/ActionList.js +27 -0
- package/dist/components/library/cards/ActionList.js.map +1 -0
- package/dist/components/library/cards/ActivityCard.js +40 -0
- package/dist/components/library/cards/ActivityCard.js.map +1 -0
- package/dist/components/library/cards/BaseCard.js +89 -0
- package/dist/components/library/cards/BaseCard.js.map +1 -0
- package/dist/components/library/cards/CalloutCard.js +28 -0
- package/dist/components/library/cards/CalloutCard.js.map +1 -0
- package/dist/components/library/cards/ChartCard.js +79 -0
- package/dist/components/library/cards/ChartCard.js.map +1 -0
- package/dist/components/library/cards/FeedPanel.js +38 -0
- package/dist/components/library/cards/FeedPanel.js.map +1 -0
- package/dist/components/library/cards/ListCard.js +112 -0
- package/dist/components/library/cards/ListCard.js.map +1 -0
- package/dist/components/library/cards/MetricCard.js +86 -0
- package/dist/components/library/cards/MetricCard.js.map +1 -0
- package/dist/components/library/cards/MetricsStrip.js +60 -0
- package/dist/components/library/cards/MetricsStrip.js.map +1 -0
- package/dist/components/library/cards/SectionCard.js +59 -0
- package/dist/components/library/cards/SectionCard.js.map +1 -0
- package/dist/components/library/cards/StatusCard.js +137 -0
- package/dist/components/library/cards/StatusCard.js.map +1 -0
- package/dist/components/library/cards/TableCard.js +244 -0
- package/dist/components/library/cards/TableCard.js.map +1 -0
- package/dist/components/library/cards/WidgetCard.js +60 -0
- package/dist/components/library/cards/WidgetCard.js.map +1 -0
- package/dist/components/library/charts/D3Chart.js +74 -0
- package/dist/components/library/charts/D3Chart.js.map +1 -0
- package/dist/components/library/charts/D3ChartTemplates.js +44 -0
- package/dist/components/library/charts/D3ChartTemplates.js.map +1 -0
- package/dist/components/library/charts/GeoMap.js +229 -0
- package/dist/components/library/charts/GeoMap.js.map +1 -0
- package/dist/components/library/chat/ChatBar.js +194 -0
- package/dist/components/library/chat/ChatBar.js.map +1 -0
- package/dist/components/library/chat/ChatInput.js +67 -0
- package/dist/components/library/chat/ChatInput.js.map +1 -0
- package/dist/components/library/chat/ChatMessage.js +112 -0
- package/dist/components/library/chat/ChatMessage.js.map +1 -0
- package/dist/components/library/chat/ChatMessageList.js +50 -0
- package/dist/components/library/chat/ChatMessageList.js.map +1 -0
- package/dist/components/library/chat/ChatPanel.js +77 -0
- package/dist/components/library/chat/ChatPanel.js.map +1 -0
- package/dist/components/library/chat/ChatSuggestions.js +22 -0
- package/dist/components/library/chat/ChatSuggestions.js.map +1 -0
- package/dist/components/library/chat/ChatToolCall.js +87 -0
- package/dist/components/library/chat/ChatToolCall.js.map +1 -0
- package/dist/components/library/chat/ChatTypingIndicator.js +20 -0
- package/dist/components/library/chat/ChatTypingIndicator.js.map +1 -0
- package/dist/components/library/chat/ChatWelcome.js +24 -0
- package/dist/components/library/chat/ChatWelcome.js.map +1 -0
- package/dist/components/library/chat/useChatState.js +77 -0
- package/dist/components/library/chat/useChatState.js.map +1 -0
- package/dist/components/library/data/DataModeProvider.js +47 -0
- package/dist/components/library/data/DataModeProvider.js.map +1 -0
- package/dist/components/library/data/DataModeToggle.js +28 -0
- package/dist/components/library/data/DataModeToggle.js.map +1 -0
- package/dist/components/library/data/filterUtils.js +71 -0
- package/dist/components/library/data/filterUtils.js.map +1 -0
- package/dist/components/library/data/useDataSource.js +13 -0
- package/dist/components/library/data/useDataSource.js.map +1 -0
- package/dist/components/library/data/usePageFilters.js +46 -0
- package/dist/components/library/data/usePageFilters.js.map +1 -0
- package/dist/components/library/filters/FilterBar.js +89 -0
- package/dist/components/library/filters/FilterBar.js.map +1 -0
- package/dist/components/library/filters/SearchFilter.js +44 -0
- package/dist/components/library/filters/SearchFilter.js.map +1 -0
- package/dist/components/library/filters/SelectFilter.js +44 -0
- package/dist/components/library/filters/SelectFilter.js.map +1 -0
- package/dist/components/library/filters/ToggleFilter.js +48 -0
- package/dist/components/library/filters/ToggleFilter.js.map +1 -0
- package/dist/components/library/forms/FormField.js +256 -0
- package/dist/components/library/forms/FormField.js.map +1 -0
- package/dist/components/library/forms/FormModal.js +161 -0
- package/dist/components/library/forms/FormModal.js.map +1 -0
- package/dist/components/library/forms/FormRenderer.js +32 -0
- package/dist/components/library/forms/FormRenderer.js.map +1 -0
- package/dist/components/library/forms/FormSection.js +49 -0
- package/dist/components/library/forms/FormSection.js.map +1 -0
- package/dist/components/library/forms/useFormState.js +85 -0
- package/dist/components/library/forms/useFormState.js.map +1 -0
- package/dist/components/library/heroui/Accordion.js +12 -0
- package/dist/components/library/heroui/Accordion.js.map +1 -0
- package/dist/components/library/heroui/Alert.js +12 -0
- package/dist/components/library/heroui/Alert.js.map +1 -0
- package/dist/components/library/heroui/Badge.js +12 -0
- package/dist/components/library/heroui/Badge.js.map +1 -0
- package/dist/components/library/heroui/Breadcrumbs.js +12 -0
- package/dist/components/library/heroui/Breadcrumbs.js.map +1 -0
- package/dist/components/library/heroui/Button.js +18 -0
- package/dist/components/library/heroui/Button.js.map +1 -0
- package/dist/components/library/heroui/Card.js +12 -0
- package/dist/components/library/heroui/Card.js.map +1 -0
- package/dist/components/library/heroui/Drawer.js +12 -0
- package/dist/components/library/heroui/Drawer.js.map +1 -0
- package/dist/components/library/heroui/Dropdown.js +12 -0
- package/dist/components/library/heroui/Dropdown.js.map +1 -0
- package/dist/components/library/heroui/Input.js +10 -0
- package/dist/components/library/heroui/Input.js.map +1 -0
- package/dist/components/library/heroui/Kbd.js +12 -0
- package/dist/components/library/heroui/Kbd.js.map +1 -0
- package/dist/components/library/heroui/Meter.js +12 -0
- package/dist/components/library/heroui/Meter.js.map +1 -0
- package/dist/components/library/heroui/Modal.js +12 -0
- package/dist/components/library/heroui/Modal.js.map +1 -0
- package/dist/components/library/heroui/Pagination.js +12 -0
- package/dist/components/library/heroui/Pagination.js.map +1 -0
- package/dist/components/library/heroui/ProgressBar.js +12 -0
- package/dist/components/library/heroui/ProgressBar.js.map +1 -0
- package/dist/components/library/heroui/ProgressCircle.js +12 -0
- package/dist/components/library/heroui/ProgressCircle.js.map +1 -0
- package/dist/components/library/heroui/ScrollShadow.js +12 -0
- package/dist/components/library/heroui/ScrollShadow.js.map +1 -0
- package/dist/components/library/heroui/Select.js +12 -0
- package/dist/components/library/heroui/Select.js.map +1 -0
- package/dist/components/library/heroui/Separator.js +12 -0
- package/dist/components/library/heroui/Separator.js.map +1 -0
- package/dist/components/library/heroui/Skeleton.js +12 -0
- package/dist/components/library/heroui/Skeleton.js.map +1 -0
- package/dist/components/library/heroui/Tabs.js +12 -0
- package/dist/components/library/heroui/Tabs.js.map +1 -0
- package/dist/components/library/heroui/Toast.js +13 -0
- package/dist/components/library/heroui/Toast.js.map +1 -0
- package/dist/components/library/heroui/Toggle.js +12 -0
- package/dist/components/library/heroui/Toggle.js.map +1 -0
- package/dist/components/library/heroui/Tooltip.js +12 -0
- package/dist/components/library/heroui/Tooltip.js.map +1 -0
- package/dist/components/library/layout/PageContainer.js +9 -0
- package/dist/components/library/layout/PageContainer.js.map +1 -0
- package/dist/components/library/skeletons/CardSkeleton.js +29 -0
- package/dist/components/library/skeletons/CardSkeleton.js.map +1 -0
- package/dist/components/library/theme/AppThemeProvider.js +55 -0
- package/dist/components/library/theme/AppThemeProvider.js.map +1 -0
- package/dist/components/library/theme/tokens.js +55 -0
- package/dist/components/library/theme/tokens.js.map +1 -0
- package/dist/components/library/ui/Avatar.js +33 -0
- package/dist/components/library/ui/Avatar.js.map +1 -0
- package/dist/components/library/ui/Button.js +50 -0
- package/dist/components/library/ui/Button.js.map +1 -0
- package/dist/components/library/ui/Card.js +21 -0
- package/dist/components/library/ui/Card.js.map +1 -0
- package/dist/components/library/ui/Chip.js +31 -0
- package/dist/components/library/ui/Chip.js.map +1 -0
- package/dist/components/library/ui/Container.js +42 -0
- package/dist/components/library/ui/Container.js.map +1 -0
- package/dist/components/library/ui/EmptyState.js +27 -0
- package/dist/components/library/ui/EmptyState.js.map +1 -0
- package/dist/components/library/ui/Input.js +22 -0
- package/dist/components/library/ui/Input.js.map +1 -0
- package/dist/components/library/ui/Spinner.js +64 -0
- package/dist/components/library/ui/Spinner.js.map +1 -0
- package/dist/components/library/ui/Text.js +43 -0
- package/dist/components/library/ui/Text.js.map +1 -0
- package/dist/components/library/ui/Toggle.js +47 -0
- package/dist/components/library/ui/Toggle.js.map +1 -0
- package/dist/components/workspace/ComponentRegistry.js +231 -0
- package/dist/components/workspace/ComponentRegistry.js.map +1 -0
- package/dist/index.js +185 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/utils.js +9 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/node_modules/clsx/dist/clsx.js +17 -0
- package/dist/node_modules/clsx/dist/clsx.js.map +1 -0
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js +2925 -0
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js.map +1 -0
- package/package.json +81 -0
- package/scripts/get-graphql-schema.mjs +68 -0
- package/scripts/reset-command-center.sh +358 -0
- package/scripts/rewrite-e2e-assets.mjs +23 -0
- package/scripts/validate-dashboard.sh +290 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: implementing-file-upload
|
|
3
|
+
description: Add file upload functionality to React webapps with progress tracking and Salesforce ContentVersion integration. Use when the user wants to upload files, attach documents, handle file input, create file dropzones, track upload progress, or link files to Salesforce records. This feature provides programmatic APIs ONLY — no components or hooks are exported. Build your own custom UI using the upload() API. ALWAYS use this feature instead of building file upload from scratch with FormData or XHR.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# File Upload API (workflow)
|
|
7
|
+
|
|
8
|
+
When the user wants file upload functionality in a React webapp, follow this workflow. This feature provides **APIs only** — you must build the UI components yourself using the provided APIs.
|
|
9
|
+
|
|
10
|
+
## CRITICAL: This is an API-only package
|
|
11
|
+
|
|
12
|
+
The package exports **programmatic APIs**, not React components or hooks. You will:
|
|
13
|
+
|
|
14
|
+
- Use the `upload()` function to handle file uploads with progress tracking
|
|
15
|
+
- Build your own custom UI (file input, dropzone, progress bars, etc.)
|
|
16
|
+
- Track upload progress through the `onProgress` callback
|
|
17
|
+
|
|
18
|
+
**Do NOT:**
|
|
19
|
+
|
|
20
|
+
- Expect pre-built components like `<FileUpload />` — they are not exported
|
|
21
|
+
- Try to import React hooks like `useFileUpload` — they are not exported
|
|
22
|
+
- Look for dropzone components — they are not exported
|
|
23
|
+
|
|
24
|
+
The source code contains reference components for demonstration, but they are **not available** as imports. Use them as examples to build your own UI.
|
|
25
|
+
|
|
26
|
+
## 1. Install the package
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @salesforce/webapp-template-feature-react-file-upload-experimental
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Dependencies are automatically installed:
|
|
33
|
+
|
|
34
|
+
- `@salesforce/webapp-experimental` (API client)
|
|
35
|
+
- `@salesforce/sdk-data` (data SDK)
|
|
36
|
+
|
|
37
|
+
## 2. Understand the three upload patterns
|
|
38
|
+
|
|
39
|
+
### Pattern A: Basic upload (no record linking)
|
|
40
|
+
|
|
41
|
+
Upload files to Salesforce and get back `contentBodyId` for each file. No ContentVersion record is created.
|
|
42
|
+
|
|
43
|
+
**When to use:**
|
|
44
|
+
|
|
45
|
+
- User wants to upload files first, then create/link them to a record later
|
|
46
|
+
- Building a multi-step form where the record doesn't exist yet
|
|
47
|
+
- Deferred record linking scenarios
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { upload } from "@salesforce/webapp-template-feature-react-file-upload-experimental";
|
|
51
|
+
|
|
52
|
+
const results = await upload({
|
|
53
|
+
files: [file1, file2],
|
|
54
|
+
onProgress: (progress) => {
|
|
55
|
+
console.log(`${progress.fileName}: ${progress.status} - ${progress.progress}%`);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// results[0].contentBodyId: "069..." (always available)
|
|
60
|
+
// results[0].contentVersionId: undefined (no record linked)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Pattern B: Upload with immediate record linking
|
|
64
|
+
|
|
65
|
+
Upload files and immediately link them to an existing Salesforce record by creating ContentVersion records.
|
|
66
|
+
|
|
67
|
+
**When to use:**
|
|
68
|
+
|
|
69
|
+
- Record already exists (Account, Opportunity, Case, etc.)
|
|
70
|
+
- User wants files immediately attached to the record
|
|
71
|
+
- Direct upload-and-attach scenarios
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import { upload } from "@salesforce/webapp-template-feature-react-file-upload-experimental";
|
|
75
|
+
|
|
76
|
+
const results = await upload({
|
|
77
|
+
files: [file1, file2],
|
|
78
|
+
recordId: "001xx000000yyyy", // Existing record ID
|
|
79
|
+
onProgress: (progress) => {
|
|
80
|
+
console.log(`${progress.fileName}: ${progress.status} - ${progress.progress}%`);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// results[0].contentBodyId: "069..." (always available)
|
|
85
|
+
// results[0].contentVersionId: "068..." (linked to record)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Pattern C: Deferred record linking (record creation flow)
|
|
89
|
+
|
|
90
|
+
Upload files without a record, then link them after the record is created.
|
|
91
|
+
|
|
92
|
+
**When to use:**
|
|
93
|
+
|
|
94
|
+
- Building a "create record with attachments" form
|
|
95
|
+
- Record doesn't exist until form submission
|
|
96
|
+
- Need to upload files before knowing the final record ID
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import {
|
|
100
|
+
upload,
|
|
101
|
+
createContentVersion,
|
|
102
|
+
} from "@salesforce/webapp-template-feature-react-file-upload-experimental";
|
|
103
|
+
|
|
104
|
+
// Step 1: Upload files (no recordId)
|
|
105
|
+
const uploadResults = await upload({
|
|
106
|
+
files: [file1, file2],
|
|
107
|
+
onProgress: (progress) => console.log(progress),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Step 2: Create the record
|
|
111
|
+
const newRecordId = await createRecord(formData);
|
|
112
|
+
|
|
113
|
+
// Step 3: Link uploaded files to the new record
|
|
114
|
+
for (const file of uploadResults) {
|
|
115
|
+
const contentVersionId = await createContentVersion(
|
|
116
|
+
new File([""], file.fileName),
|
|
117
|
+
file.contentBodyId,
|
|
118
|
+
newRecordId,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 3. Build your custom UI
|
|
124
|
+
|
|
125
|
+
The package provides the backend — you build the frontend. Here's a minimal example:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import {
|
|
129
|
+
upload,
|
|
130
|
+
type FileUploadProgress,
|
|
131
|
+
} from "@salesforce/webapp-template-feature-react-file-upload-experimental";
|
|
132
|
+
import { useState } from "react";
|
|
133
|
+
|
|
134
|
+
function CustomFileUpload({ recordId }: { recordId?: string }) {
|
|
135
|
+
const [progress, setProgress] = useState<Map<string, FileUploadProgress>>(new Map());
|
|
136
|
+
|
|
137
|
+
const handleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
138
|
+
const files = Array.from(event.target.files || []);
|
|
139
|
+
|
|
140
|
+
await upload({
|
|
141
|
+
files,
|
|
142
|
+
recordId,
|
|
143
|
+
onProgress: (fileProgress) => {
|
|
144
|
+
setProgress((prev) => new Map(prev).set(fileProgress.fileName, fileProgress));
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div>
|
|
151
|
+
<input type="file" multiple onChange={handleFileSelect} />
|
|
152
|
+
|
|
153
|
+
{Array.from(progress.entries()).map(([fileName, fileProgress]) => (
|
|
154
|
+
<div key={fileName}>
|
|
155
|
+
{fileName}: {fileProgress.status} - {fileProgress.progress}%
|
|
156
|
+
{fileProgress.error && <span>Error: {fileProgress.error}</span>}
|
|
157
|
+
</div>
|
|
158
|
+
))}
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 4. Track upload progress
|
|
165
|
+
|
|
166
|
+
The `onProgress` callback fires multiple times for each file as it moves through stages:
|
|
167
|
+
|
|
168
|
+
| Status | When | Progress Value |
|
|
169
|
+
| -------------- | ---------------------------------------------- | -------------------- |
|
|
170
|
+
| `"pending"` | File queued for upload | `0` |
|
|
171
|
+
| `"uploading"` | Upload in progress (XHR) | `0-100` (percentage) |
|
|
172
|
+
| `"processing"` | Creating ContentVersion (if recordId provided) | `0` |
|
|
173
|
+
| `"success"` | Upload complete | `100` |
|
|
174
|
+
| `"error"` | Upload failed | `0` |
|
|
175
|
+
|
|
176
|
+
**Always provide visual feedback:**
|
|
177
|
+
|
|
178
|
+
- Show file name
|
|
179
|
+
- Display current status
|
|
180
|
+
- Render progress bar for "uploading" status
|
|
181
|
+
- Show error message if status is "error"
|
|
182
|
+
|
|
183
|
+
## 5. Cancel uploads (optional)
|
|
184
|
+
|
|
185
|
+
Use an `AbortController` to allow users to cancel uploads:
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
const abortController = new AbortController();
|
|
189
|
+
|
|
190
|
+
const handleUpload = async (files: File[]) => {
|
|
191
|
+
try {
|
|
192
|
+
await upload({
|
|
193
|
+
files,
|
|
194
|
+
signal: abortController.signal,
|
|
195
|
+
onProgress: (progress) => console.log(progress),
|
|
196
|
+
});
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.error("Upload cancelled or failed:", error);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const cancelUpload = () => {
|
|
203
|
+
abortController.abort();
|
|
204
|
+
};
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## 6. Link to current user (special case)
|
|
208
|
+
|
|
209
|
+
If the user wants to upload files to their own profile or personal library:
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
import {
|
|
213
|
+
upload,
|
|
214
|
+
getCurrentUserId,
|
|
215
|
+
} from "@salesforce/webapp-template-feature-react-file-upload-experimental";
|
|
216
|
+
|
|
217
|
+
const userId = await getCurrentUserId();
|
|
218
|
+
await upload({ files, recordId: userId });
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## API Reference
|
|
222
|
+
|
|
223
|
+
### upload(options)
|
|
224
|
+
|
|
225
|
+
Main upload API that handles complete flow with progress tracking.
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
interface UploadOptions {
|
|
229
|
+
files: File[];
|
|
230
|
+
recordId?: string | null; // If provided, creates ContentVersion
|
|
231
|
+
onProgress?: (progress: FileUploadProgress) => void;
|
|
232
|
+
signal?: AbortSignal; // Optional cancellation
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
interface FileUploadProgress {
|
|
236
|
+
fileName: string;
|
|
237
|
+
status: "pending" | "uploading" | "processing" | "success" | "error";
|
|
238
|
+
progress: number; // 0-100 for uploading, 0 for other states
|
|
239
|
+
error?: string;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface FileUploadResult {
|
|
243
|
+
fileName: string;
|
|
244
|
+
size: number;
|
|
245
|
+
contentBodyId: string; // Always available
|
|
246
|
+
contentVersionId?: string; // Only if recordId was provided
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**Returns:** `Promise<FileUploadResult[]>`
|
|
251
|
+
|
|
252
|
+
### createContentVersion(file, contentBodyId, recordId)
|
|
253
|
+
|
|
254
|
+
Manually create a ContentVersion record from a previously uploaded file.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
async function createContentVersion(
|
|
258
|
+
file: File,
|
|
259
|
+
contentBodyId: string,
|
|
260
|
+
recordId: string,
|
|
261
|
+
): Promise<string | undefined>;
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Parameters:**
|
|
265
|
+
|
|
266
|
+
- `file` — File object (used for metadata like name)
|
|
267
|
+
- `contentBodyId` — ContentBody ID from previous upload
|
|
268
|
+
- `recordId` — Record ID for FirstPublishLocationId
|
|
269
|
+
|
|
270
|
+
**Returns:** ContentVersion ID if successful
|
|
271
|
+
|
|
272
|
+
### getCurrentUserId()
|
|
273
|
+
|
|
274
|
+
Get the current user's Salesforce ID.
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
async function getCurrentUserId(): Promise<string>;
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Returns:** Current user ID
|
|
281
|
+
|
|
282
|
+
## Common UI patterns
|
|
283
|
+
|
|
284
|
+
### File input with button
|
|
285
|
+
|
|
286
|
+
```tsx
|
|
287
|
+
<input type="file" multiple accept=".pdf,.doc,.docx,.jpg,.png" onChange={handleFileSelect} />
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Drag-and-drop zone
|
|
291
|
+
|
|
292
|
+
Build your own dropzone using native events:
|
|
293
|
+
|
|
294
|
+
```tsx
|
|
295
|
+
function DropZone({ onDrop }: { onDrop: (files: File[]) => void }) {
|
|
296
|
+
const handleDrop = (e: React.DragEvent) => {
|
|
297
|
+
e.preventDefault();
|
|
298
|
+
const files = Array.from(e.dataTransfer.files);
|
|
299
|
+
onDrop(files);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
return (
|
|
303
|
+
<div
|
|
304
|
+
onDrop={handleDrop}
|
|
305
|
+
onDragOver={(e) => e.preventDefault()}
|
|
306
|
+
style={{ border: "2px dashed #ccc", padding: "2rem" }}
|
|
307
|
+
>
|
|
308
|
+
Drop files here
|
|
309
|
+
</div>
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Progress bar
|
|
315
|
+
|
|
316
|
+
```tsx
|
|
317
|
+
{
|
|
318
|
+
progress.status === "uploading" && (
|
|
319
|
+
<div style={{ width: "100%", background: "#eee" }}>
|
|
320
|
+
<div
|
|
321
|
+
style={{
|
|
322
|
+
width: `${progress.progress}%`,
|
|
323
|
+
background: "#0176d3",
|
|
324
|
+
height: "8px",
|
|
325
|
+
}}
|
|
326
|
+
/>
|
|
327
|
+
</div>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Decision tree for agents
|
|
333
|
+
|
|
334
|
+
**User asks for file upload functionality:**
|
|
335
|
+
|
|
336
|
+
1. **Ask about record context:**
|
|
337
|
+
- "Do you want to link uploaded files to a specific record, or upload them first and link later?"
|
|
338
|
+
|
|
339
|
+
2. **Based on response:**
|
|
340
|
+
- **Link to existing record** → Use Pattern B with `recordId`
|
|
341
|
+
- **Upload first, link later** → Use Pattern A (no recordId), then Pattern C for linking
|
|
342
|
+
- **Link to current user** → Use Pattern B with `getCurrentUserId()`
|
|
343
|
+
|
|
344
|
+
3. **Build the UI:**
|
|
345
|
+
- Create file input or dropzone (not provided by package)
|
|
346
|
+
- Add progress display for each file (status + progress bar)
|
|
347
|
+
- Handle errors in the UI
|
|
348
|
+
|
|
349
|
+
4. **Test the implementation:**
|
|
350
|
+
- Verify progress callbacks fire correctly
|
|
351
|
+
- Check that `contentBodyId` is returned
|
|
352
|
+
- If `recordId` was provided, verify `contentVersionId` is returned
|
|
353
|
+
|
|
354
|
+
## Reference implementation
|
|
355
|
+
|
|
356
|
+
The package includes a reference implementation in `src/features/fileupload/` with:
|
|
357
|
+
|
|
358
|
+
- `FileUpload.tsx` — Complete component with dropzone and dialog
|
|
359
|
+
- `FileUploadDialog.tsx` — Progress tracking dialog
|
|
360
|
+
- `FileUploadDropZone.tsx` — Drag-and-drop zone
|
|
361
|
+
- `useFileUpload.ts` — React hook for state management
|
|
362
|
+
|
|
363
|
+
**These are NOT exported** but can be viewed as examples. Read the source files to understand patterns for building your own UI.
|
|
364
|
+
|
|
365
|
+
## Troubleshooting
|
|
366
|
+
|
|
367
|
+
**Upload fails with CORS error:**
|
|
368
|
+
|
|
369
|
+
- Ensure the webapp is properly deployed to Salesforce or running on `localhost`
|
|
370
|
+
- Check that the org allows the origin in CORS settings
|
|
371
|
+
|
|
372
|
+
**No progress updates:**
|
|
373
|
+
|
|
374
|
+
- Verify `onProgress` callback is provided
|
|
375
|
+
- Check that the callback function updates React state correctly
|
|
376
|
+
|
|
377
|
+
**ContentVersion not created:**
|
|
378
|
+
|
|
379
|
+
- Verify `recordId` is provided to `upload()` function
|
|
380
|
+
- Check that the record ID is valid and exists in the org
|
|
381
|
+
- Ensure user has permissions to create ContentVersion records
|
|
382
|
+
|
|
383
|
+
**Files upload but don't appear in record:**
|
|
384
|
+
|
|
385
|
+
- Verify `recordId` is correct
|
|
386
|
+
- Check that ContentVersion was created (look for `contentVersionId` in results)
|
|
387
|
+
- Confirm user has access to view files on the record
|
|
388
|
+
|
|
389
|
+
## DO NOT do these things
|
|
390
|
+
|
|
391
|
+
- ❌ Build XHR/fetch upload logic from scratch — use the `upload()` API
|
|
392
|
+
- ❌ Try to import `<FileUpload />` component — it's not exported
|
|
393
|
+
- ❌ Try to import `useFileUpload` hook — it's not exported
|
|
394
|
+
- ❌ Use third-party file upload libraries when this feature exists
|
|
395
|
+
- ❌ Skip progress tracking — always provide user feedback
|
|
396
|
+
- ❌ Ignore errors — always handle and display error messages
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: installing-webapp-features
|
|
3
|
+
description: Search, describe, and install pre-built UI features (authentication, shadcn components, navigation, search, GraphQL, Agentforce AI) into Salesforce webapps. Use this when the user wants to add functionality to a webapp, or when determining what salesforce-provided features are available — whether prompted by the user or on your own initiative. Always check for an existing feature before building from scratch.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# webapps-features-experimental CLI — Agent Reference
|
|
7
|
+
|
|
8
|
+
**Always check for an existing feature before building something yourself.** This CLI installs pre-built, tested feature packages into Salesforce webapps. Features range from foundational UI component libraries (shadcn/ui with Button, Card, Input, Table, etc.) to full-stack application capabilities like authentication (login, registration, password flows, session management, and Apex backend classes), global search, navigation menus, GraphQL integrations, and Agentforce AI conversation UIs. Each feature ships as a complete implementation — including React components, context providers, route guards, and any required Salesforce server-side code — that already handles platform-specific concerns like Salesforce API integration, session management, and SFDX metadata structure. Building these from scratch is error-prone and unnecessary when a feature exists. **If no existing feature is found, ask the user before proceeding with a custom implementation — a relevant feature may exist under a different name or keyword.**
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npx @salesforce/webapps-features-experimental <command> [options]
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Workflow: Search Project → Search Features → Describe → Install
|
|
15
|
+
|
|
16
|
+
**MANDATORY**: When the user asks to add ANY webapp functionality, follow this entire workflow. Do not skip steps.
|
|
17
|
+
|
|
18
|
+
### 1. Search existing project code
|
|
19
|
+
|
|
20
|
+
Before installing anything, check whether the functionality already exists in the **project source code** (not dependencies).
|
|
21
|
+
|
|
22
|
+
- **Always scope searches to `src/`** to avoid matching files in `node_modules/`, `dist/`, or `build/` output
|
|
23
|
+
- Use Glob with a scoped path: e.g., `src/**/Button.tsx`, `src/**/*auth*.tsx`
|
|
24
|
+
- Use Grep with the `path` parameter set to the `src/` directory, or use `glob: "*.{ts,tsx}"` to restrict file types
|
|
25
|
+
- Check common directories: `src/components/`, `src/lib/`, `src/pages/`, `src/hooks/`
|
|
26
|
+
- **Never** search from the project root without a path or glob filter — this will crawl `node_modules` and produce massive, unhelpful output
|
|
27
|
+
|
|
28
|
+
**If existing code is found** — read the files, present them to the user, and ask if they want to reuse or extend what's there. If yes, use the existing code and stop. If no, proceed to step 2.
|
|
29
|
+
|
|
30
|
+
**If nothing is found** — proceed to step 2.
|
|
31
|
+
|
|
32
|
+
### 2. Search available features
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx @salesforce/webapps-features-experimental list [options]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Options:
|
|
39
|
+
|
|
40
|
+
- `-v, --verbose` — Show full descriptions, packages, and dependencies
|
|
41
|
+
- `--search <query>` — Filter features by keyword (ranked by relevance)
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx @salesforce/webapps-features-experimental list
|
|
45
|
+
npx @salesforce/webapps-features-experimental list --search "auth"
|
|
46
|
+
npx @salesforce/webapps-features-experimental list --search "button"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**If no matching feature is found** — ask the user before proceeding with a custom implementation. A relevant feature may exist under a different name or keyword.
|
|
50
|
+
|
|
51
|
+
### 3. Describe a feature
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx @salesforce/webapps-features-experimental describe <feature>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Shows description, package name, dependencies, components, copy operations, and example files.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx @salesforce/webapps-features-experimental describe authentication
|
|
61
|
+
npx @salesforce/webapps-features-experimental describe shadcn
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 4. Install a feature
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npx @salesforce/webapps-features-experimental install <feature> --webapp-dir <path> [options]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Resolves the feature name to an npm package, installs it and its dependencies (including transitive feature dependencies like `shadcn`), copies source files into your project, and reports any `__example__` files that require manual integration.
|
|
71
|
+
|
|
72
|
+
Options:
|
|
73
|
+
|
|
74
|
+
- `--webapp-dir <name>` (required) — Webapp name, resolves to `<sfdx-source>/webapplications/<name>`
|
|
75
|
+
- `--sfdx-source <path>` (default: `force-app/main/default`) — SFDX source directory
|
|
76
|
+
- `--dry-run` (default: `false`) — Preview changes without writing files
|
|
77
|
+
- `-v, --verbose` (default: `false`) — Enable verbose logging
|
|
78
|
+
- `-y, --yes` (default: `false`) — Skip all prompts (auto-skip conflicts)
|
|
79
|
+
- `--on-conflict <mode>` (default: `prompt`) — `prompt`, `error`, `skip`, or `overwrite`
|
|
80
|
+
- `--conflict-resolution <file>` — Path to JSON file with per-file resolutions
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Install authentication (also installs shadcn dependency)
|
|
84
|
+
npx @salesforce/webapps-features-experimental install authentication \
|
|
85
|
+
--webapp-dir mywebapp
|
|
86
|
+
|
|
87
|
+
# Dry run to preview changes
|
|
88
|
+
npx @salesforce/webapps-features-experimental install shadcn \
|
|
89
|
+
--webapp-dir mywebapp \
|
|
90
|
+
--dry-run
|
|
91
|
+
|
|
92
|
+
# Non-interactive install (skip all file conflicts)
|
|
93
|
+
npx @salesforce/webapps-features-experimental install authentication \
|
|
94
|
+
--webapp-dir mywebapp \
|
|
95
|
+
--yes
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Conflict Handling
|
|
99
|
+
|
|
100
|
+
Since you are running in a non-interactive environment, you cannot use `--on-conflict prompt` directly. When conflicts are likely (e.g. installing into an existing project), you have two options:
|
|
101
|
+
|
|
102
|
+
**Option A — Let the user resolve conflicts interactively.** Suggest the user run the install command themselves with `--on-conflict prompt` so they can decide per-file.
|
|
103
|
+
|
|
104
|
+
**Option B — Two-pass automated resolution:**
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Pass 1: detect conflicts
|
|
108
|
+
npx @salesforce/webapps-features-experimental install authentication \
|
|
109
|
+
--webapp-dir mywebapp \
|
|
110
|
+
--on-conflict error
|
|
111
|
+
|
|
112
|
+
# The CLI will exit with an error listing every conflicting file path.
|
|
113
|
+
|
|
114
|
+
# Pass 2: create a resolution file and re-run
|
|
115
|
+
echo '{ "src/styles/global.css": "overwrite", "src/lib/utils.ts": "skip" }' > resolutions.json
|
|
116
|
+
|
|
117
|
+
npx @salesforce/webapps-features-experimental install authentication \
|
|
118
|
+
--webapp-dir mywebapp \
|
|
119
|
+
--conflict-resolution resolutions.json
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Resolution values per file: `"skip"` (keep existing) or `"overwrite"` (replace). When unsure how to resolve a conflict, ask the user rather than guessing.
|
|
123
|
+
|
|
124
|
+
## Hint Placeholders in Copy Paths
|
|
125
|
+
|
|
126
|
+
Some copy operations use **hint placeholders** in the `"to"` path — descriptive segments like `<desired-page-with-search-input>` that are NOT resolved by the CLI. These are guidance for the user or LLM to choose an appropriate destination.
|
|
127
|
+
|
|
128
|
+
**How they work:** The file is copied with the literal placeholder name (e.g., `src/pages/<desired-page-with-search-input>.tsx`). After installation, you should:
|
|
129
|
+
|
|
130
|
+
1. Read the copied file to understand its purpose
|
|
131
|
+
2. Rename or relocate it to the intended target (e.g., `src/pages/Home.tsx`)
|
|
132
|
+
3. Or integrate its patterns into an existing file, then delete it
|
|
133
|
+
|
|
134
|
+
**How to identify them:** Hint placeholders use `<descriptive-name>` syntax but are NOT one of the system placeholders (`<sfdxSource>`, `<webappDir>`, `<webapp>`). They always appear in the middle or end of a path, never as the leading segment.
|
|
135
|
+
|
|
136
|
+
**Example from features.json:**
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"to": "<webappDir>/src/pages/<desired-page-with-search-input>.tsx",
|
|
141
|
+
"description": "Example home page showing GlobalSearchInput integration",
|
|
142
|
+
"integrationTarget": "src/pages/Home.tsx"
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The `integrationTarget` field tells you the suggested destination. Use your judgment — if the user already has a different page where search should go, integrate there instead.
|
|
147
|
+
|
|
148
|
+
**When `integrationTarget` itself is a placeholder:** Some features use a hint placeholder in the `integrationTarget` value (e.g., `"integrationTarget": "src/<path-to-desired-page-with-search-input>.tsx"`). This means there is no single default target — the user must decide which existing file to integrate into. When you encounter this:
|
|
149
|
+
|
|
150
|
+
1. Ask the user which page or file they want to integrate the feature into
|
|
151
|
+
2. Read the `__example__` file to understand the integration pattern
|
|
152
|
+
3. Read the user's chosen target file
|
|
153
|
+
4. Apply the pattern from the example into the target file
|
|
154
|
+
|
|
155
|
+
## Post Installation: Integrating **example** Files
|
|
156
|
+
|
|
157
|
+
Features may include `__example__` files (e.g., `__example__auth-app.tsx`) showing integration patterns.
|
|
158
|
+
|
|
159
|
+
**The describe command shows**:
|
|
160
|
+
|
|
161
|
+
- Which **example** files will be copied
|
|
162
|
+
- Target file to integrate into (e.g., `src/app.tsx`)
|
|
163
|
+
- What the example demonstrates
|
|
164
|
+
|
|
165
|
+
### How to Integrate Example Files (CRITICAL FOR LLMs)
|
|
166
|
+
|
|
167
|
+
⚠️ **ONLY USE Read AND Edit TOOLS - NO BASH COMMANDS** ⚠️
|
|
168
|
+
|
|
169
|
+
**DO NOT DO THIS**:
|
|
170
|
+
|
|
171
|
+
- ❌ `git status` or any git commands
|
|
172
|
+
- ❌ `ls`, `cat`, `sed`, `awk`, or ANY bash file commands
|
|
173
|
+
- ❌ Chaining bash commands to read multiple files
|
|
174
|
+
- ❌ Using bash to check directories or file existence
|
|
175
|
+
|
|
176
|
+
**DO THIS INSTEAD**:
|
|
177
|
+
|
|
178
|
+
- ✅ Use Read tool with `file_path` parameter to read each file
|
|
179
|
+
- ✅ Use Edit tool with `file_path`, `old_string`, `new_string` to modify files
|
|
180
|
+
- ✅ That's it! Just Read and Edit tools.
|
|
181
|
+
|
|
182
|
+
**Integration steps**:
|
|
183
|
+
|
|
184
|
+
1. **Read each example file** (use Read tool)
|
|
185
|
+
- Example: Read tool with `file_path: "force-app/main/default/webapplications/mywebapp/src/__example__auth-app.tsx"`
|
|
186
|
+
- Note the imports and patterns to integrate
|
|
187
|
+
|
|
188
|
+
2. **Read each target file** (use Read tool)
|
|
189
|
+
- Example: Read tool with `file_path: "force-app/main/default/webapplications/mywebapp/src/app.tsx"`
|
|
190
|
+
- Understand where the new code should go
|
|
191
|
+
|
|
192
|
+
3. **Edit each target file** (use Edit tool)
|
|
193
|
+
- Add imports from the example
|
|
194
|
+
- Add or modify code following the example's patterns
|
|
195
|
+
- Preserve existing functionality
|
|
196
|
+
|
|
197
|
+
4. **Delete the example file after successful integration** (use Bash tool)
|
|
198
|
+
- Example: `rm force-app/main/default/webapplications/mywebapp/src/__example__authentication-routes.tsx`
|
|
199
|
+
- Only delete after you have successfully integrated the pattern
|
|
200
|
+
- This keeps the codebase clean and removes temporary example files
|
|
201
|
+
|
|
202
|
+
## Troubleshooting
|
|
203
|
+
|
|
204
|
+
**Directory not found**: Check paths are correct, use absolute or correct relative paths
|
|
205
|
+
|
|
206
|
+
**Feature not found**: Use `npx @salesforce/webapps-features-experimental list` to see available feature names
|
|
207
|
+
|
|
208
|
+
**Conflicts in error mode**: Follow CLI instructions to create resolution file
|
|
209
|
+
|
|
210
|
+
**Need help?**: Run `npx @salesforce/webapps-features-experimental --help` to see all commands and options
|