Skip to content

Commit

Permalink
VingRecord.propOptions() now returns validation options S3File relati…
Browse files Browse the repository at this point in the history
…ons in the form of acceptedFileExtensions.

* VingRecord.describe().meta no longer includes the acceptedFileExtensions on S3File relations.
  • Loading branch information
rizen committed Oct 27, 2024
1 parent 8f0ca3e commit 9235456
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/pages/user/settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<FormInput type="select" @change="currentUser.save('avatarType')" v-model="currentUser.props.avatarType"
:options="currentUser.options?.avatarType" name="avatarType" label="Avatar" class="mb-4" />
<div v-if="currentUser.props.avatarType == 'uploaded'" class="mb-4">
<Dropzone id="avatar" :acceptedFiles="currentUser.meta?.acceptedFileExtensions?.avatar"
<Dropzone id="avatar" :acceptedFiles="currentUser.options?.avatar"
:afterUpload="currentUser.importAvatar" :maxFiles="1" :resizeHeight="300"
:resizeWidth="300" resizeMethod="crop"></Dropzone>
</div>
Expand Down
3 changes: 3 additions & 0 deletions ving/docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ outline: deep

### 2024-10-27
* Added ego behavior to useVingRecord() and useVingKind() to allow disambiguation of multiple copies of the same record with different views.
* VingRecord.propOptions() now returns validation options S3File relations in the form of acceptedFileExtensions.
* VingRecord.describe().meta no longer includes the acceptedFileExtensions on S3File relations.
* NOTE: If you are using `record.meta.acceptedFileExtensions` in your UI, you will need to change it to `record.options.relationName` instead. For example `record.meta.acceptedFileExtensions.avatar` would become `record.options.avatar`.

### 2024-10-25
* Fix a bug in redis client where it wouldn't connect to the AWS valkey/redis cluster.
Expand Down
4 changes: 2 additions & 2 deletions ving/docs/subsystems/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ Creates a user interface for uploading [S3Files](/rest/S3File). It handles the r
Props:

- **acceptedFiles** - An array of file extensions that S3File should accept. Defaults to `['png','jpg']`. This can and should be automatically filled by a `meta.acceptedFileExtensions` property from a [Ving Record](ving-record) when dealing with S3Files. It is set by the `relation.acceptedFileExtensions` attribute in a [Ving Schema](ving-schema). For example:
- **acceptedFiles** - An array of file extensions that S3File should accept. Defaults to `['png','jpg']`. This can and should be automatically filled by property such as `options.avatar` which will be generated when enabling `options` on a [Ving Record](ving-record) when dealing with S3Files. It is set by the `relation.acceptedFileExtensions` attribute in a [Ving Schema](ving-schema). For example:

```html
<Dropzone :acceptedFiles="user.meta?.acceptedFileExtensions?.avatar" />
<Dropzone :acceptedFiles="user.options?.avatar" />
```
- **afterUpload** - Required. A function that will be executed after upload. This function should then call the appropriate import endpoint to post process and verify the file.
- **info** - A string that will be displayed inside the dropzone box. Useful to give the user some insights about the nature of the files you will allow such as size or dimension contstraints.
Expand Down
3 changes: 2 additions & 1 deletion ving/docs/subsystems/ving-record.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ const user = apikey.parent('user');
```
#### propOptions
Returns a list of enumeration options for this record.
Returns a list of validation options for fields in this record.
```js
const options = await user.propOptions(params, false);
Expand All @@ -442,6 +442,7 @@ const options = await user.propOptions(params, false);
{ label : 'Username', value : 'username' },
...
],
avatar : [ 'png', 'jpg' ],
...
}
```
Expand Down
2 changes: 1 addition & 1 deletion ving/generator/nuxtpages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const editProps = (schema) => {
else if (prop.type == 'id' && prop?.relation?.type == 'parent' && prop.relation?.kind == 'S3File') {
out += `
<div class="mb-4">
<Dropzone id="${prop?.relation?.name}" :acceptedFiles="${schema.kind.toLowerCase()}.meta?.acceptedFileExtensions?.${prop?.relation?.name}" :afterUpload="(s3file) => ${schema.kind.toLowerCase()}.importS3File('${prop?.relation?.name}', s3file.props?.id)"
<Dropzone id="${prop?.relation?.name}" :acceptedFiles="${schema.kind.toLowerCase()}.options?.${prop?.relation?.name}" :afterUpload="(s3file) => ${schema.kind.toLowerCase()}.importS3File('${prop?.relation?.name}', s3file.props?.id)"
:maxFiles="1" :resizeHeight="300" :resizeWidth="300" resizeMethod="crop"></Dropzone>
</div>`;
}
Expand Down
13 changes: 7 additions & 6 deletions ving/record/VingRecord.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@ export class VingRecord {
const parent = await this.parent(field.relation.name);
out.related[field.relation.name] = await parent.describe(params);
}
if (isObject(out.meta) && 'acceptedFileExtensions' in field.relation) {
if (!('acceptedFileExtensions' in out.meta))
out.meta.acceptedFileExtensions = {};
out.meta.acceptedFileExtensions[field.relation.name] = field.relation.acceptedFileExtensions;
}
}

}
Expand Down Expand Up @@ -418,7 +413,7 @@ export class VingRecord {
}

/**
* Returns a list of the enumerated prop options available to the current user
* Returns a list of the enumerated prop options available to the current user. These options can be used to validate the data submitted to this field.
*
* @param {Object} params A list of params to change the output of the describe. Defaults to `{}`
* @param {Object} params.currentUser The `User` or `Session` instance to test ownership against
Expand Down Expand Up @@ -453,6 +448,12 @@ export class VingRecord {
else if (prop.options) {
options[prop.name] = await this[prop.options]();
}
else if (prop.relation
&& ['parent', 'sibling'].includes(prop.relation.type)
&& 'acceptedFileExtensions' in prop.relation
) {
options[prop.relation.name] = prop.relation.acceptedFileExtensions;
}
}
return options;
}
Expand Down

0 comments on commit 9235456

Please sign in to comment.