@nocobase/plugin-ui-templates 2.1.0-beta.33 → 2.1.0-beta.35

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,17 +8,17 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.1.0-beta.33",
12
- "@nocobase/flow-engine": "2.1.0-beta.33",
11
+ "@nocobase/client": "2.1.0-beta.35",
12
+ "@nocobase/flow-engine": "2.1.0-beta.35",
13
13
  "react": "18.2.0",
14
14
  "antd": "5.24.2",
15
15
  "@ant-design/icons": "5.6.1",
16
16
  "lodash": "4.18.1",
17
17
  "@formily/react": "2.3.7",
18
- "@nocobase/server": "2.1.0-beta.33",
19
- "@nocobase/plugin-flow-engine": "2.1.0-beta.33",
20
- "@nocobase/utils": "2.1.0-beta.33",
18
+ "@nocobase/server": "2.1.0-beta.35",
19
+ "@nocobase/plugin-flow-engine": "2.1.0-beta.35",
20
+ "@nocobase/utils": "2.1.0-beta.35",
21
21
  "@formily/core": "2.3.7",
22
- "@nocobase/database": "2.1.0-beta.33",
23
- "@nocobase/actions": "2.1.0-beta.33"
22
+ "@nocobase/database": "2.1.0-beta.35",
23
+ "@nocobase/actions": "2.1.0-beta.35"
24
24
  };
@@ -142,17 +142,33 @@ class PluginBlockReferenceServer extends import_server.Plugin {
142
142
  });
143
143
  }
144
144
  };
145
- const removeUsagesByInstance = async (instanceUid, _options, { transaction } = {}) => {
145
+ const removeUsagesByInstances = async (instanceUids, { transaction } = {}) => {
146
146
  const usageRepo = this.db.getRepository("flowModelTemplateUsages");
147
- await usageRepo.destroy({ filter: { modelUid: instanceUid }, transaction });
147
+ const uids = import_lodash.default.uniq(instanceUids.map(String).filter(Boolean));
148
+ for (const chunk of import_lodash.default.chunk(uids, 500)) {
149
+ await usageRepo.destroy({
150
+ filter: {
151
+ modelUid: {
152
+ $in: chunk
153
+ }
154
+ },
155
+ transaction
156
+ });
157
+ }
148
158
  };
149
159
  this.db.on("flowModels.afterDestroy", async (instance, { transaction } = {}) => {
150
- var _a2, _b;
160
+ var _a2;
151
161
  const instanceUid = ((_a2 = instance == null ? void 0 : instance.get) == null ? void 0 : _a2.call(instance, "uid")) || (instance == null ? void 0 : instance.uid);
152
162
  if (!instanceUid) return;
153
- const options = parseOptions(((_b = instance == null ? void 0 : instance.get) == null ? void 0 : _b.call(instance, "options")) || (instance == null ? void 0 : instance.options));
154
- await removeUsagesByInstance(instanceUid, options, { transaction });
163
+ await removeUsagesByInstances([instanceUid], { transaction });
155
164
  });
165
+ this.db.on(
166
+ "flowModels.beforeRemoveTree",
167
+ async ({ uids } = {}, options = {}) => {
168
+ if (!(uids == null ? void 0 : uids.length)) return;
169
+ await removeUsagesByInstances(uids, { transaction: options == null ? void 0 : options.transaction });
170
+ }
171
+ );
156
172
  const handleFlowModelSave = async (instance, { transaction } = {}) => {
157
173
  var _a2, _b;
158
174
  const instanceUid = ((_a2 = instance == null ? void 0 : instance.get) == null ? void 0 : _a2.call(instance, "uid")) || (instance == null ? void 0 : instance.uid);
@@ -203,11 +219,7 @@ class PluginBlockReferenceServer extends import_server.Plugin {
203
219
  for (const node of nodes) {
204
220
  const instanceUid = node == null ? void 0 : node.uid;
205
221
  if (!instanceUid) continue;
206
- const options = parseOptions((node == null ? void 0 : node.options) || {});
207
- if ((node == null ? void 0 : node.parent) && !(options == null ? void 0 : options.parentId)) {
208
- options.parentId = node.parent;
209
- }
210
- await removeUsagesByInstance(instanceUid, options, { transaction: ctx.transaction });
222
+ await removeUsagesByInstances([instanceUid], { transaction: ctx.transaction });
211
223
  }
212
224
  return;
213
225
  }
@@ -237,6 +237,7 @@ var flowModelTemplates_default = {
237
237
  }
238
238
  },
239
239
  async destroy(ctx, next) {
240
+ var _a;
240
241
  const templateUid = resolveTemplateUid(ctx);
241
242
  if (!templateUid) {
242
243
  return ctx.throw(400, "template uid is required");
@@ -255,6 +256,13 @@ var flowModelTemplates_default = {
255
256
  data: { usageCount }
256
257
  });
257
258
  }
259
+ const templateRepo = ctx.db.getRepository("flowModelTemplates");
260
+ const template = await templateRepo.findOne({
261
+ filter: { uid: templateUid },
262
+ transaction: ctx.transaction,
263
+ context: ctx
264
+ });
265
+ const targetUid = ((_a = template == null ? void 0 : template.get) == null ? void 0 : _a.call(template, "targetUid")) || (template == null ? void 0 : template.targetUid);
258
266
  await import_actions.default.destroy(ctx, next);
259
267
  await usageRepo.destroy({
260
268
  filter: {
@@ -262,6 +270,10 @@ var flowModelTemplates_default = {
262
270
  },
263
271
  context: ctx
264
272
  });
273
+ if (targetUid) {
274
+ const flowRepo = ctx.db.getRepository("flowModels");
275
+ await flowRepo.remove(targetUid, { transaction: ctx.transaction });
276
+ }
265
277
  }
266
278
  }
267
279
  };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "UI 模板",
5
5
  "description": "Provides block templates and popup templates for UI reuse.",
6
6
  "description.zh-CN": "提供区块模板和弹窗模板复用的能力。",
7
- "version": "2.1.0-beta.33",
7
+ "version": "2.1.0-beta.35",
8
8
  "license": "Apache-2.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "types": "./dist/index.d.ts",
@@ -33,5 +33,5 @@
33
33
  "block",
34
34
  "popup"
35
35
  ],
36
- "gitHead": "4815c394e80a264fa8ed619246280923c47aeb72"
36
+ "gitHead": "74310d8b9e9581fcde14b5a93d12b41ddb5bb325"
37
37
  }