@nocobase/plugin-field-sort 1.5.0-beta.8 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,12 +8,12 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.5.0-beta.8",
12
- "@nocobase/database": "1.5.0-beta.8",
13
- "@nocobase/actions": "1.5.0-beta.8",
14
- "@nocobase/server": "1.5.0-beta.8",
15
- "@nocobase/data-source-manager": "1.5.0-beta.8",
11
+ "@nocobase/client": "1.5.0",
16
12
  "lodash": "4.17.21",
13
+ "@nocobase/database": "1.5.0",
14
+ "@nocobase/actions": "1.5.0",
15
+ "@nocobase/server": "1.5.0",
16
+ "@nocobase/data-source-manager": "1.5.0",
17
17
  "sequelize": "6.35.2",
18
- "@nocobase/lock-manager": "1.5.0-beta.8"
18
+ "@nocobase/lock-manager": "1.5.0"
19
19
  };
@@ -30,6 +30,7 @@ __export(action_exports, {
30
30
  move: () => move
31
31
  });
32
32
  module.exports = __toCommonJS(action_exports);
33
+ var import_lodash = require("lodash");
33
34
  var import_database = require("@nocobase/database");
34
35
  var import_sort_field = require("./sort-field");
35
36
  async function move(ctx, next) {
@@ -78,42 +79,42 @@ class SortableCollection {
78
79
  }
79
80
  // insert source position to target position
80
81
  async move(sourceInstanceId, targetInstanceId, options = {}) {
81
- const sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
82
+ let sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
82
83
  const targetInstance = await this.collection.repository.findByTargetKey(targetInstanceId);
83
84
  if (this.scopeKey && sourceInstance.get(this.scopeKey) !== targetInstance.get(this.scopeKey)) {
84
- await sourceInstance.update({
85
- [this.scopeKey]: targetInstance.get(this.scopeKey)
85
+ [sourceInstance] = await this.collection.repository.update({
86
+ filterByTk: sourceInstanceId,
87
+ values: {
88
+ [this.scopeKey]: targetInstance.get(this.scopeKey)
89
+ }
86
90
  });
87
91
  }
88
92
  await this.sameScopeMove(sourceInstance, targetInstance, options);
89
93
  }
90
94
  async changeScope(sourceInstanceId, targetScope, method) {
91
- const sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
95
+ let sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
92
96
  const targetScopeValue = targetScope[this.scopeKey];
93
97
  if (targetScopeValue && sourceInstance.get(this.scopeKey) !== targetScopeValue) {
94
- await sourceInstance.update(
95
- {
98
+ [sourceInstance] = await this.collection.repository.update({
99
+ filterByTk: sourceInstanceId,
100
+ values: {
96
101
  [this.scopeKey]: targetScopeValue
97
102
  },
98
- {
99
- silent: false
100
- }
101
- );
103
+ silent: false
104
+ });
102
105
  if (method === "prepend") {
103
106
  await this.sticky(sourceInstanceId);
104
107
  }
105
108
  }
106
109
  }
107
110
  async sticky(sourceInstanceId) {
108
- const sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
109
- await sourceInstance.update(
110
- {
111
+ await this.collection.repository.update({
112
+ filterByTk: sourceInstanceId,
113
+ values: {
111
114
  [this.field.get("name")]: 0
112
115
  },
113
- {
114
- silent: true
115
- }
116
- );
116
+ silent: true
117
+ });
117
118
  }
118
119
  async sameScopeMove(sourceInstance, targetInstance, options) {
119
120
  const fieldName = this.field.get("name");
@@ -151,14 +152,13 @@ class SortableCollection {
151
152
  by: change,
152
153
  silent: true
153
154
  });
154
- await sourceInstance.update(
155
- {
155
+ await this.collection.repository.update({
156
+ filterByTk: this.collection.isMultiFilterTargetKey() ? (0, import_lodash.pick)(sourceInstance, this.collection.filterTargetKey) : sourceInstance.get(this.collection.filterTargetKey),
157
+ values: {
156
158
  [fieldName]: targetSort
157
159
  },
158
- {
159
- silent: true
160
- }
161
- );
160
+ silent: true
161
+ });
162
162
  }
163
163
  }
164
164
  // Annotate the CommonJS export names for ESM import in node:
@@ -68,16 +68,6 @@ class SortField extends import_database.Field {
68
68
  };
69
69
  initRecordsSortValue = async (options) => {
70
70
  const { transaction } = options;
71
- const orderField = (() => {
72
- const model = this.collection.model;
73
- if (model.primaryKeyAttribute) {
74
- return model.primaryKeyAttribute;
75
- }
76
- if (model.rawAttributes["createdAt"]) {
77
- return model.rawAttributes["createdAt"].field;
78
- }
79
- throw new Error(`can not find order key for collection ${this.collection.name}`);
80
- })();
81
71
  const needInit = async (scopeKey2 = null, scopeValue = null) => {
82
72
  const filter = {};
83
73
  if (scopeKey2 && scopeValue) {
@@ -97,6 +87,19 @@ class SortField extends import_database.Field {
97
87
  return emptyCount === totalCount && emptyCount > 0;
98
88
  };
99
89
  const doInit = async (scopeKey2 = null, scopeValue = null) => {
90
+ const orderField = (() => {
91
+ const model = this.collection.model;
92
+ if (model.primaryKeyAttribute) {
93
+ const primaryKeyAttribute = model.rawAttributes[model.primaryKeyAttribute];
94
+ if (primaryKeyAttribute.autoIncrement) {
95
+ return primaryKeyAttribute.field;
96
+ }
97
+ }
98
+ if (model.rawAttributes["createdAt"]) {
99
+ return model.rawAttributes["createdAt"].field;
100
+ }
101
+ throw new Error(`can not find order key for collection ${this.collection.name}`);
102
+ })();
100
103
  const queryInterface = this.collection.db.sequelize.getQueryInterface();
101
104
  if (scopeKey2) {
102
105
  const scopeAttribute = this.collection.model.rawAttributes[scopeKey2];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-field-sort",
3
- "version": "1.5.0-beta.8",
3
+ "version": "1.5.0",
4
4
  "license": "AGPL-3.0",
5
5
  "displayName": "Collection field: Sort",
6
6
  "displayName.zh-CN": "数据表字段:排序",
@@ -20,5 +20,5 @@
20
20
  "keywords": [
21
21
  "Collection fields"
22
22
  ],
23
- "gitHead": "eb7db7301ac5eed305e73540884611832bc761f6"
23
+ "gitHead": "1eae52e1fc837e9b1c6b63fc31bda7945b6101e9"
24
24
  }