Merge pull request #1868 from bluewave-labs/feat/depin-monitors-initial-data-fetch
feat: depin monitors initial data fetch, #1867
This commit is contained in:
2 files changed
+62
No files matched your search
@@ -20,6 +20,43 @@ const useSubscribeToMonitors = (page, rowsPerPage) => {
|
|||||||
const { getMonitorWithPercentage } = useMonitorUtils();
|
const { getMonitorWithPercentage } = useMonitorUtils();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const fetchInitialData = async () => {
|
||||||
|
try {
|
||||||
|
const initialDataRes = await networkService.getDistributedUptimeMonitors({
|
||||||
|
teamId: user.teamId,
|
||||||
|
limit: 25,
|
||||||
|
types: [
|
||||||
|
typeof import.meta.env.VITE_DEPIN_TESTING === "undefined"
|
||||||
|
? "distributed_http"
|
||||||
|
: "distributed_test",
|
||||||
|
],
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
});
|
||||||
|
const responseData = initialDataRes?.data?.data;
|
||||||
|
if (typeof responseData === "undefined") throw new Error("No data");
|
||||||
|
|
||||||
|
const { monitors, filteredMonitors, summary } = responseData;
|
||||||
|
|
||||||
|
const mappedMonitors = filteredMonitors?.map((monitor) =>
|
||||||
|
getMonitorWithPercentage(monitor, theme)
|
||||||
|
);
|
||||||
|
|
||||||
|
setMonitors(monitors);
|
||||||
|
setMonitorsSummary(summary);
|
||||||
|
setFilteredMonitors(mappedMonitors);
|
||||||
|
} catch (error) {
|
||||||
|
setNetworkError(true);
|
||||||
|
createToast({
|
||||||
|
body: error.message,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchInitialData();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cleanup = networkService.subscribeToDistributedUptimeMonitors({
|
const cleanup = networkService.subscribeToDistributedUptimeMonitors({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
|
|||||||
@@ -807,6 +807,31 @@ class NetworkService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDistributedUptimeMonitors(config) {
|
||||||
|
const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config;
|
||||||
|
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
|
if (limit) params.append("limit", limit);
|
||||||
|
if (types) {
|
||||||
|
types.forEach((type) => {
|
||||||
|
params.append("type", type);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (page) params.append("page", page);
|
||||||
|
if (rowsPerPage) params.append("rowsPerPage", rowsPerPage);
|
||||||
|
if (filter) params.append("filter", filter);
|
||||||
|
if (field) params.append("field", field);
|
||||||
|
if (order) params.append("order", order);
|
||||||
|
|
||||||
|
if (this.eventSource) {
|
||||||
|
this.eventSource.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `${this.axiosInstance.defaults.baseURL}/distributed-uptime/monitors/${teamId}/initial?${params.toString()}`;
|
||||||
|
return this.axiosInstance.get(url);
|
||||||
|
}
|
||||||
|
|
||||||
subscribeToDistributedUptimeMonitors(config) {
|
subscribeToDistributedUptimeMonitors(config) {
|
||||||
const {
|
const {
|
||||||
teamId,
|
teamId,
|
||||||
|
|||||||
Reference in new issue
Block a user