@adminforth/crud-approve-plugin 1.0.19 → 1.0.21

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/build.log CHANGED
@@ -11,5 +11,5 @@ custom/package.json
11
11
  custom/pnpm-lock.yaml
12
12
  custom/tsconfig.json
13
13
 
14
- sent 32,550 bytes received 134 bytes 65,368.00 bytes/sec
15
- total size is 32,047 speedup is 0.98
14
+ sent 32,790 bytes received 134 bytes 65,848.00 bytes/sec
15
+ total size is 32,287 speedup is 0.98
@@ -15,6 +15,7 @@ const theme = computed(() => coreStore.theme);
15
15
 
16
16
  const oldContent = JSON.stringify(props.record[props.meta.resourceColumns.dataColumnName].oldRecord, null, 2)
17
17
  const newContent = JSON.stringify(props.record[props.meta.resourceColumns.dataColumnName].newRecord, null, 2)
18
+ const hasChanges = oldContent !== newContent;
18
19
 
19
20
  const diffFile = ref();
20
21
 
@@ -53,7 +54,9 @@ function initDiffFile() {
53
54
  diffFile.value = file;
54
55
  }
55
56
 
56
- initDiffFile();
57
+ if (hasChanges) {
58
+ initDiffFile();
59
+ }
57
60
 
58
61
  watch([theme], ([t]) => {
59
62
  if (!diffFile.value) return;
@@ -65,6 +68,7 @@ watch([theme], ([t]) => {
65
68
 
66
69
  <template>
67
70
  <DiffView
71
+ v-if="hasChanges"
68
72
  :diff-file="diffFile"
69
73
  :diff-view-mode="DiffModeEnum.Unified"
70
74
  :diff-view-theme="theme === 'dark' ? 'dark' : 'light'"
@@ -72,6 +76,7 @@ watch([theme], ([t]) => {
72
76
  :diff-view-wrap="true"
73
77
  :diff-view-font-size="14"
74
78
  />
79
+ <div v-else>No changes</div>
75
80
  <div v-if="record[meta.resourceColumns.statusColumnName] === 1" style="margin-top: 16px; display: flex; gap: 8px;">
76
81
  <Button style="background-color: green; color: white;" @click="sendApproveRequest(true)" :loader="false" class="w-full">Approve</Button>
77
82
  <Button style="background-color: red; color: white;" @click="sendApproveRequest(false)" :loader="false" class="w-full">Reject</Button>
@@ -18,6 +18,7 @@ const mode = computed(() => isMobile.value ? DiffModeEnum.Unified : DiffModeEnum
18
18
 
19
19
  const oldContent = JSON.stringify(props.record[props.meta.resourceColumns.dataColumnName].oldRecord, null, 2)
20
20
  const newContent = JSON.stringify(props.record[props.meta.resourceColumns.dataColumnName].newRecord, null, 2)
21
+ const hasChanges = oldContent !== newContent;
21
22
 
22
23
  const diffFile = ref();
23
24
 
@@ -58,7 +59,9 @@ function initDiffFile() {
58
59
  diffFile.value = file;
59
60
  }
60
61
 
61
- initDiffFile();
62
+ if (hasChanges) {
63
+ initDiffFile();
64
+ }
62
65
 
63
66
  watch([mode, theme], ([m, t]) => {
64
67
  if (!diffFile.value) return;
@@ -74,6 +77,7 @@ watch([mode, theme], ([m, t]) => {
74
77
 
75
78
  <template>
76
79
  <DiffView
80
+ v-if="hasChanges"
77
81
  :diff-file="diffFile"
78
82
  :diff-view-mode="mode"
79
83
  :diff-view-theme="theme === 'dark' ? 'dark' : 'light'"
@@ -81,9 +85,9 @@ watch([mode, theme], ([m, t]) => {
81
85
  :diff-view-wrap="true"
82
86
  :diff-view-font-size="14"
83
87
  />
88
+ <div v-else>No changes</div>
84
89
  <div v-if="record[meta.resourceColumns.statusColumnName] === 1" style="margin-top: 16px; display: flex; gap: 8px;">
85
90
  <Button style="background-color: green; color: white;" @click="sendApproveRequest(true)" :loader="false" class="w-full">Approve</Button>
86
91
  <Button style="background-color: red; color: white;" @click="sendApproveRequest(false)" :loader="false" class="w-full">Reject</Button>
87
92
  </div>
88
93
  </template>
89
-
@@ -15,6 +15,7 @@ const theme = computed(() => coreStore.theme);
15
15
 
16
16
  const oldContent = JSON.stringify(props.record[props.meta.resourceColumns.dataColumnName].oldRecord, null, 2)
17
17
  const newContent = JSON.stringify(props.record[props.meta.resourceColumns.dataColumnName].newRecord, null, 2)
18
+ const hasChanges = oldContent !== newContent;
18
19
 
19
20
  const diffFile = ref();
20
21
 
@@ -53,7 +54,9 @@ function initDiffFile() {
53
54
  diffFile.value = file;
54
55
  }
55
56
 
56
- initDiffFile();
57
+ if (hasChanges) {
58
+ initDiffFile();
59
+ }
57
60
 
58
61
  watch([theme], ([t]) => {
59
62
  if (!diffFile.value) return;
@@ -65,6 +68,7 @@ watch([theme], ([t]) => {
65
68
 
66
69
  <template>
67
70
  <DiffView
71
+ v-if="hasChanges"
68
72
  :diff-file="diffFile"
69
73
  :diff-view-mode="DiffModeEnum.Unified"
70
74
  :diff-view-theme="theme === 'dark' ? 'dark' : 'light'"
@@ -72,6 +76,7 @@ watch([theme], ([t]) => {
72
76
  :diff-view-wrap="true"
73
77
  :diff-view-font-size="14"
74
78
  />
79
+ <div v-else>No changes</div>
75
80
  <div v-if="record[meta.resourceColumns.statusColumnName] === 1" style="margin-top: 16px; display: flex; gap: 8px;">
76
81
  <Button style="background-color: green; color: white;" @click="sendApproveRequest(true)" :loader="false" class="w-full">Approve</Button>
77
82
  <Button style="background-color: red; color: white;" @click="sendApproveRequest(false)" :loader="false" class="w-full">Reject</Button>
@@ -18,6 +18,7 @@ const mode = computed(() => isMobile.value ? DiffModeEnum.Unified : DiffModeEnum
18
18
 
19
19
  const oldContent = JSON.stringify(props.record[props.meta.resourceColumns.dataColumnName].oldRecord, null, 2)
20
20
  const newContent = JSON.stringify(props.record[props.meta.resourceColumns.dataColumnName].newRecord, null, 2)
21
+ const hasChanges = oldContent !== newContent;
21
22
 
22
23
  const diffFile = ref();
23
24
 
@@ -58,7 +59,9 @@ function initDiffFile() {
58
59
  diffFile.value = file;
59
60
  }
60
61
 
61
- initDiffFile();
62
+ if (hasChanges) {
63
+ initDiffFile();
64
+ }
62
65
 
63
66
  watch([mode, theme], ([m, t]) => {
64
67
  if (!diffFile.value) return;
@@ -74,6 +77,7 @@ watch([mode, theme], ([m, t]) => {
74
77
 
75
78
  <template>
76
79
  <DiffView
80
+ v-if="hasChanges"
77
81
  :diff-file="diffFile"
78
82
  :diff-view-mode="mode"
79
83
  :diff-view-theme="theme === 'dark' ? 'dark' : 'light'"
@@ -81,9 +85,9 @@ watch([mode, theme], ([m, t]) => {
81
85
  :diff-view-wrap="true"
82
86
  :diff-view-font-size="14"
83
87
  />
88
+ <div v-else>No changes</div>
84
89
  <div v-if="record[meta.resourceColumns.statusColumnName] === 1" style="margin-top: 16px; display: flex; gap: 8px;">
85
90
  <Button style="background-color: green; color: white;" @click="sendApproveRequest(true)" :loader="false" class="w-full">Approve</Button>
86
91
  <Button style="background-color: red; color: white;" @click="sendApproveRequest(false)" :loader="false" class="w-full">Reject</Button>
87
92
  </div>
88
93
  </template>
89
-
package/dist/index.js CHANGED
@@ -119,25 +119,19 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
119
119
  //@ts-ignore
120
120
  };
121
121
  for (const hook of hooks) {
122
- const resp = yield hook({
123
- resource,
124
- record,
125
- adminUser,
126
- recordId,
127
- adminforth: this.adminforth,
128
- extra,
122
+ const resp = yield hook(Object.assign(Object.assign({ resource }, (action === AllowedActionsEnum.edit ? {} : { record })), { adminUser,
123
+ recordId, adminforth: this.adminforth, extra,
129
124
  updates,
130
- oldRecord,
131
- });
132
- if (!resp || (typeof resp.ok !== 'boolean' && (!resp.error && !resp.newRecordId))) {
133
- throw new Error(`Invalid return value from beforeSave hook. Expected: { ok: boolean, error?: string | null, newRecordId?: any }.\n` +
134
- `Note: Return { ok: false, error: null, newRecordId } to stop creation and redirect to an existing record.`);
125
+ oldRecord }));
126
+ if (!resp || (typeof resp.ok !== 'boolean' && (!resp.error && !resp.redirectToRecordId))) {
127
+ throw new Error(`Invalid return value from beforeSave hook. Expected: { ok: boolean, error?: string | null, redirectToRecordId?: any }.\n` +
128
+ `Note: Return { ok: false, error: null, redirectToRecordId } to stop creation and redirect to an existing record.`);
135
129
  }
136
130
  if (resp.ok === false && !resp.error) {
137
- const { error, ok, newRecordId } = resp;
131
+ const { error, redirectToRecordId } = resp;
138
132
  return {
139
133
  error: error !== null && error !== void 0 ? error : 'Operation aborted by hook',
140
- newRecordId: newRecordId
134
+ redirectToRecordId,
141
135
  };
142
136
  }
143
137
  if (resp.error) {
@@ -161,16 +155,10 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
161
155
  hooks = resource.hooks.delete.afterSave;
162
156
  }
163
157
  for (const hook of hooks) {
164
- const resp = yield hook({
165
- resource,
166
- record,
167
- adminUser,
168
- recordId,
169
- adminforth: this.adminforth,
170
- extra,
158
+ const resp = yield hook(Object.assign(Object.assign({ resource }, (action === AllowedActionsEnum.edit ? {} : { record })), { adminUser,
159
+ recordId, adminforth: this.adminforth, extra,
171
160
  updates,
172
- oldRecord,
173
- });
161
+ oldRecord }));
174
162
  if (!resp || (!resp.ok && !resp.error)) {
175
163
  throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
176
164
  }
package/index.ts CHANGED
@@ -176,9 +176,10 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
176
176
  //@ts-ignore
177
177
  }
178
178
  for (const hook of hooks) {
179
- const resp = await hook({
180
- resource,
181
- record,
179
+ const resp = await hook({
180
+ resource,
181
+ // edit hooks get the changed fields only in updates, like in core
182
+ ...(action === AllowedActionsEnum.edit ? {} : { record }),
182
183
  adminUser,
183
184
  recordId,
184
185
  adminforth: this.adminforth,
@@ -186,17 +187,17 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
186
187
  updates,
187
188
  oldRecord,
188
189
  });
189
- if (!resp || (typeof resp.ok !== 'boolean' && (!resp.error && !resp.newRecordId))) {
190
+ if (!resp || (typeof resp.ok !== 'boolean' && (!resp.error && !resp.redirectToRecordId))) {
190
191
  throw new Error(
191
- `Invalid return value from beforeSave hook. Expected: { ok: boolean, error?: string | null, newRecordId?: any }.\n` +
192
- `Note: Return { ok: false, error: null, newRecordId } to stop creation and redirect to an existing record.`
192
+ `Invalid return value from beforeSave hook. Expected: { ok: boolean, error?: string | null, redirectToRecordId?: any }.\n` +
193
+ `Note: Return { ok: false, error: null, redirectToRecordId } to stop creation and redirect to an existing record.`
193
194
  );
194
195
  }
195
196
  if (resp.ok === false && !resp.error) {
196
- const { error, ok, newRecordId } = resp;
197
+ const { error, redirectToRecordId } = resp;
197
198
  return {
198
199
  error: error ?? 'Operation aborted by hook',
199
- newRecordId: newRecordId
200
+ redirectToRecordId,
200
201
  };
201
202
  }
202
203
  if (resp.error) {
@@ -233,7 +234,7 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
233
234
  for (const hook of hooks) {
234
235
  const resp = await hook({
235
236
  resource,
236
- record,
237
+ ...(action === AllowedActionsEnum.edit ? {} : { record }),
237
238
  adminUser,
238
239
  recordId,
239
240
  adminforth: this.adminforth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/crud-approve-plugin",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/node": "^22.10.7",
55
- "adminforth": "^3.1.2",
55
+ "adminforth": "^4.7.3",
56
56
  "semantic-release": "^24.2.1",
57
57
  "semantic-release-slack-bot": "^4.0.2",
58
58
  "typescript": "^5.7.3"