13ab9007f6
* Add workflow_call event * Add tests-daily-run.yml * Remove workflow version * Update input value * Remove secrets from caller workflow * Rename job * Check context * Check context * Check workflow_call inputs * Override github.event_name with inputs.trigger * Fix input name * Add config for daily e2e tests with Gutenberg * Update env commands for Gutenberg run * Add disableHpos env variable in ci-utils * Revert the trigger to push * Revert the env variable setting in ci-jobs * Revert the env variable setting in ci-jobs * Rebuild utils * Update test env start command * Define the Gutenberg Playwright project * Use path relative to workspace root * Update events for test projects * Update events for test projects * Add changelogs * Remove the e2e tests with Gutenberg tests from daily runs * Set the schedule and workflow_dispatch triggers * Add --project default flag to only run the default tests in CI * Renamed snapshots to match the new Playwright project name |
||
---|---|---|
.. | ||
changelog | ||
src | ||
typings | ||
.eslintrc.js | ||
.npmrc | ||
.prettierrc.js | ||
CHANGELOG.md | ||
PREVIOUS_CHANGELOG.md | ||
README.md | ||
babel.config.js | ||
composer.json | ||
composer.lock | ||
jest.config.json | ||
package.json | ||
tsconfig-cjs.json | ||
tsconfig.json |
README.md
CSV Export
A set of functions to convert data into CSV values, and enable a browser download of the CSV data.
Installation
Install the module
pnpm install @woocommerce/csv-export --save
Usage
onClick = () => {
// Create a file name based on a title and optional query. Will return a timestamped
// name, for example: revenue-2018-11-01-interval-month.csv
const name = generateCSVFileName( 'revenue', { interval: 'month' } );
// Create a string of CSV data, `headers` is an array of row headers, put at the top
// of the file. `rows` is a 2 dimensional array. Each array is a line in the file,
// separated by newlines. The second-level arrays are the data points in each row.
// For header format, see https://woocommerce.github.io/woocommerce-admin/#/components/table?id=headers-2
// For rows format, see https://woocommerce.github.io/woocommerce-admin/#/components/table?id=rows-1
const data = generateCSVDataFromTable( headers, rows );
// Triggers a browser UI to save a file, named the first argument, with the contents of
// the second argument.
downloadCSVFile( name, data );
}
generateCSVDataFromTable(headers, rows) ⇒ String
Generates a CSV string from table contents
Returns: String
- Table contents in a CSV format
Param | Type | Description |
---|---|---|
headers | Array.<Object> |
Object with table header information |
rows | Array.Array.<Object> |
Object with table rows information |
generateCSVFileName([name], [params]) ⇒ String
Generates a file name for CSV files based on the provided name, the current date and the provided params, which are all appended with hyphens.
Returns: String
- Formatted file name
Param | Type | Default | Description |
---|---|---|---|
[name] | String |
'' |
Name of the file |
[params] | Object |
{} |
Object of key-values to append to the file name |
downloadCSVFile(fileName, content)
Downloads a CSV file with the given file name and contents
Param | Type | Description |
---|---|---|
fileName | String |
Name of the file to download |
content | String |
Contents of the file to download |