@adminforth/i18n 1.0.21-next.0 → 1.0.21-next.1

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.
package/Changelog.md CHANGED
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [1.0.21] - next
9
9
 
10
+ ### Fixed
11
+ - improve cache reset when editing messages manually
12
+
10
13
  ## [1.0.20]
11
14
 
12
15
  ### Fixed
package/dist/index.js CHANGED
@@ -215,7 +215,6 @@ export default class I18N extends AdminForthPlugin {
215
215
  }));
216
216
  // add hook on edit of any translation
217
217
  resourceConfig.hooks.edit.afterSave.push((_d) => __awaiter(this, [_d], void 0, function* ({ updates, oldRecord }) {
218
- console.log('🪲edit.afterSave', JSON.stringify(updates, null, 2), '-----', JSON.stringify(oldRecord, null, 2));
219
218
  if (oldRecord) {
220
219
  // find lang which changed
221
220
  let langsChanged = [];
@@ -223,10 +222,18 @@ export default class I18N extends AdminForthPlugin {
223
222
  if (lang === 'en') {
224
223
  continue;
225
224
  }
225
+ if (updates[this.trFieldNames[lang]]) {
226
+ langsChanged.push(lang);
227
+ }
226
228
  }
227
229
  // clear frontend cache for all langsChanged
228
230
  for (const lang of langsChanged) {
229
- this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
231
+ if (oldRecord[this.options.categoryFieldName] === 'frontend') {
232
+ this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
233
+ }
234
+ else {
235
+ this.cache.clear(`${this.resourceConfig.resourceId}:${oldRecord[this.options.categoryFieldName]}:${lang}:${oldRecord[this.enFieldName]}`);
236
+ }
230
237
  }
231
238
  this.updateUntranslatedMenuBadge();
232
239
  }
@@ -236,8 +243,13 @@ export default class I18N extends AdminForthPlugin {
236
243
  // add hook on delete of any translation to reset cache
237
244
  resourceConfig.hooks.delete.afterSave.push((_e) => __awaiter(this, [_e], void 0, function* ({ record }) {
238
245
  for (const lang of this.options.supportedLanguages) {
239
- this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
240
- this.cache.clear(`${this.resourceConfig.resourceId}:${record[this.options.categoryFieldName]}:${lang}:${record[this.enFieldName]}`);
246
+ // if frontend, clear frontend cache
247
+ if (record[this.options.categoryFieldName] === 'frontend') {
248
+ this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
249
+ }
250
+ else {
251
+ this.cache.clear(`${this.resourceConfig.resourceId}:${record[this.options.categoryFieldName]}:${lang}:${record[this.enFieldName]}`);
252
+ }
241
253
  }
242
254
  this.updateUntranslatedMenuBadge();
243
255
  return { ok: true };
package/index.ts CHANGED
@@ -244,7 +244,6 @@ export default class I18N extends AdminForthPlugin {
244
244
 
245
245
  // add hook on edit of any translation
246
246
  resourceConfig.hooks.edit.afterSave.push(async ({ updates, oldRecord }: { updates: any, oldRecord?: any }): Promise<{ ok: boolean, error?: string }> => {
247
- console.log('🪲edit.afterSave', JSON.stringify(updates, null, 2),'-----', JSON.stringify(oldRecord, null, 2));
248
247
  if (oldRecord) {
249
248
  // find lang which changed
250
249
  let langsChanged: LanguageCode[] = [];
@@ -252,27 +251,34 @@ export default class I18N extends AdminForthPlugin {
252
251
  if (lang === 'en') {
253
252
  continue;
254
253
  }
254
+ if (updates[this.trFieldNames[lang]]) {
255
+ langsChanged.push(lang);
256
+ }
255
257
  }
256
-
258
+
257
259
  // clear frontend cache for all langsChanged
258
260
  for (const lang of langsChanged) {
259
- this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
261
+ if (oldRecord[this.options.categoryFieldName] === 'frontend') {
262
+ this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
263
+ } else {
264
+ this.cache.clear(`${this.resourceConfig.resourceId}:${oldRecord[this.options.categoryFieldName]}:${lang}:${oldRecord[this.enFieldName]}`);
265
+ }
260
266
  }
261
-
262
267
  this.updateUntranslatedMenuBadge();
263
-
264
268
  }
265
269
  // clear frontend cache for all lan
266
-
267
-
268
270
  return { ok: true };
269
271
  });
270
272
 
271
273
  // add hook on delete of any translation to reset cache
272
274
  resourceConfig.hooks.delete.afterSave.push(async ({ record }: { record: any }): Promise<{ ok: boolean, error?: string }> => {
273
275
  for (const lang of this.options.supportedLanguages) {
274
- this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
275
- this.cache.clear(`${this.resourceConfig.resourceId}:${record[this.options.categoryFieldName]}:${lang}:${record[this.enFieldName]}`);
276
+ // if frontend, clear frontend cache
277
+ if (record[this.options.categoryFieldName] === 'frontend') {
278
+ this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
279
+ } else {
280
+ this.cache.clear(`${this.resourceConfig.resourceId}:${record[this.options.categoryFieldName]}:${lang}:${record[this.enFieldName]}`);
281
+ }
276
282
  }
277
283
  this.updateUntranslatedMenuBadge();
278
284
  return { ok: true };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/i18n",
3
- "version": "1.0.21-next.0",
3
+ "version": "1.0.21-next.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",