AdobeDocs / uxp

Documentation for UXP
Apache License 2.0
15 stars 7 forks source link

Wrong parameters and examples in `FileSystemProvider.getFileForSaving()` #53

Closed pklaschka closed 2 years ago

pklaschka commented 3 years ago

Expected Behaviour

In uxp/src/pages/uxp/reference-js/Modules/uxp/Persistent File Storage/FileSystemProvider.md, the documentation should reflect the APIs behavior, which (tested in both PS and XD in their current versions) differs between docs and actual behavior. The old XD docs actually document the correct behavior.

What the docs should look like (based on the actual behavior) ## getFileForSaving(suggestedName, options) Gets a file reference suitable for read-write by displaying a "Save" file picker dialog to the user. If the act of writing to the file would overwrite it, the file picker will prompt the user to confirm before returning a result to you. **Returns**: `Promise` - returns the selected file, or `null` if canceled | Param | Type | Description | | --- | --- | --- | | suggestedName | `string` | Required. The file extension should match one of the options specified in the `types` option. | | options | `Object` | | | [options.types] | `Array` | Allowed file extensions, with no "." prefix. | | [options.initialDomain] | `Symbol` | the preferred initial location of the file picker. If not defined, the most recently used domain from a file picker is used instead. | **Example** ```js const file = await fs.getFileForSaving("output.txt", { types: [ "txt" ]}); if (!file) { // file picker was cancelled return; } await file.write("It was a dark and stormy night"); ```

Actual Behaviour

Issues with the current documentation:

=> Overall, without looking back at adobexdplatform.com (or my old code based on the info from there), there would have been no way for me to discover the actual working solution from either the docs or anywhere else (there's also no way to discover correct arguments via dev tools, etc., after all, meaning the only option would have been a lot of trial and error).

Reproduce Scenario (including but not limited to)

Steps to Reproduce

Platform and Version

(both Windows 10)

Sample Code that illustrates the problem

// from docs example
const [file] = await fs.getFileForSaving({ types = [ "txt" ]}); // syntax error 😜 

// docs without syntax error
const [file] = await fs.getFileForSaving({ types: [ "txt" ]}); // doesn't work, fails silently

// works
const file = await fs.getFileForSaving({ types: [ "txt" ]}); // works

Logs taken while reproducing the problem

n/a

pklaschka commented 3 years ago

(There are also a few similar issues with the other functions, including, but not limited to, a syntax error in the getFileForOpening which, e.g., also includes the code example syntax error; getFileForSasving is just something I recently used and therefore took a closer look at)