@adventurelabs/scout-core 1.2.6 → 1.3.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/dist/helpers/cache.js +3 -1
- package/dist/helpers/session_summaries.d.ts +6 -0
- package/dist/helpers/session_summaries.js +51 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/useHerdData.d.ts +167 -0
- package/dist/hooks/useHerdData.js +153 -0
- package/dist/hooks/useInfiniteQuery.d.ts +24 -0
- package/dist/hooks/useInfiniteQuery.js +360 -0
- package/dist/hooks/useScoutRealtimeEvents.d.ts +1 -1
- package/dist/hooks/useScoutRealtimeEvents.js +18 -23
- package/dist/hooks/useScoutRealtimeSessions.d.ts +1 -1
- package/dist/hooks/useScoutRealtimeSessions.js +20 -12
- package/dist/hooks/useScoutRealtimeTags.d.ts +1 -1
- package/dist/hooks/useScoutRealtimeTags.js +15 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/providers/ScoutRefreshProvider.d.ts +119 -0
- package/dist/store/api.d.ts +968 -0
- package/dist/store/api.js +377 -0
- package/dist/store/configureStore.d.ts +96 -0
- package/dist/store/configureStore.js +40 -0
- package/dist/store/hooks.d.ts +5 -0
- package/dist/store/hooks.js +21 -3
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.js +1 -0
- package/dist/store/scout.d.ts +13 -50
- package/dist/store/scout.js +33 -141
- package/dist/types/db.d.ts +18 -0
- package/dist/types/herd_module.d.ts +4 -16
- package/dist/types/herd_module.js +17 -23
- package/dist/types/supabase.d.ts +119 -0
- package/package.json +1 -1
package/dist/store/scout.d.ts
CHANGED
|
@@ -6,16 +6,19 @@ export declare enum EnumScoutStateStatus {
|
|
|
6
6
|
LOADING = "LOADING",
|
|
7
7
|
DONE_LOADING = "DONE_LOADING"
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
10
|
-
herd_modules: IHerdModule[];
|
|
11
|
-
status: EnumScoutStateStatus;
|
|
12
|
-
herd_modules_loading_state: EnumHerdModulesLoadingState;
|
|
9
|
+
export interface LoadingPerformance {
|
|
13
10
|
herd_modules_loaded_in_ms: number | null;
|
|
14
11
|
herd_modules_api_server_processing_ms: number | null;
|
|
15
12
|
herd_modules_api_total_request_ms: number | null;
|
|
16
13
|
user_api_duration_ms: number | null;
|
|
17
14
|
data_processing_duration_ms: number | null;
|
|
18
15
|
cache_load_duration_ms: number | null;
|
|
16
|
+
}
|
|
17
|
+
export interface ScoutState {
|
|
18
|
+
herd_modules: IHerdModule[];
|
|
19
|
+
status: EnumScoutStateStatus;
|
|
20
|
+
herd_modules_loading_state: EnumHerdModulesLoadingState;
|
|
21
|
+
loading_performance: LoadingPerformance;
|
|
19
22
|
active_herd_id: string | null;
|
|
20
23
|
active_device_id: string | null;
|
|
21
24
|
lastRefreshed: number;
|
|
@@ -40,6 +43,10 @@ export declare const scoutSlice: import("@reduxjs/toolkit").Slice<ScoutState, {
|
|
|
40
43
|
payload: any;
|
|
41
44
|
type: string;
|
|
42
45
|
}) => void;
|
|
46
|
+
setLoadingPerformance: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
47
|
+
payload: any;
|
|
48
|
+
type: string;
|
|
49
|
+
}) => void;
|
|
43
50
|
setHerdModulesLoadedInMs: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
44
51
|
payload: any;
|
|
45
52
|
type: string;
|
|
@@ -80,19 +87,7 @@ export declare const scoutSlice: import("@reduxjs/toolkit").Slice<ScoutState, {
|
|
|
80
87
|
payload: any;
|
|
81
88
|
type: string;
|
|
82
89
|
}) => void;
|
|
83
|
-
|
|
84
|
-
payload: any;
|
|
85
|
-
type: string;
|
|
86
|
-
}) => void;
|
|
87
|
-
appendEventsToHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
88
|
-
payload: any;
|
|
89
|
-
type: string;
|
|
90
|
-
}) => void;
|
|
91
|
-
replaceArtifactsForHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
92
|
-
payload: any;
|
|
93
|
-
type: string;
|
|
94
|
-
}) => void;
|
|
95
|
-
appendArtifactsToHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
90
|
+
updateSessionSummariesForHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
96
91
|
payload: any;
|
|
97
92
|
type: string;
|
|
98
93
|
}) => void;
|
|
@@ -108,18 +103,6 @@ export declare const scoutSlice: import("@reduxjs/toolkit").Slice<ScoutState, {
|
|
|
108
103
|
payload: any;
|
|
109
104
|
type: string;
|
|
110
105
|
}) => void;
|
|
111
|
-
addTag(state: import("immer").WritableDraft<ScoutState>, action: {
|
|
112
|
-
payload: any;
|
|
113
|
-
type: string;
|
|
114
|
-
}): void;
|
|
115
|
-
deleteTag(state: import("immer").WritableDraft<ScoutState>, action: {
|
|
116
|
-
payload: any;
|
|
117
|
-
type: string;
|
|
118
|
-
}): void;
|
|
119
|
-
updateTag(state: import("immer").WritableDraft<ScoutState>, action: {
|
|
120
|
-
payload: any;
|
|
121
|
-
type: string;
|
|
122
|
-
}): void;
|
|
123
106
|
addDevice(state: import("immer").WritableDraft<ScoutState>, action: {
|
|
124
107
|
payload: any;
|
|
125
108
|
type: string;
|
|
@@ -144,26 +127,6 @@ export declare const scoutSlice: import("@reduxjs/toolkit").Slice<ScoutState, {
|
|
|
144
127
|
payload: any;
|
|
145
128
|
type: string;
|
|
146
129
|
}): void;
|
|
147
|
-
updateEventValuesForHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
148
|
-
payload: any;
|
|
149
|
-
type: string;
|
|
150
|
-
}) => void;
|
|
151
|
-
updatePageIndexForHerdModule: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
152
|
-
payload: any;
|
|
153
|
-
type: string;
|
|
154
|
-
}) => void;
|
|
155
|
-
addSessionToStore: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
156
|
-
payload: any;
|
|
157
|
-
type: string;
|
|
158
|
-
}) => void;
|
|
159
|
-
deleteSessionFromStore: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
160
|
-
payload: any;
|
|
161
|
-
type: string;
|
|
162
|
-
}) => void;
|
|
163
|
-
updateSessionInStore: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
164
|
-
payload: any;
|
|
165
|
-
type: string;
|
|
166
|
-
}) => void;
|
|
167
130
|
setUser: (state: import("immer").WritableDraft<ScoutState>, action: {
|
|
168
131
|
payload: any;
|
|
169
132
|
type: string;
|
|
@@ -173,6 +136,6 @@ export declare const scoutSlice: import("@reduxjs/toolkit").Slice<ScoutState, {
|
|
|
173
136
|
type: string;
|
|
174
137
|
}) => void;
|
|
175
138
|
}, "scout", "scout", import("@reduxjs/toolkit").SliceSelectors<ScoutState>>;
|
|
176
|
-
export declare const setHerdModules: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setHerdModules">, setStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setStatus">, setHerdModulesLoadingState: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setHerdModulesLoadingState">,
|
|
139
|
+
export declare const setHerdModules: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setHerdModules">, setStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setStatus">, setHerdModulesLoadingState: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setHerdModulesLoadingState">, setLoadingPerformance: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setLoadingPerformance">, setHerdModulesLoadedInMs: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setHerdModulesLoadedInMs">, setHerdModulesApiServerProcessingDuration: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setHerdModulesApiServerProcessingDuration">, setHerdModulesApiTotalRequestDuration: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setHerdModulesApiTotalRequestDuration">, setUserApiDuration: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setUserApiDuration">, setDataProcessingDuration: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setDataProcessingDuration">, setCacheLoadDuration: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setCacheLoadDuration">, setActiveHerdId: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setActiveHerdId">, setActiveDeviceId: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setActiveDeviceId">, setDataSource: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setDataSource">, setDataSourceInfo: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setDataSourceInfo">, updateSessionSummariesForHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/updateSessionSummariesForHerdModule">, appendPlansToHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/appendPlansToHerdModule">, setUser: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setUser">, addNewDeviceToHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/addNewDeviceToHerdModule">, updateDeviceForHerdModule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/updateDeviceForHerdModule">, addDevice: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/addDevice">, deleteDevice: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/deleteDevice">, updateDevice: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/updateDevice">, addPlan: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/addPlan">, deletePlan: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/deletePlan">, updatePlan: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/updatePlan">, setActiveHerdGpsTrackersConnectivity: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "scout/setActiveHerdGpsTrackersConnectivity">;
|
|
177
140
|
declare const _default: import("redux").Reducer<ScoutState>;
|
|
178
141
|
export default _default;
|
package/dist/store/scout.js
CHANGED
|
@@ -10,13 +10,14 @@ const initialState = {
|
|
|
10
10
|
herd_modules: [],
|
|
11
11
|
status: EnumScoutStateStatus.LOADING,
|
|
12
12
|
herd_modules_loading_state: EnumHerdModulesLoadingState.NOT_LOADING,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
loading_performance: {
|
|
14
|
+
herd_modules_loaded_in_ms: null,
|
|
15
|
+
herd_modules_api_server_processing_ms: null,
|
|
16
|
+
herd_modules_api_total_request_ms: null,
|
|
17
|
+
user_api_duration_ms: null,
|
|
18
|
+
data_processing_duration_ms: null,
|
|
19
|
+
cache_load_duration_ms: null,
|
|
20
|
+
},
|
|
20
21
|
lastRefreshed: 0,
|
|
21
22
|
active_herd_id: null,
|
|
22
23
|
active_device_id: null,
|
|
@@ -40,23 +41,31 @@ export const scoutSlice = createSlice({
|
|
|
40
41
|
setHerdModulesLoadingState: (state, action) => {
|
|
41
42
|
state.herd_modules_loading_state = action.payload;
|
|
42
43
|
},
|
|
44
|
+
setLoadingPerformance: (state, action) => {
|
|
45
|
+
state.loading_performance = {
|
|
46
|
+
...state.loading_performance,
|
|
47
|
+
...action.payload,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
43
50
|
setHerdModulesLoadedInMs: (state, action) => {
|
|
44
|
-
state.herd_modules_loaded_in_ms = action.payload;
|
|
51
|
+
state.loading_performance.herd_modules_loaded_in_ms = action.payload;
|
|
45
52
|
},
|
|
46
53
|
setHerdModulesApiServerProcessingDuration: (state, action) => {
|
|
47
|
-
state.herd_modules_api_server_processing_ms =
|
|
54
|
+
state.loading_performance.herd_modules_api_server_processing_ms =
|
|
55
|
+
action.payload;
|
|
48
56
|
},
|
|
49
57
|
setHerdModulesApiTotalRequestDuration: (state, action) => {
|
|
50
|
-
state.herd_modules_api_total_request_ms =
|
|
58
|
+
state.loading_performance.herd_modules_api_total_request_ms =
|
|
59
|
+
action.payload;
|
|
51
60
|
},
|
|
52
61
|
setUserApiDuration: (state, action) => {
|
|
53
|
-
state.user_api_duration_ms = action.payload;
|
|
62
|
+
state.loading_performance.user_api_duration_ms = action.payload;
|
|
54
63
|
},
|
|
55
64
|
setDataProcessingDuration: (state, action) => {
|
|
56
|
-
state.data_processing_duration_ms = action.payload;
|
|
65
|
+
state.loading_performance.data_processing_duration_ms = action.payload;
|
|
57
66
|
},
|
|
58
67
|
setCacheLoadDuration: (state, action) => {
|
|
59
|
-
state.cache_load_duration_ms = action.payload;
|
|
68
|
+
state.loading_performance.cache_load_duration_ms = action.payload;
|
|
60
69
|
},
|
|
61
70
|
setActiveHerdId: (state, action) => {
|
|
62
71
|
state.active_herd_id = action.payload;
|
|
@@ -71,32 +80,11 @@ export const scoutSlice = createSlice({
|
|
|
71
80
|
setDataSourceInfo: (state, action) => {
|
|
72
81
|
state.data_source_info = action.payload;
|
|
73
82
|
},
|
|
74
|
-
|
|
75
|
-
const { herd_id,
|
|
76
|
-
const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
|
|
77
|
-
if (herd_module) {
|
|
78
|
-
herd_module.events = events;
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
appendEventsToHerdModule: (state, action) => {
|
|
82
|
-
const { herd_id, events } = action.payload;
|
|
83
|
-
const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
|
|
84
|
-
if (herd_module) {
|
|
85
|
-
herd_module.events = [...herd_module.events, ...events];
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
replaceArtifactsForHerdModule: (state, action) => {
|
|
89
|
-
const { herd_id, artifacts } = action.payload;
|
|
90
|
-
const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
|
|
91
|
-
if (herd_module) {
|
|
92
|
-
herd_module.artifacts = artifacts;
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
appendArtifactsToHerdModule: (state, action) => {
|
|
96
|
-
const { herd_id, artifacts } = action.payload;
|
|
83
|
+
updateSessionSummariesForHerdModule: (state, action) => {
|
|
84
|
+
const { herd_id, session_summaries } = action.payload;
|
|
97
85
|
const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
|
|
98
86
|
if (herd_module) {
|
|
99
|
-
herd_module.
|
|
87
|
+
herd_module.session_summaries = session_summaries;
|
|
100
88
|
}
|
|
101
89
|
},
|
|
102
90
|
appendPlansToHerdModule: (state, action) => {
|
|
@@ -121,60 +109,11 @@ export const scoutSlice = createSlice({
|
|
|
121
109
|
herd_module.devices = [...herd_module.devices, device];
|
|
122
110
|
}
|
|
123
111
|
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
event.tags = [];
|
|
130
|
-
}
|
|
131
|
-
event.tags.push(action.payload);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
deleteTag(state, action) {
|
|
138
|
-
console.log("[Redux] deleteTag action called with:", action.payload);
|
|
139
|
-
console.log("[Redux] deleteTag - Looking for tag ID:", action.payload.id);
|
|
140
|
-
for (const herd_module of state.herd_modules) {
|
|
141
|
-
for (const event of herd_module.events) {
|
|
142
|
-
if (!event.tags) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
console.log(`[Redux] deleteTag - Checking event ${event.id}, has ${event.tags.length} tags`);
|
|
146
|
-
for (const tag of event.tags) {
|
|
147
|
-
if (tag.id === action.payload.id) {
|
|
148
|
-
console.log(`[Redux] deleteTag - Found tag ${tag.id} in event ${event.id}, removing it`);
|
|
149
|
-
event.tags = event.tags.filter((t) => t.id !== tag.id);
|
|
150
|
-
console.log(`[Redux] deleteTag - After removal, event ${event.id} has ${event.tags.length} tags`);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
console.log("[Redux] deleteTag - Tag not found in any event");
|
|
157
|
-
},
|
|
158
|
-
updateTag(state, action) {
|
|
159
|
-
for (const herd_module of state.herd_modules) {
|
|
160
|
-
for (const event of herd_module.events) {
|
|
161
|
-
if (!event.tags) {
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
for (const tag of event.tags) {
|
|
165
|
-
if (tag.id === action.payload.id) {
|
|
166
|
-
tag.x = action.payload.x;
|
|
167
|
-
tag.y = action.payload.y;
|
|
168
|
-
tag.width = action.payload.width;
|
|
169
|
-
tag.height = action.payload.height;
|
|
170
|
-
tag.conf = action.payload.conf;
|
|
171
|
-
tag.class_name = action.payload.class_name;
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
},
|
|
112
|
+
// NOTE: Tag management will need to be updated to work with RTK Query
|
|
113
|
+
// These actions are commented out until we implement tag management with RTK Query
|
|
114
|
+
// addTag(state, action) { ... },
|
|
115
|
+
// deleteTag(state, action) { ... },
|
|
116
|
+
// updateTag(state, action) { ... },
|
|
178
117
|
addDevice(state, action) {
|
|
179
118
|
for (const herd_module of state.herd_modules) {
|
|
180
119
|
if (herd_module.herd.id === action.payload.herd_id) {
|
|
@@ -229,55 +168,8 @@ export const scoutSlice = createSlice({
|
|
|
229
168
|
}
|
|
230
169
|
}
|
|
231
170
|
},
|
|
232
|
-
//
|
|
233
|
-
|
|
234
|
-
const { herd_id, events } = action.payload;
|
|
235
|
-
const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
|
|
236
|
-
if (herd_module) {
|
|
237
|
-
herd_module.events = herd_module.events.map((event) => {
|
|
238
|
-
const updated_event = events.find((e) => e.id === event.id);
|
|
239
|
-
if (updated_event) {
|
|
240
|
-
return updated_event;
|
|
241
|
-
}
|
|
242
|
-
return event;
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
state.herd_modules = [...state.herd_modules];
|
|
246
|
-
},
|
|
247
|
-
updatePageIndexForHerdModule: (state, action) => {
|
|
248
|
-
const { herd_id, new_page_index } = action.payload;
|
|
249
|
-
const herd_module = state.herd_modules.find((hm) => hm.herd.id.toString() === herd_id);
|
|
250
|
-
if (herd_module) {
|
|
251
|
-
herd_module.events_page_index = new_page_index;
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
addSessionToStore: (state, action) => {
|
|
255
|
-
const session = action.payload;
|
|
256
|
-
// Find the herd module that contains the device for this session
|
|
257
|
-
for (const herd_module of state.herd_modules) {
|
|
258
|
-
const device = herd_module.devices.find((d) => d.id === session.device_id);
|
|
259
|
-
if (device) {
|
|
260
|
-
herd_module.sessions = [session, ...herd_module.sessions];
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
deleteSessionFromStore: (state, action) => {
|
|
266
|
-
const sessionId = action.payload.id;
|
|
267
|
-
for (const herd_module of state.herd_modules) {
|
|
268
|
-
herd_module.sessions = herd_module.sessions.filter((session) => session.id !== sessionId);
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
updateSessionInStore: (state, action) => {
|
|
272
|
-
const updatedSession = action.payload;
|
|
273
|
-
for (const herd_module of state.herd_modules) {
|
|
274
|
-
const sessionIndex = herd_module.sessions.findIndex((session) => session.id === updatedSession.id);
|
|
275
|
-
if (sessionIndex !== -1) {
|
|
276
|
-
herd_module.sessions[sessionIndex] = updatedSession;
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
},
|
|
171
|
+
// NOTE: Events, sessions, and artifacts are now handled by RTK Query
|
|
172
|
+
// These actions have been removed as they're no longer needed
|
|
281
173
|
setUser: (state, action) => {
|
|
282
174
|
state.user = action.payload;
|
|
283
175
|
},
|
|
@@ -287,5 +179,5 @@ export const scoutSlice = createSlice({
|
|
|
287
179
|
},
|
|
288
180
|
});
|
|
289
181
|
// Action creators are generated for each case reducer function
|
|
290
|
-
export const { setHerdModules, setStatus, setHerdModulesLoadingState, setHerdModulesLoadedInMs, setHerdModulesApiServerProcessingDuration, setHerdModulesApiTotalRequestDuration, setUserApiDuration, setDataProcessingDuration, setCacheLoadDuration, setActiveHerdId, setActiveDeviceId, setDataSource, setDataSourceInfo,
|
|
182
|
+
export const { setHerdModules, setStatus, setHerdModulesLoadingState, setLoadingPerformance, setHerdModulesLoadedInMs, setHerdModulesApiServerProcessingDuration, setHerdModulesApiTotalRequestDuration, setUserApiDuration, setDataProcessingDuration, setCacheLoadDuration, setActiveHerdId, setActiveDeviceId, setDataSource, setDataSourceInfo, updateSessionSummariesForHerdModule, appendPlansToHerdModule, setUser, addNewDeviceToHerdModule, updateDeviceForHerdModule, addDevice, deleteDevice, updateDevice, addPlan, deletePlan, updatePlan, setActiveHerdGpsTrackersConnectivity, } = scoutSlice.actions;
|
|
291
183
|
export default scoutSlice.reducer;
|
package/dist/types/db.d.ts
CHANGED
|
@@ -30,6 +30,24 @@ export type IArtifact = Database["public"]["Tables"]["artifacts"]["Row"];
|
|
|
30
30
|
export type IArtifactWithMediaUrl = IArtifact & {
|
|
31
31
|
media_url?: string | null;
|
|
32
32
|
};
|
|
33
|
+
export interface ISessionSummary {
|
|
34
|
+
total_session_time_minutes: number;
|
|
35
|
+
total_session_time_night_minutes: number;
|
|
36
|
+
total_session_time_day_minutes: number;
|
|
37
|
+
total_sessions: number;
|
|
38
|
+
first_session_timestamp: string | null;
|
|
39
|
+
last_session_timestamp: string | null;
|
|
40
|
+
total_distance_meters: number;
|
|
41
|
+
average_distance_meters: number;
|
|
42
|
+
session_time_by_version: Record<string, number>;
|
|
43
|
+
summary_generated_at: string;
|
|
44
|
+
filters_applied: {
|
|
45
|
+
start_date: string | null;
|
|
46
|
+
end_date: string | null;
|
|
47
|
+
device_id: number | null;
|
|
48
|
+
herd_id: number | null;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
33
51
|
export type ComponentInsert = Database["public"]["Tables"]["components"]["Insert"];
|
|
34
52
|
export type VersionsSoftwareInsert = Database["public"]["Tables"]["versions_software"]["Insert"];
|
|
35
53
|
export type ArtifactInsert = Database["public"]["Tables"]["artifacts"]["Insert"];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
-
import { IDevice,
|
|
2
|
+
import { IDevice, IHerd, IPlan, ILayer, IProvider, IUserAndRole, IZoneWithActions, ISessionSummary } from "../types/db";
|
|
3
3
|
import { EnumWebResponse } from "./requests";
|
|
4
4
|
export declare enum EnumHerdModulesLoadingState {
|
|
5
5
|
NOT_LOADING = "NOT_LOADING",
|
|
@@ -10,41 +10,29 @@ export declare enum EnumHerdModulesLoadingState {
|
|
|
10
10
|
export declare class HerdModule {
|
|
11
11
|
herd: IHerd;
|
|
12
12
|
devices: IDevice[];
|
|
13
|
-
events: IEventWithTags[];
|
|
14
13
|
zones: IZoneWithActions[];
|
|
15
|
-
sessions: ISessionWithCoordinates[];
|
|
16
|
-
artifacts: IArtifactWithMediaUrl[];
|
|
17
14
|
timestamp_last_refreshed: number;
|
|
18
15
|
user_roles: IUserAndRole[] | null;
|
|
19
|
-
events_page_index: number;
|
|
20
|
-
total_events: number;
|
|
21
|
-
total_events_with_filters: number;
|
|
22
|
-
total_artifacts: number;
|
|
23
16
|
labels: string[];
|
|
24
17
|
plans: IPlan[];
|
|
25
18
|
layers: ILayer[];
|
|
26
19
|
providers: IProvider[];
|
|
27
|
-
|
|
20
|
+
session_summaries: ISessionSummary | null;
|
|
21
|
+
constructor(herd: IHerd, devices: IDevice[], timestamp_last_refreshed: number, user_roles?: IUserAndRole[] | null, labels?: string[], plans?: IPlan[], zones?: IZoneWithActions[], layers?: ILayer[], providers?: IProvider[], session_summaries?: ISessionSummary | null);
|
|
28
22
|
to_serializable(): IHerdModule;
|
|
29
23
|
static from_herd(herd: IHerd, client: SupabaseClient): Promise<HerdModule>;
|
|
30
24
|
}
|
|
31
25
|
export interface IHerdModule {
|
|
32
26
|
herd: IHerd;
|
|
33
27
|
devices: IDevice[];
|
|
34
|
-
events: IEventWithTags[];
|
|
35
28
|
timestamp_last_refreshed: number;
|
|
36
29
|
user_roles: IUserAndRole[] | null;
|
|
37
|
-
events_page_index: number;
|
|
38
|
-
total_events: number;
|
|
39
|
-
total_events_with_filters: number;
|
|
40
30
|
labels: string[];
|
|
41
31
|
plans: IPlan[];
|
|
42
32
|
zones: IZoneWithActions[];
|
|
43
|
-
sessions: ISessionWithCoordinates[];
|
|
44
33
|
layers: ILayer[];
|
|
45
34
|
providers: IProvider[];
|
|
46
|
-
|
|
47
|
-
total_artifacts: number;
|
|
35
|
+
session_summaries: ISessionSummary | null;
|
|
48
36
|
}
|
|
49
37
|
export interface IHerdModulesResponse {
|
|
50
38
|
data: IHerdModule[];
|
|
@@ -11,6 +11,7 @@ import { server_get_more_zones_and_actions_for_herd } from "../helpers/zones";
|
|
|
11
11
|
import { server_list_api_keys_batch } from "../api_keys/actions";
|
|
12
12
|
import { server_get_sessions_by_herd_id } from "../helpers/sessions";
|
|
13
13
|
import { server_get_artifacts_by_herd, server_get_total_artifacts_by_herd, } from "../helpers/artifacts";
|
|
14
|
+
import { server_get_session_summaries_by_herd } from "../helpers/session_summaries";
|
|
14
15
|
export var EnumHerdModulesLoadingState;
|
|
15
16
|
(function (EnumHerdModulesLoadingState) {
|
|
16
17
|
EnumHerdModulesLoadingState["NOT_LOADING"] = "NOT_LOADING";
|
|
@@ -19,51 +20,36 @@ export var EnumHerdModulesLoadingState;
|
|
|
19
20
|
EnumHerdModulesLoadingState["UNSUCCESSFULLY_LOADED"] = "UNSUCCESSFULLY_LOADED";
|
|
20
21
|
})(EnumHerdModulesLoadingState || (EnumHerdModulesLoadingState = {}));
|
|
21
22
|
export class HerdModule {
|
|
22
|
-
constructor(herd, devices,
|
|
23
|
+
constructor(herd, devices, timestamp_last_refreshed, user_roles = null, labels = [], plans = [], zones = [], layers = [], providers = [], session_summaries = null) {
|
|
23
24
|
this.user_roles = null;
|
|
24
|
-
this.events_page_index = 0;
|
|
25
|
-
this.total_events = 0;
|
|
26
|
-
this.total_events_with_filters = 0;
|
|
27
|
-
this.total_artifacts = 0;
|
|
28
25
|
this.labels = [];
|
|
29
26
|
this.plans = [];
|
|
30
27
|
this.layers = [];
|
|
31
28
|
this.providers = [];
|
|
29
|
+
this.session_summaries = null;
|
|
32
30
|
this.herd = herd;
|
|
33
31
|
this.devices = devices;
|
|
34
|
-
this.events = events;
|
|
35
32
|
this.timestamp_last_refreshed = timestamp_last_refreshed;
|
|
36
33
|
this.user_roles = user_roles;
|
|
37
|
-
this.events_page_index = events_page_index;
|
|
38
|
-
this.total_events = total_events;
|
|
39
|
-
this.total_events_with_filters = total_events_with_filters;
|
|
40
34
|
this.labels = labels;
|
|
41
35
|
this.plans = plans;
|
|
42
36
|
this.zones = zones;
|
|
43
|
-
this.sessions = sessions;
|
|
44
37
|
this.layers = layers;
|
|
45
38
|
this.providers = providers;
|
|
46
|
-
this.
|
|
47
|
-
this.total_artifacts = total_artifacts;
|
|
39
|
+
this.session_summaries = session_summaries;
|
|
48
40
|
}
|
|
49
41
|
to_serializable() {
|
|
50
42
|
return {
|
|
51
43
|
herd: this.herd,
|
|
52
44
|
devices: this.devices,
|
|
53
|
-
events: this.events,
|
|
54
45
|
timestamp_last_refreshed: this.timestamp_last_refreshed,
|
|
55
46
|
user_roles: this.user_roles,
|
|
56
|
-
events_page_index: this.events_page_index,
|
|
57
|
-
total_events: this.total_events,
|
|
58
|
-
total_events_with_filters: this.total_events_with_filters,
|
|
59
47
|
labels: this.labels,
|
|
60
48
|
plans: this.plans,
|
|
61
49
|
zones: this.zones,
|
|
62
|
-
sessions: this.sessions,
|
|
63
50
|
layers: this.layers,
|
|
64
51
|
providers: this.providers,
|
|
65
|
-
|
|
66
|
-
total_artifacts: this.total_artifacts,
|
|
52
|
+
session_summaries: this.session_summaries,
|
|
67
53
|
};
|
|
68
54
|
}
|
|
69
55
|
static async from_herd(herd, client) {
|
|
@@ -111,6 +97,10 @@ export class HerdModule {
|
|
|
111
97
|
console.warn(`[HerdModule] Failed to get total artifacts count:`, error);
|
|
112
98
|
return { status: EnumWebResponse.ERROR, data: null };
|
|
113
99
|
}),
|
|
100
|
+
server_get_session_summaries_by_herd(herd.id, client).catch((error) => {
|
|
101
|
+
console.warn(`[HerdModule] Failed to get session summaries:`, error);
|
|
102
|
+
return { status: EnumWebResponse.ERROR, data: null };
|
|
103
|
+
}),
|
|
114
104
|
]);
|
|
115
105
|
// Load devices
|
|
116
106
|
const devicesPromise = get_devices_by_herd(herd.id, client);
|
|
@@ -123,7 +113,7 @@ export class HerdModule {
|
|
|
123
113
|
if (deviceResponse.status == EnumWebResponse.ERROR ||
|
|
124
114
|
!deviceResponse.data) {
|
|
125
115
|
console.warn(`[HerdModule] No devices found for herd ${herd.id}`);
|
|
126
|
-
return new HerdModule(herd, [],
|
|
116
|
+
return new HerdModule(herd, [], Date.now());
|
|
127
117
|
}
|
|
128
118
|
const new_devices = deviceResponse.data;
|
|
129
119
|
// Load API keys for devices if we have any
|
|
@@ -143,7 +133,7 @@ export class HerdModule {
|
|
|
143
133
|
}
|
|
144
134
|
}
|
|
145
135
|
// Extract herd-level data with safe fallbacks
|
|
146
|
-
const [res_zones, res_user_roles, total_event_count, res_plans, res_sessions, res_layers, res_providers, res_artifacts, total_artifact_count,] = herdLevelResults;
|
|
136
|
+
const [res_zones, res_user_roles, total_event_count, res_plans, res_sessions, res_layers, res_providers, res_artifacts, total_artifact_count, session_summaries_result,] = herdLevelResults;
|
|
147
137
|
const zones = res_zones.status === "fulfilled" && res_zones.value?.data
|
|
148
138
|
? res_zones.value.data
|
|
149
139
|
: [];
|
|
@@ -173,19 +163,23 @@ export class HerdModule {
|
|
|
173
163
|
total_artifact_count.value?.data
|
|
174
164
|
? total_artifact_count.value.data
|
|
175
165
|
: 0;
|
|
166
|
+
const session_summaries = session_summaries_result.status === "fulfilled" &&
|
|
167
|
+
session_summaries_result.value?.data
|
|
168
|
+
? session_summaries_result.value.data
|
|
169
|
+
: null;
|
|
176
170
|
// TODO: store in DB and retrieve on load?
|
|
177
171
|
const newLabels = LABELS;
|
|
178
172
|
const endTime = Date.now();
|
|
179
173
|
const loadTime = endTime - startTime;
|
|
180
174
|
console.log(`[HerdModule] Loaded herd ${herd.slug} in ${loadTime}ms (${new_devices.length} devices)`);
|
|
181
|
-
return new HerdModule(herd, new_devices,
|
|
175
|
+
return new HerdModule(herd, new_devices, Date.now(), user_roles, newLabels, plans, zones, layers, providers, session_summaries);
|
|
182
176
|
}
|
|
183
177
|
catch (error) {
|
|
184
178
|
const endTime = Date.now();
|
|
185
179
|
const loadTime = endTime - startTime;
|
|
186
180
|
console.error(`[HerdModule] Critical error in HerdModule.from_herd (${loadTime}ms):`, error);
|
|
187
181
|
// Return a minimal but valid HerdModule instance to prevent complete failure
|
|
188
|
-
return new HerdModule(herd, [],
|
|
182
|
+
return new HerdModule(herd, [], Date.now(), null, [], [], [], [], [], null);
|
|
189
183
|
}
|
|
190
184
|
}
|
|
191
185
|
}
|