nocobase/packages/plugins/@nocobase/plugin-action-import
ChengLei Shao 2063227f4a
refactor: export & import plugin (#4468)
* feat: chunk method in repository

* chore: xlsx export test

* chore: xlsx export

* chore: export action

* chore: export action

* chore: code

* feat: database interface manager

* feat: export with ui schema

* chore: console.log

* chore: export with china region field

* chore: export with attachments

* chore: export with multiple select

* chore: export with interface

* chore: export action

* fix: export with datetime file

* chore: limit export action running in same time

* chore: yarn.lock

* fix: render json value

* chore: chunk with limit

* feat: add EXPORT_LIMIT env config

* fix: typo

* fix: type

* chore: asyn mutex version

* chore: test

* chore: test

* fix: export null value

* chore: test

* chore: createdAt test

* fix: export with createdAt

* chore: import template

* chore: xlsx importer

* chore: import run

* chore: export with data source api

* chore: toValue api in interface

* fix: build

* chore: import with transaction

* fix: build database

* chore: many to one interface

* chore: code

* chore: import with associations

* chore: default toValue

* chore: import template with explain

* chore: import with explain template

* chore: reset id seq after import

* chore: download template action

* fix: database build

* fix: build

* fix: build

* fix: test

* chore: import with number field

* chore: import with boolean field

* chore: json interface

* chore: import action

* chore: typo

* chore: i18n

* chore: select interface

* chore: china region interface

* chore: datetiem field

* chore: cast to array

* fix: import tips

* chore: import await

* fix: test

* fix: test in mariadb

* chore: comments

* chore: comments

* fix: parse date with empty string

* fix: read import limit

* fix: type

* fix: test in mariadb

* chore: skip bigint test in sqlite

* chore: skip bigint test in sqlite

* chore: download tip i18n keys

* fix: download tips

* feat(client): add new variable named 'URL search params' and support link action (#4506)

* feat: support link action

* feat(client): add new variable named 'URL search params'

* chore: add translation

* fix: avoid crashing

* chore: fix failed test

* feat: link action

* feat: link action

* fix: remove filter parameters with undefined values

* feat: link action

* feat: add support for default values in filter form fields

* refactor: code improve

* refactor: locale improve

* refactor: locale improve

* test: add e2e test

* refactor: locale improve

* refactor: locale improve

* fix: resolve operation issues with variables

* refactor: code improve

* chore: enable direct selection of variables as default value

* chore: use qs to parse query string

* fix: menu selectKeys (T-4373)

* refactor: use qs to stringify search params

* refactor: locale improve

* refactor: locale improve

* chore: fix failed tests

* fix: resolve issue where setting Data scope is not work

* chore: fix failed e2e tests

* chore: make e2e tests more stable

* chore: add translation

* chore: make e2e tests more stable

* fix: resolve the issue of error when saving data scope

* feat: trigger variable parsing after context change

* test: add unit tests

* test: add e2e test

* refactor: extract template

* chore: fix failed unit tests

* chore: fix failed e2e test

* fix(Link): hide linkage rules in top link (T-4410)

* fix(permission): remove URL search params variable from data scope

* chore: make more stable

* chore: make e2e test more stable

* fix(Link): reduce size for variable

* fix: clear previous context (T-4449)

* fix(calendar, map): resolve initial data scope setting error (T-4450)

* fix: correct concatenation of query string (T-4453)

---------

Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: jack zhang <1098626505@qq.com>

* refactor(FormV2): add FormWithDataTemplates component (#4551)

* Revert "fix(client): fix data template style (#4536)"

This reverts commit db66090ab2.

* refactor(FormV2): add FormWithDataTemplates component

* chore: fix failed e2e tests

* chore: make e2e test more stable

* chore: import warning i18n

* chore: import warning i18n

* fix: bug

* fix: export action loading

* fix: bug

* chore: map field interface

* fix: merge bug

---------

Co-authored-by: xilesun <2013xile@gmail.com>
Co-authored-by: Zeke Zhang <958414905@qq.com>
Co-authored-by: katherinehhh <katherine_15995@163.com>
Co-authored-by: jack zhang <1098626505@qq.com>
2024-06-05 17:52:43 +08:00
..
src refactor: export & import plugin (#4468) 2024-06-05 17:52:43 +08:00
.npmignore chore(versions): 😊 publish v1.0.0-alpha.1 (#4186) 2024-04-29 00:46:21 +08:00
client.d.ts chore(versions): 😊 publish v1.0.0-alpha.1 (#4186) 2024-04-29 00:46:21 +08:00
client.js chore(versions): 😊 publish v1.0.0-alpha.1 (#4186) 2024-04-29 00:46:21 +08:00
LICENSE chore(versions): 😊 publish v1.0.0-alpha.1 (#4186) 2024-04-29 00:46:21 +08:00
package.json refactor: export & import plugin (#4468) 2024-06-05 17:52:43 +08:00
README.md chore(versions): 😊 publish v1.0.0-alpha.1 (#4186) 2024-04-29 00:46:21 +08:00
README.zh-CN.md chore(versions): 😊 publish v1.0.0-alpha.1 (#4186) 2024-04-29 00:46:21 +08:00
server.d.ts chore(versions): 😊 publish v1.0.0-alpha.1 (#4186) 2024-04-29 00:46:21 +08:00
server.js chore(versions): 😊 publish v1.0.0-alpha.1 (#4186) 2024-04-29 00:46:21 +08:00

import

English | 中文

Excel 数据导入插件。

安装激活

内置插件无需手动安装激活。

导入说明

数字类型字段

支持数字和百分比,N/A- 的文案会被过滤掉

数字1 百分比 数字2 数字3
123 25% N/A -

转 JSON 之后为

{
  "数字1": 123,
  "百分比": 0.25,
  "数字2": null,
  "数字3": null,
}

布尔类型字段

输入文案支持(英文不区分大小写):

  • Yes Y True 1
  • No N False 0
字段1 字段2 字段3 字段4 字段4
Y true 0

转 JSON 之后为

{
  "字段1": false,
  "字段2": true,
  "字段3": true,
  "字段4": true,
  "字段5": false,
}

日期类型字段

DateOnly Local(+08:00) GMT
2023-01-18 22:22:22 2023-01-18 22:22:22 2023-01-18 22:22:22

转 JSON 之后为

{
  "DateOnly": "2023-01-18T00:00:00.000Z",
  "Local(+08:00)": "2023-01-18T14:22:22.000Z",
  "GMT": "2023-01-18T22:22:22.000Z",
}

选择类型字段

选项值和选项标签都可作为导入文案,多个选项之间以以逗号(, )或顿号()区分

如字段 优先级 的可选项包括:

选项值 选项标签
low
medium
high

选项值和选项标签都可作为导入文案

优先级
low

转 JSON 之后为

[
  { "优先级": "high" },
  { "优先级": "low" },
]

中国行政区字段

地区1 地区2
北京市/市辖区 天津市/市辖区

转 JSON 之后为

{
  "地区1": ["11","1101"],
  "地区2": ["12","1201"]
}

附件字段

附件
https://www.nocobase.com/images/logo.png

转 JSON 之后为

{
  "附件": [
    {
      "filename": "logo.png",
      "title": "logo.png",
      "extname": ".png",
      "url": "https://www.nocobase.com/images/logo.png"
    }
  ]
}

关系类型字段

多条数据以逗号(, )或顿号()区分

部门/名称 分类/标题
开发组 分类1、分类2

转 JSON 之后为

{
  "部门": [1], // 1 为部门名称为「开发组」的记录 ID
  "分类": [1,2], // 1,2 为分类标题为「分类1」和「分类2」的记录 ID
}

JSON 类型字段

JSON1
{"key":"value"}

转 JSON 之后为

{
  "JSON": {"key":"value"}
}

地图几何图形类型

Point Line Polygon Circle
1,2 (1,2),(3,4) (1,2),(3,4),(1,2) 1,2,3

转 JSON 之后为

{
  "Point": [1,2],
  "Line": [[1,2], [3,4]],
  "Polygon": [[1,2], [3,4], [1,2]],
  "Circle": [1,2,3]
}

自定义导入格式

通过 db.registerFieldValueParsers() 方法注册自定义的 ValueParser,如:

import { BaseValueParser } from '@nocobase/database';

class PointValueParser extends BaseValueParser {
  async setValue(value) {
    if (Array.isArray(value)) {
      this.value = value;
    } else if (typeof value === 'string') {
      this.value = value.split(',');
    } else {
      this.errors.push('Value invalid');
    }
  }
}

const db = new Database();

// type=point 的字段导入时,将通过 PointValueParser 解析数据
db.registerFieldValueParsers({
  point: PointValueParser,
});

导入示例

Point
1,2

转 JSON 之后为

{
  "Point": [1,2]
}