Skip to content

Commit c2f08bc

Browse files
miquelgallclaude
andcommitted
Fix Forms Viewer plugin filtering and column ordering
- Fix FORM_LABEL parameter in descriptor.json (was empty, now properly configured) - Add support for specific field names in COLUMN_ORDER - Users can now specify individual fields: "SITE_NOTE_TITLE, SITE_NOTE_DETAILS" - Or use generic keywords: "formDetails" to auto-expand all fields - Update @ofs-users/plugin from ^1.5.0 to ^1.5.1 - Improve README documentation with examples for both approaches - Clean up excessive debugging logs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent af2c541 commit c2f08bc

File tree

5 files changed

+69
-25
lines changed

5 files changed

+69
-25
lines changed

samples/019-formsViewer/README.md

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ When both are provided, `openParams` values override `securedParams` values.
5656
- `formDetails` - Expands to show each form field as a separate column
5757
- `activityDetails` - Expands to show each activity field as a separate column
5858
- `resourceDetails` - Expands to show each resource field as a separate column
59-
- **Example**: `time,user,formLabel,formDetails`
59+
- **Specific field names** - You can also specify individual field names (e.g., `SITE_NOTE_TITLE`, `SITE_NOTE_DETAILS`)
60+
- **Example (generic)**: `time,user,formLabel,formDetails`
61+
- **Example (specific fields)**: `formSubmitId,time,user,formLabel,SITE_NOTE_TITLE,SITE_NOTE_DETAILS`
6062
- **Default**: `time,user,formLabel,formDetails`
61-
- **Note**: When you specify `formDetails`, `activityDetails`, or `resourceDetails`, the plugin automatically creates a column for each field found in the data. For example, if your forms have `SITE_NOTE_TITLE` and `SITE_NOTE_DETAILS` fields, specifying `formDetails` will create two columns with those names.
63+
- **Note**: When you specify `formDetails`, `activityDetails`, or `resourceDetails`, the plugin automatically creates a column for each field found in the data. Alternatively, you can specify individual field names directly to control exactly which fields appear and in what order.
6264

6365
### Example Configurations
6466

@@ -67,37 +69,48 @@ When both are provided, `openParams` values override `securedParams` values.
6769
```json
6870
{
6971
"properties": {
70-
"activity": ["aid", "appt_number"],
71-
"provider": []
72+
"activity": ["aid", "appt_number"]
7273
},
7374
"securedParams": [
7475
{
7576
"name": "FORM_LABEL",
76-
"value": "Service Notes"
77+
"comment": "Service Notes"
7778
},
7879
{
7980
"name": "COLUMN_ORDER",
80-
"value": "time,user,formDetails"
81+
"comment": "formSubmitId,time,user,formLabel,SITE_NOTE_TITLE,SITE_NOTE_DETAILS"
8182
}
8283
]
8384
}
8485
```
8586

87+
This configuration will:
88+
- Filter to show only "Service Notes" forms
89+
- Display columns in this specific order: Submit ID, Time, User, Form Label, Site Note Title, and Site Note Details
90+
8691
#### Using openParams (Dynamic Configuration)
8792

8893
When opening the plugin programmatically, you can pass parameters dynamically:
8994

9095
```javascript
91-
// Open plugin with specific form filter
96+
// Open plugin with specific form filter and specific fields
9297
openPlugin({
9398
plugin: "formsViewer",
9499
openParams: {
95100
FORM_LABEL: "Service Notes",
96-
COLUMN_ORDER: "time,user,formDetails"
101+
COLUMN_ORDER: "formSubmitId,time,user,formLabel,SITE_NOTE_TITLE,SITE_NOTE_DETAILS"
102+
}
103+
});
104+
105+
// Open plugin showing all forms with generic formDetails expansion
106+
openPlugin({
107+
plugin: "formsViewer",
108+
openParams: {
109+
COLUMN_ORDER: "time,user,formLabel,formDetails"
97110
}
98111
});
99112

100-
// Open plugin showing all forms with different columns
113+
// Open plugin showing all forms with activityDetails fields
101114
openPlugin({
102115
plugin: "formsViewer",
103116
openParams: {
@@ -129,19 +142,26 @@ The plugin can be opened from:
129142

130143
### Form Details Display
131144

132-
The plugin dynamically creates columns based on the actual fields present in the submitted forms:
145+
The plugin supports two approaches for displaying form fields:
133146

134-
- **Dynamic Columns**: When you include `formDetails` in `COLUMN_ORDER`, the plugin scans all forms and creates a column for each unique field found
147+
#### 1. Generic Keywords (Dynamic Discovery)
148+
When you include `formDetails`, `activityDetails`, or `resourceDetails` in `COLUMN_ORDER`, the plugin scans all forms and creates a column for each unique field found.
149+
150+
**Example**: `COLUMN_ORDER: "time,user,formLabel,formDetails"`
151+
- The plugin will automatically discover and display all fields found in formDetails across all forms
152+
153+
#### 2. Specific Field Names (Explicit Control)
154+
You can specify individual field names directly in `COLUMN_ORDER` to control exactly which fields appear and in what order.
155+
156+
**Example**: `COLUMN_ORDER: "formSubmitId,time,user,formLabel,SITE_NOTE_TITLE,SITE_NOTE_DETAILS"`
157+
- Only the specified fields will be displayed, in the exact order given
158+
159+
#### Field Display Characteristics:
135160
- **Field Values**: Each form field value is displayed in its own column
136161
- **Simple Fields**: Text and numeric values displayed directly
137162
- **File References**: Shows filename for file attachments (e.g., signatures, photos)
138163
- **Missing Fields**: Shows "-" when a form doesn't have a particular field
139-
- **Sortable**: All dynamically created columns are sortable
140-
141-
**Example**: If you filter by "Service Notes" forms that have `SITE_NOTE_TITLE` and `SITE_NOTE_DETAILS` fields, the table will display:
142-
- Time | User | Form Label | SITE_NOTE_TITLE | SITE_NOTE_DETAILS
143-
144-
The same applies to `activityDetails` and `resourceDetails` - each field becomes its own column.
164+
- **Sortable**: All columns are sortable
145165

146166
## Use Cases
147167

samples/019-formsViewer/assets/js/custom.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,30 @@ export class CustomPlugin extends OFSPlugin {
304304
});
305305
});
306306
break;
307+
default:
308+
// Check if it's a specific field name from formDetails, activityDetails, or resourceDetails
309+
if (formDetailsFields.has(columnKey)) {
310+
columns.push({
311+
key: `formDetails.${columnKey}`,
312+
label: columnKey,
313+
sortable: true,
314+
isFormDetail: true
315+
});
316+
} else if (activityDetailsFields.has(columnKey)) {
317+
columns.push({
318+
key: `activityDetails.${columnKey}`,
319+
label: columnKey,
320+
sortable: true
321+
});
322+
} else if (resourceDetailsFields.has(columnKey)) {
323+
columns.push({
324+
key: `resourceDetails.${columnKey}`,
325+
label: columnKey,
326+
sortable: true
327+
});
328+
}
329+
// If not found in any collection, silently skip this column
330+
break;
307331
}
308332
});
309333

samples/019-formsViewer/descriptor.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"securedParams": [
99
{
1010
"name": "FORM_LABEL",
11-
"comment": "Service Notes"
11+
"value": "Service Notes"
1212
},
1313
{
1414
"name": "COLUMN_ORDER",
15-
"comment": "formSubmitId, time, user, formLabel,SITE_NOTE_TITLE, SITE_NOTE_DETAILS"
15+
"value": "formSubmitId, time, user, formLabel, SITE_NOTE_TITLE, SITE_NOTE_DETAILS"
1616
}
1717
]
1818
}

samples/019-formsViewer/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/019-formsViewer/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"webpack-cli": "^5.0.1"
3030
},
3131
"dependencies": {
32-
"@ofs-users/plugin": "^1.5.0",
32+
"@ofs-users/plugin": "^1.5.1",
3333
"@ofs-users/proxy": "^1.20.1",
3434
"buffer": "^6.0.3"
3535
}
36-
}
36+
}

0 commit comments

Comments
 (0)