@n8n/frontend-module-inbox 0.0.0-stage → 0.1.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.
Files changed (58) hide show
  1. package/LICENSE.md +88 -0
  2. package/README.md +59 -2
  3. package/biome.jsonc +4 -0
  4. package/eslint.config.mjs +4 -0
  5. package/package.json +62 -3
  6. package/src/__tests__/design-system-icons.test.ts +24 -0
  7. package/src/__tests__/setup.ts +4 -0
  8. package/src/components/InboxEmptyState.vue +86 -0
  9. package/src/components/InboxList.test.ts +229 -0
  10. package/src/components/InboxList.vue +195 -0
  11. package/src/components/InboxListItem.vue +134 -0
  12. package/src/components/InboxListSection.vue +168 -0
  13. package/src/composables/useReviewInboxSectionCollapse.test.ts +66 -0
  14. package/src/composables/useReviewInboxSectionCollapse.ts +42 -0
  15. package/src/inbox.api.ts +20 -0
  16. package/src/inbox.constants.ts +16 -0
  17. package/src/inbox.module.ts +50 -0
  18. package/src/inbox.routes.test.ts +111 -0
  19. package/src/inbox.routes.ts +30 -0
  20. package/src/inbox.store.test.ts +349 -0
  21. package/src/inbox.store.ts +305 -0
  22. package/src/index.ts +5 -0
  23. package/src/reviews/WorkflowReviewDetail.test.ts +647 -0
  24. package/src/reviews/WorkflowReviewDetail.vue +257 -0
  25. package/src/reviews/components/WorkflowReviewActivityFeed.test.ts +923 -0
  26. package/src/reviews/components/WorkflowReviewActivityFeed.vue +312 -0
  27. package/src/reviews/components/WorkflowReviewChangesSection.test.ts +327 -0
  28. package/src/reviews/components/WorkflowReviewChangesSection.vue +219 -0
  29. package/src/reviews/components/WorkflowReviewCommentComposer.test.ts +175 -0
  30. package/src/reviews/components/WorkflowReviewCommentComposer.vue +83 -0
  31. package/src/reviews/components/WorkflowReviewDecisionPopover.test.ts +288 -0
  32. package/src/reviews/components/WorkflowReviewDecisionPopover.vue +203 -0
  33. package/src/reviews/components/WorkflowReviewDetailMetadata.test.ts +206 -0
  34. package/src/reviews/components/WorkflowReviewDetailMetadata.vue +241 -0
  35. package/src/reviews/components/WorkflowReviewDetailTabs.decisionNote.test.ts +90 -0
  36. package/src/reviews/components/WorkflowReviewDetailTabs.test.ts +434 -0
  37. package/src/reviews/components/WorkflowReviewDetailTabs.vue +311 -0
  38. package/src/reviews/components/WorkflowReviewStatusDot.vue +67 -0
  39. package/src/reviews/components/_activity-card.scss +36 -0
  40. package/src/reviews/components/activity-entries/WorkflowReviewActivityActorAvatar.vue +50 -0
  41. package/src/reviews/components/activity-entries/WorkflowReviewActivityComment.test.ts +103 -0
  42. package/src/reviews/components/activity-entries/WorkflowReviewActivityComment.vue +116 -0
  43. package/src/reviews/components/activity-entries/WorkflowReviewActivityEventEntry.vue +361 -0
  44. package/src/reviews/components/activity-entries/WorkflowReviewActivityFallback.vue +49 -0
  45. package/src/reviews/components/activity-entries/WorkflowReviewActivityWorkflowLink.vue +36 -0
  46. package/src/reviews/components/activityEntryRegistry.ts +27 -0
  47. package/src/reviews/constants.ts +41 -0
  48. package/src/reviews/reviewActivity.store.test.ts +463 -0
  49. package/src/reviews/reviewActivity.store.ts +186 -0
  50. package/src/reviews/reviewDetail.store.test.ts +135 -0
  51. package/src/reviews/reviewDetail.store.ts +74 -0
  52. package/src/reviews/workflowReviewStatus.utils.ts +44 -0
  53. package/src/reviews/workflowReviews.api.ts +61 -0
  54. package/src/reviews/workflowReviews.utils.ts +18 -0
  55. package/src/views/InboxView.test.ts +525 -0
  56. package/src/views/InboxView.vue +251 -0
  57. package/stylelint.config.mjs +9 -0
  58. package/vite.config.ts +52 -0
@@ -0,0 +1,305 @@
1
+ import type {
2
+ InboxCategory,
3
+ InboxItem,
4
+ InboxSourceType,
5
+ InboxState,
6
+ ListInboxResponse,
7
+ } from '@n8n/api-types';
8
+ import { ResponseError } from '@n8n/rest-api-client';
9
+ import { useRootStore } from '@n8n/stores/useRootStore';
10
+ import { useSettingsStore } from '@n8n/stores/settings.store';
11
+ import { defineStore } from 'pinia';
12
+ import { computed, reactive, ref } from 'vue';
13
+
14
+ import { fetchInbox, fetchInboxSummary } from './inbox.api';
15
+ import { INBOX_PAGE_LIMIT, type InboxItemChange, type InboxSectionKey } from './inbox.constants';
16
+ import { toError } from './reviews/workflowReviews.utils';
17
+
18
+ const sourceTypes: InboxSourceType[] = ['workflow_review'];
19
+
20
+ type ListState = {
21
+ items: InboxItem[];
22
+ nextCursor: string | null;
23
+ hasMore: boolean;
24
+ hasLoaded: boolean;
25
+ loading: boolean;
26
+ loadingMore: boolean;
27
+ error: Error | null;
28
+ failedRequest: 'list' | 'loadMore' | null;
29
+ partial: boolean;
30
+ };
31
+
32
+ function isSourceType(value: unknown): value is InboxSourceType {
33
+ return value === 'workflow_review';
34
+ }
35
+
36
+ function disabledTypesFromError(error: unknown): InboxSourceType[] {
37
+ const types = error instanceof ResponseError ? error.meta?.disabledSources : undefined;
38
+ return Array.isArray(types) ? types.filter(isSourceType) : [];
39
+ }
40
+
41
+ export function createInboxListSlice(
42
+ requestPage: (cursor?: string) => Promise<ListInboxResponse>,
43
+ onDisabledSources: (types: InboxSourceType[]) => void,
44
+ onPage?: (page: ListInboxResponse, append: boolean) => void,
45
+ ) {
46
+ const state = reactive<ListState>({
47
+ items: [],
48
+ nextCursor: null,
49
+ hasMore: false,
50
+ hasLoaded: false,
51
+ loading: false,
52
+ loadingMore: false,
53
+ error: null,
54
+ failedRequest: null,
55
+ partial: false,
56
+ });
57
+ let requestSeq = 0;
58
+
59
+ function applyResponse(page: ListInboxResponse, append: boolean) {
60
+ onPage?.(page, append);
61
+ onDisabledSources(page.disabledSources);
62
+ state.hasLoaded = true;
63
+ state.items = append ? [...state.items, ...page.data] : page.data;
64
+ state.nextCursor = page.nextCursor;
65
+ state.hasMore = page.hasMore;
66
+ state.partial = page.partial;
67
+ }
68
+
69
+ async function fetchList() {
70
+ const seq = ++requestSeq;
71
+ state.items = [];
72
+ state.nextCursor = null;
73
+ state.hasMore = false;
74
+ state.loading = true;
75
+ state.loadingMore = false;
76
+ state.error = null;
77
+ state.failedRequest = null;
78
+ try {
79
+ const page = await requestPage();
80
+ if (seq === requestSeq) applyResponse(page, false);
81
+ } catch (error) {
82
+ if (seq !== requestSeq) return;
83
+ onDisabledSources(disabledTypesFromError(error));
84
+ state.error = toError(error);
85
+ state.failedRequest = 'list';
86
+ } finally {
87
+ if (seq === requestSeq) state.loading = false;
88
+ }
89
+ }
90
+
91
+ async function loadMore() {
92
+ if (state.loading || state.loadingMore || !state.hasMore || !state.nextCursor) return;
93
+ const seq = ++requestSeq;
94
+ state.loadingMore = true;
95
+ state.error = null;
96
+ state.failedRequest = null;
97
+ try {
98
+ const page = await requestPage(state.nextCursor);
99
+ if (seq === requestSeq) applyResponse(page, true);
100
+ } catch (error) {
101
+ if (seq !== requestSeq) return;
102
+ onDisabledSources(disabledTypesFromError(error));
103
+ state.error = toError(error);
104
+ state.failedRequest = 'loadMore';
105
+ } finally {
106
+ if (seq === requestSeq) state.loadingMore = false;
107
+ }
108
+ }
109
+
110
+ function removeSources(types: InboxSourceType[]) {
111
+ state.items = state.items.filter((item) => !types.includes(item.type));
112
+ }
113
+
114
+ function reset() {
115
+ requestSeq++;
116
+ state.items = [];
117
+ state.hasLoaded = false;
118
+ state.nextCursor = null;
119
+ state.hasMore = false;
120
+ state.loading = false;
121
+ state.loadingMore = false;
122
+ state.error = null;
123
+ state.failedRequest = null;
124
+ state.partial = false;
125
+ }
126
+
127
+ return Object.assign(state, {
128
+ fetchList,
129
+ loadMore,
130
+ removeSources,
131
+ reset,
132
+ async retry() {
133
+ if (state.failedRequest === 'loadMore') await loadMore();
134
+ else await fetchList();
135
+ },
136
+ });
137
+ }
138
+
139
+ export const useInboxStore = defineStore('inbox', () => {
140
+ const rootStore = useRootStore();
141
+ const settingsStore = useSettingsStore();
142
+ const activeTab = ref<InboxState>('open');
143
+ const openCount = ref<number | null>(null);
144
+ const closedCount = ref<number | null>(null);
145
+ const disabledSources = ref<InboxSourceType[]>([]);
146
+ const enabled = computed(() => settingsStore.settings.inbox?.enabled === true);
147
+ let summaryRequestSeq = 0;
148
+
149
+ function removeDisabledSources(types: InboxSourceType[]) {
150
+ if (types.length === 0) return;
151
+ disabledSources.value = [...new Set([...disabledSources.value, ...types])];
152
+ for (const list of Object.values(lists)) list.removeSources(types);
153
+ }
154
+
155
+ function reconcileSources(page: ListInboxResponse, partialSourceSet: boolean) {
156
+ if (partialSourceSet) {
157
+ const returnedTypes = page.data.map((item) => item.type);
158
+ disabledSources.value = disabledSources.value.filter(
159
+ (type) => page.disabledSources.includes(type) || !returnedTypes.includes(type),
160
+ );
161
+ return;
162
+ }
163
+ const settings = settingsStore.settings.inbox;
164
+ const knownTypes = new Set([
165
+ ...(settings?.availableTypes ?? []),
166
+ ...(settings?.failedTypes ?? []),
167
+ ...page.data.map((item) => item.type),
168
+ ]);
169
+ disabledSources.value = sourceTypes.filter(
170
+ (type) =>
171
+ !knownTypes.has(type) ||
172
+ page.disabledSources.includes(type) ||
173
+ (disabledSources.value.includes(type) && page.failedSources.includes(type)),
174
+ );
175
+ }
176
+
177
+ function requestPage(state: InboxState, category?: InboxCategory) {
178
+ return async (cursor?: string) =>
179
+ await fetchInbox(rootStore.restApiContext, {
180
+ state,
181
+ category,
182
+ limit: INBOX_PAGE_LIMIT,
183
+ cursor,
184
+ });
185
+ }
186
+ const lists = {
187
+ waiting: createInboxListSlice(
188
+ requestPage('open', 'waiting'),
189
+ removeDisabledSources,
190
+ reconcileSources,
191
+ ),
192
+ // A category can query only part of the source set.
193
+ authored: createInboxListSlice(requestPage('open', 'authored'), removeDisabledSources, (page) =>
194
+ reconcileSources(page, true),
195
+ ),
196
+ closed: createInboxListSlice(requestPage('closed'), removeDisabledSources, reconcileSources),
197
+ };
198
+ const activeSectionKeys = computed<InboxSectionKey[]>(() =>
199
+ activeTab.value === 'closed' ? ['closed'] : ['waiting', 'authored'],
200
+ );
201
+ const activeLists = computed(() => activeSectionKeys.value.map((key) => lists[key]));
202
+ const hasItems = computed(() => activeLists.value.some((list) => list.items.length > 0));
203
+ const loading = computed(() => activeLists.value.some((list) => list.loading));
204
+ const initialLoadFailed = computed(() =>
205
+ activeLists.value.some((list) => list.failedRequest === 'list'),
206
+ );
207
+ const partial = computed(() => activeLists.value.some((list) => list.partial));
208
+ const isEmpty = computed(() =>
209
+ activeLists.value.every(
210
+ (list) =>
211
+ list.hasLoaded &&
212
+ !list.loading &&
213
+ !list.error &&
214
+ !list.partial &&
215
+ !list.hasMore &&
216
+ list.items.length === 0,
217
+ ),
218
+ );
219
+
220
+ async function fetchSummary() {
221
+ if (!enabled.value) return;
222
+ const seq = ++summaryRequestSeq;
223
+ try {
224
+ const summary = await fetchInboxSummary(rootStore.restApiContext);
225
+ if (seq !== summaryRequestSeq) return;
226
+ removeDisabledSources(summary.disabledSources);
227
+ openCount.value = summary.counts?.open ?? null;
228
+ closedCount.value = summary.counts?.closed ?? null;
229
+ } catch (error) {
230
+ if (seq !== summaryRequestSeq) return;
231
+ removeDisabledSources(disabledTypesFromError(error));
232
+ }
233
+ }
234
+
235
+ async function fetchActiveTab() {
236
+ if (!enabled.value) return;
237
+ await Promise.all(activeLists.value.map(async (list) => await list.fetchList()));
238
+ }
239
+
240
+ async function refreshListAndSummary() {
241
+ await Promise.all([fetchActiveTab(), fetchSummary()]);
242
+ }
243
+
244
+ function reconcileItemChange(change: InboxItemChange) {
245
+ let previousState: InboxState | undefined;
246
+ for (const [key, list] of Object.entries(lists)) {
247
+ const item = list.items.find((row) => row.type === change.type && row.id === change.id);
248
+ if (!item) continue;
249
+ previousState ??= item.state;
250
+ if (change.state) item.state = change.state;
251
+ if (change.updatedAt) item.updatedAt = change.updatedAt;
252
+ if (item.type === 'workflow_review' && change.decision) item.decision = change.decision;
253
+ if (item.state !== (key === 'closed' ? 'closed' : 'open')) {
254
+ list.items = list.items.filter((row) => row !== item);
255
+ }
256
+ }
257
+ if (change.state !== 'closed') return;
258
+ // A late result can arrive after a summary that already counts it.
259
+ // Count only a row that closes now. Without a row, ask the server.
260
+ if (previousState === 'open') {
261
+ if (openCount.value !== null) openCount.value = Math.max(0, openCount.value - 1);
262
+ if (closedCount.value !== null) closedCount.value++;
263
+ } else if (!previousState) {
264
+ void fetchSummary();
265
+ }
266
+ }
267
+
268
+ async function setActiveTab(tab: InboxState) {
269
+ if (activeTab.value === tab) return;
270
+ activeTab.value = tab;
271
+ await fetchActiveTab();
272
+ }
273
+
274
+ function reset() {
275
+ summaryRequestSeq++;
276
+ for (const list of Object.values(lists)) list.reset();
277
+ openCount.value = null;
278
+ closedCount.value = null;
279
+ const settings = settingsStore.settings.inbox;
280
+ const available = [...(settings?.availableTypes ?? []), ...(settings?.failedTypes ?? [])];
281
+ disabledSources.value = sourceTypes.filter((type) => !available.includes(type));
282
+ }
283
+
284
+ return {
285
+ lists,
286
+ activeTab,
287
+ activeSectionKeys,
288
+ activeLists,
289
+ hasItems,
290
+ loading,
291
+ initialLoadFailed,
292
+ partial,
293
+ isEmpty,
294
+ enabled,
295
+ openCount,
296
+ closedCount,
297
+ disabledSources,
298
+ fetchSummary,
299
+ fetchActiveTab,
300
+ refreshListAndSummary,
301
+ reconcileItemChange,
302
+ setActiveTab,
303
+ reset,
304
+ };
305
+ });
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { InboxModule } from './inbox.module';
2
+ export { INBOX_VIEW } from './inbox.constants';
3
+ export { isInboxRoute } from './inbox.routes';
4
+ export { WORKFLOW_REVIEW_REQUESTS_VIEW, REVIEW_INBOX_QUERY_PARAM } from './reviews/constants';
5
+ export { formatUserDisplayName } from './reviews/workflowReviews.utils';