@go-avro/avro-js 0.0.2-beta.129 → 0.0.2-beta.130
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.
|
@@ -36,6 +36,10 @@ declare module '../client/QueryClient' {
|
|
|
36
36
|
amt?: number;
|
|
37
37
|
query?: string;
|
|
38
38
|
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Team[], StandardError>;
|
|
39
|
+
useGetSkills(body: {
|
|
40
|
+
amt?: number;
|
|
41
|
+
query?: string;
|
|
42
|
+
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Skill[], StandardError>;
|
|
39
43
|
useGetEvents(body: {
|
|
40
44
|
amt?: number;
|
|
41
45
|
known_ids?: string[];
|
|
@@ -402,6 +406,13 @@ export declare class AvroQueryClient {
|
|
|
402
406
|
query?: string;
|
|
403
407
|
offset?: number;
|
|
404
408
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
409
|
+
fetchSkills(body?: {
|
|
410
|
+
amt?: number;
|
|
411
|
+
known_ids?: string[];
|
|
412
|
+
unknown_ids?: string[];
|
|
413
|
+
query?: string;
|
|
414
|
+
offset?: number;
|
|
415
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
405
416
|
fetchSessions(body?: {
|
|
406
417
|
amt?: number;
|
|
407
418
|
query?: string;
|
|
@@ -363,6 +363,25 @@ export class AvroQueryClient {
|
|
|
363
363
|
throw new StandardError(500, 'Failed to fetch teams');
|
|
364
364
|
});
|
|
365
365
|
}
|
|
366
|
+
fetchSkills(body = {}, cancelToken, headers = {}) {
|
|
367
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
368
|
+
throw new StandardError(400, 'Company ID is required');
|
|
369
|
+
}
|
|
370
|
+
return this._fetch('POST', `/company/${this.companyId}/skills`, JSON.stringify(body), cancelToken, {
|
|
371
|
+
...headers,
|
|
372
|
+
'Content-Type': 'application/json',
|
|
373
|
+
})
|
|
374
|
+
.then(response => {
|
|
375
|
+
if (!response || !Array.isArray(response)) {
|
|
376
|
+
throw new StandardError(400, 'Invalid skills response');
|
|
377
|
+
}
|
|
378
|
+
return response;
|
|
379
|
+
})
|
|
380
|
+
.catch(err => {
|
|
381
|
+
console.error('Failed to fetch skills:', err);
|
|
382
|
+
throw new StandardError(500, 'Failed to fetch skills');
|
|
383
|
+
});
|
|
384
|
+
}
|
|
366
385
|
fetchSessions(body = {}, cancelToken, headers = {}) {
|
|
367
386
|
if (!this.companyId || this.companyId.trim() === '') {
|
|
368
387
|
throw new StandardError(400, 'Company ID is required');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMutation } from '@tanstack/react-query';
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useCreateSkill = function () {
|
|
4
4
|
const queryClient = this.getQueryClient();
|
|
@@ -8,39 +8,34 @@ AvroQueryClient.prototype.useCreateSkill = function () {
|
|
|
8
8
|
"Content-Type": "application/json",
|
|
9
9
|
});
|
|
10
10
|
},
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
await queryClient.cancelQueries({ queryKey: ['company', this.companyId, 'skills'] });
|
|
14
|
-
const previousCompany = queryClient.getQueryData(['company', this.companyId]);
|
|
15
|
-
const previousSkills = queryClient.getQueryData(['company', this.companyId, 'skills']);
|
|
16
|
-
const tempSkill = {
|
|
17
|
-
id: `temp-${Date.now()}`,
|
|
18
|
-
name: skillData.name ?? 'New Skill',
|
|
19
|
-
};
|
|
20
|
-
if (previousCompany) {
|
|
21
|
-
queryClient.setQueryData(['company', this.companyId], {
|
|
22
|
-
...previousCompany,
|
|
23
|
-
skills: [...(previousCompany.skills || []), tempSkill],
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
if (previousSkills) {
|
|
27
|
-
queryClient.setQueryData(['company', this.companyId, 'skills'], [...previousSkills, tempSkill]);
|
|
28
|
-
}
|
|
29
|
-
return { previousCompany, previousSkills };
|
|
11
|
+
onSettled: () => {
|
|
12
|
+
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
30
13
|
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
AvroQueryClient.prototype.useGetSkills = function (body, total, onProgress) {
|
|
17
|
+
return useQuery({
|
|
18
|
+
queryKey: ['skills', this.companyId, body.amt ?? 50, body.query ?? "", total ?? "all"],
|
|
19
|
+
queryFn: async () => {
|
|
20
|
+
if (typeof total !== "number") {
|
|
21
|
+
return this.fetchSkills({ ...body, offset: 0 });
|
|
38
22
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
23
|
+
onProgress?.(0);
|
|
24
|
+
const pageCount = body.amt ? Math.ceil(total / body.amt) : 0;
|
|
25
|
+
let completed = 0;
|
|
26
|
+
const promises = Array.from({ length: pageCount }, (_, i) => this.fetchSkills({
|
|
27
|
+
...body,
|
|
28
|
+
offset: i * (body.amt ?? 0),
|
|
29
|
+
}));
|
|
30
|
+
const trackedPromises = promises.map((promise) => promise.then((result) => {
|
|
31
|
+
completed++;
|
|
32
|
+
const fraction = completed / pageCount;
|
|
33
|
+
onProgress?.(fraction);
|
|
34
|
+
return result;
|
|
35
|
+
}));
|
|
36
|
+
const pages = await Promise.all(trackedPromises);
|
|
37
|
+
const skills = pages.flat();
|
|
38
|
+
return skills;
|
|
44
39
|
},
|
|
45
40
|
});
|
|
46
41
|
};
|
|
@@ -53,34 +48,42 @@ AvroQueryClient.prototype.useUpdateSkill = function () {
|
|
|
53
48
|
});
|
|
54
49
|
},
|
|
55
50
|
onMutate: async ({ skillId, updates }) => {
|
|
56
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
57
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
51
|
+
await queryClient.cancelQueries({ queryKey: ['skills'] });
|
|
52
|
+
await queryClient.cancelQueries({ queryKey: ['skill', skillId] });
|
|
53
|
+
const previousSkills = queryClient.getQueryData(['skills']);
|
|
54
|
+
const previousSkill = queryClient.getQueryData(['skill', skillId]);
|
|
55
|
+
queryClient.setQueryData(['skill', skillId], (oldData) => {
|
|
56
|
+
if (!oldData)
|
|
57
|
+
return oldData;
|
|
58
|
+
return { ...oldData, ...updates };
|
|
59
|
+
});
|
|
60
|
+
queryClient.setQueriesData({ queryKey: ['skills'] }, (oldData) => {
|
|
61
|
+
if (!oldData)
|
|
62
|
+
return oldData;
|
|
63
|
+
if (oldData.pages) {
|
|
64
|
+
const updatedPages = oldData.pages.map((page) => page.map((skill) => skill.id === skillId ? { ...skill, ...updates } : skill));
|
|
65
|
+
return { ...oldData, pages: updatedPages };
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(oldData)) {
|
|
68
|
+
return oldData.map((skill) => skill.id === skillId ? { ...skill, ...updates } : skill);
|
|
69
|
+
}
|
|
70
|
+
return oldData;
|
|
71
|
+
});
|
|
72
|
+
return { previousSkills, previousSkill };
|
|
70
73
|
},
|
|
71
74
|
onError: (_err, variables, context) => {
|
|
72
|
-
const {
|
|
73
|
-
if (context?.
|
|
74
|
-
queryClient.setQueryData(['
|
|
75
|
+
const { skillId } = variables;
|
|
76
|
+
if (context?.previousSkills) {
|
|
77
|
+
queryClient.setQueryData(['skills'], context.previousSkills);
|
|
75
78
|
}
|
|
76
|
-
if (context?.
|
|
77
|
-
queryClient.setQueryData(['
|
|
79
|
+
if (context?.previousSkill) {
|
|
80
|
+
queryClient.setQueryData(['skill', skillId], context.previousSkill);
|
|
78
81
|
}
|
|
79
82
|
},
|
|
80
83
|
onSettled: (_data, _error, variables) => {
|
|
81
|
-
const {
|
|
82
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
83
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
84
|
+
const { skillId } = variables;
|
|
85
|
+
queryClient.invalidateQueries({ queryKey: ['skills'] });
|
|
86
|
+
queryClient.invalidateQueries({ queryKey: ['skill', skillId] });
|
|
84
87
|
},
|
|
85
88
|
});
|
|
86
89
|
};
|
|
@@ -91,34 +94,29 @@ AvroQueryClient.prototype.useDeleteSkill = function () {
|
|
|
91
94
|
return this.delete(`/skill/${skillId}`);
|
|
92
95
|
},
|
|
93
96
|
onMutate: async ({ skillId }) => {
|
|
94
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
97
|
+
await queryClient.cancelQueries({ queryKey: ['skills'] });
|
|
98
|
+
const previousSkills = queryClient.getQueryData(['skills']);
|
|
99
|
+
queryClient.setQueriesData({ queryKey: ['skills'] }, (oldData) => {
|
|
100
|
+
if (!oldData)
|
|
101
|
+
return oldData;
|
|
102
|
+
if (oldData.pages) {
|
|
103
|
+
const updatedPages = oldData.pages.map((page) => page.filter((skill) => skill.id !== skillId));
|
|
104
|
+
return { ...oldData, pages: updatedPages };
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(oldData)) {
|
|
107
|
+
return oldData.filter((skill) => skill.id !== skillId);
|
|
108
|
+
}
|
|
109
|
+
return oldData;
|
|
110
|
+
});
|
|
111
|
+
return { previousSkills };
|
|
108
112
|
},
|
|
109
113
|
onError: (_err, variables, context) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
queryClient.setQueryData(['company', companyId], context.previousCompany);
|
|
113
|
-
}
|
|
114
|
-
if (context?.previousSkills && companyId) {
|
|
115
|
-
queryClient.setQueryData(['company', companyId, 'skills'], context.previousSkills);
|
|
114
|
+
if (context?.previousSkills) {
|
|
115
|
+
queryClient.setQueryData(['skills'], context.previousSkills);
|
|
116
116
|
}
|
|
117
117
|
},
|
|
118
|
-
onSettled: (
|
|
119
|
-
|
|
120
|
-
queryClient.invalidateQueries({ queryKey: ['company', companyId] });
|
|
121
|
-
queryClient.invalidateQueries({ queryKey: ['company', companyId, 'skills'] });
|
|
118
|
+
onSettled: () => {
|
|
119
|
+
queryClient.invalidateQueries({ queryKey: ['skills'] });
|
|
122
120
|
},
|
|
123
121
|
});
|
|
124
122
|
};
|