Skip to content

Commit

Permalink
Added recordsAsOptions() method to the useVingKind() composable.
Browse files Browse the repository at this point in the history
  • Loading branch information
rizen committed Apr 10, 2024
1 parent 4466629 commit d07a510
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions composables/useVingKind.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,23 @@ class VingKind {
return this.records[index].partialUpdate(props, options);
}

/**
* Turns the list of records into an array compatible with various components such as FormSelect and Autocomplete
* Usage: `users.recordsAsOptions('meta','displayName')`
*
* @param {'props'|'meta'|'extra'} section One of the describe section names such as `props`, or `meta`, or `extra`.
* @param {string} field The name of the field within the `section` that will serve as the labelf for this option list.
* @returns {Object[]} An array of objects with `label` and `value` attributes.
*/
recordsAsOptions(section, field) {
return this.records.map(u => {
return {
value: u.props?.id,
label: u[section][field]
}
})
}

/**
* Remove a record from `records` locally, but not delete it from the server.
*
Expand Down
1 change: 1 addition & 0 deletions docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ outline: deep
## 2024-04-10
* Implemented: filterQualifier: true should be in the examples for all relation ids #96
* Implemented: add documentation to ving schema about filterQuery #87
* Added recordsAsOptions() method to the useVingKind() composable.

## 2024-04-09
* Fixed: no type int example in ving schema #82
Expand Down

0 comments on commit d07a510

Please sign in to comment.