-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from lowdefy/community-plugin-xlsx
feat: Add community-plugin-xlsx.
- Loading branch information
Showing
8 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@lowdefy/community-plugin-xlsx': major | ||
'@lowdefy/community-plugin-docs': minor | ||
--- | ||
|
||
Added community-plugin-xlsx. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
_ref: | ||
path: templates/general.yaml.njk | ||
vars: | ||
pageId: DownloadXlsx | ||
pageTitle: DownloadXlsx | ||
section: '@lowdefy/community-plugin-xlsx' | ||
content: | ||
- id: markdown | ||
type: MarkdownWithCode | ||
properties: | ||
content: | | ||
The `DownloadXlsx` action implements [write-excel-file](https://www.npmjs.com/package/write-excel-file) for writing `*.xlsx` files. | ||
- _ref: | ||
path: templates/plugin_usage.yaml | ||
vars: | ||
name: '@lowdefy/community-plugin-xlsx' | ||
packageJsonPath: ../../plugins/community-plugin-xlsx/package.json | ||
- id: xlsx_button | ||
type: Button | ||
style: | ||
margin: 40px | ||
maxWidth: 300 | ||
properties: | ||
title: Excel Download | ||
icon: AiOutlineDownload | ||
size: large | ||
block: true | ||
shape: round | ||
type: default | ||
events: | ||
onClick: | ||
- id: download_xlsx | ||
type: DownloadXlsx | ||
params: | ||
fileName: download.xlsx | ||
dateFormat: 'DD/MM/YYYY' | ||
data: | ||
- Category: a | ||
Amount: 10 | ||
Date: | ||
_date: 2023-01-26 | ||
- Category: b | ||
Amount: 20 | ||
Date: | ||
_date: 2023-01-27 | ||
- Category: c | ||
Amount: 30 | ||
Date: | ||
_date: 2023-01-28 | ||
schema: | ||
- column: Category Name | ||
value: Category | ||
type: String | ||
width: 20 | ||
- column: Amount Made | ||
value: Amount | ||
type: Number | ||
width: 20 | ||
- column: Date Created | ||
value: Date | ||
type: Date | ||
width: 20 | ||
- id: markdown | ||
type: MarkdownWithCode | ||
properties: | ||
content: | | ||
#### Properties | ||
- `data: object[]`: An array of rows containing data. | ||
- `fileName: string`: The name the file will be saved as when downloaded. | ||
- `schema: object[]`: A schema to describe each column. | ||
- `dateFormat: string`: The format of dates in the file. | ||
See [write-excel-file](https://www.npmjs.com/package/write-excel-file) for additional properties. | ||
### Examples | ||
###### Defined data. | ||
```yaml | ||
id: xlsx_button | ||
type: Button | ||
properties: | ||
title: Excel Download | ||
events: | ||
onClick: | ||
- id: download_xlsx | ||
type: DownloadXlsx | ||
params: | ||
fileName: download.xlsx | ||
dateFormat: 'DD/MM/YYYY' | ||
data: | ||
- Category: a | ||
Amount: 10 | ||
Date: | ||
_date: 2023-01-26 | ||
- Category: b | ||
Amount: 20 | ||
Date: | ||
_date: 2023-01-27 | ||
- Category: c | ||
Amount: 30 | ||
Date: | ||
_date: 2023-01-28 | ||
schema: | ||
- column: Category Name | ||
value: Category | ||
type: String | ||
width: 20 | ||
- column: Amount Made | ||
value: Amount | ||
type: Number | ||
width: 20 | ||
- column: Date Created | ||
value: Date | ||
type: Date | ||
width: 20 | ||
``` | ||
###### Request data. | ||
```yaml | ||
id: xlsx_button | ||
type: Button | ||
properties: | ||
title: Excel Download | ||
events: | ||
onClick: | ||
- id: get_data | ||
type: Request | ||
params: get_data | ||
- id: download_xlsx | ||
type: DownloadXlsx | ||
params: | ||
fileName: download.xlsx | ||
dateFormat: 'DD/MM/YYYY' | ||
data: | ||
_request: get_data | ||
schema: | ||
- column: Category Name | ||
value: Category | ||
type: String | ||
width: 20 | ||
- column: Amount Made | ||
value: Amount | ||
type: Number | ||
width: 20 | ||
- column: Date Created | ||
value: Date | ||
type: Date | ||
width: 20 | ||
``` | ||
###### Schema columns with functions. | ||
```yaml | ||
id: xlsx_button | ||
type: Button | ||
properties: | ||
title: Excel Download | ||
events: | ||
onClick: | ||
- id: get_data | ||
type: Request | ||
params: get_data | ||
- id: download_xlsx | ||
type: DownloadXlsx | ||
params: | ||
fileName: download.xlsx | ||
dateFormat: 'DD/MM/YYYY' | ||
data: | ||
_request: get_data | ||
schema: | ||
- column: Category Name | ||
value: | ||
_function: | ||
__args: 0.Category | ||
type: String | ||
width: 20 | ||
- column: Amount Made | ||
value: | ||
_function: | ||
__args: 0.Amount | ||
type: Number | ||
width: 20 | ||
- column: Date Created | ||
value: Date | ||
type: Date | ||
width: 20 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@lowdefy/community-plugin-xlsx", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"type": "module", | ||
"exports": { | ||
"./actions": "./dist/actions.js", | ||
"./types": "./dist/types.js" | ||
}, | ||
"files": [ | ||
"dist/*" | ||
], | ||
"scripts": { | ||
"build": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start --copy-files", | ||
"prepare": "pnpm build" | ||
}, | ||
"dependencies": { | ||
"@lowdefy/helpers": "4.0.0-rc.10", | ||
"write-excel-file": "1.4.27" | ||
}, | ||
"devDependencies": { | ||
"@swc/cli": "0.1.57", | ||
"@swc/core": "1.2.194" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as DownloadXlsx } from './actions/DownloadXlsx.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { type } from '@lowdefy/helpers'; | ||
import writeXlsxFile from 'write-excel-file'; | ||
|
||
async function DownloadXlsx({ params }) { | ||
const { data, fileName, schema, ...options } = params; | ||
|
||
if (!type.isArray(data) || !type.isObject(data[0])) { | ||
throw new Error('Data should be an array of objects.'); | ||
} | ||
|
||
const colTypes = { | ||
String: String, | ||
Number: Number, | ||
Boolean: Boolean, | ||
Date: Date, | ||
}; | ||
|
||
await writeXlsxFile(data, { | ||
fileName: !type.isString(fileName) ? 'download.xlsx' : fileName, | ||
schema: | ||
type.isArray(schema) && | ||
schema.map((column) => ({ | ||
...column, | ||
value: type.isString(column.value) ? (row) => row[column.value] : column.value, | ||
type: column.type ? colTypes[column.type] : undefined, | ||
})), | ||
...options, | ||
}); | ||
|
||
return; | ||
} | ||
|
||
export default DownloadXlsx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as actions from './actions.js'; | ||
|
||
export default { | ||
actions: Object.keys(actions), | ||
}; |