-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneurojson.action.ts
More file actions
126 lines (114 loc) · 3.4 KB
/
Copy pathneurojson.action.ts
File metadata and controls
126 lines (114 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { createAsyncThunk } from "@reduxjs/toolkit";
import { fetchDocuments } from "services/couchDb.service";
import { NeurojsonService } from "services/neurojson.service";
export const fetchRegistry = createAsyncThunk(
"neurojson/fetchRegistry",
async () => {
const response = await NeurojsonService.getRegistry();
return response.database;
}
);
export const fetchDbInfo = createAsyncThunk(
"neurojson/fetchDbInfo",
async (dbName: string) => {
const response = await NeurojsonService.getDbInfo(dbName);
return response;
}
);
export const loadPaginatedData = createAsyncThunk(
"neurojson/loadPaginatedData",
async (
{
dbName,
offset,
limit,
}: { dbName: string; offset: number; limit: number },
{ rejectWithValue, dispatch, getState }
) => {
try {
const state = getState() as any;
const currentData = state.neurojson.data;
if (currentData.length > 0 && currentData[0]?.dbName !== dbName) {
dispatch({ type: "neurojson/resetData" });
}
const response = await NeurojsonService.getPaginatedData(
dbName,
offset,
limit
);
if (response.rows.length === 0) {
return rejectWithValue("No more data to load.");
}
response.rows = response.rows.map((row: any) => ({
...row,
dbName,
}));
return response;
} catch (error: any) {
return rejectWithValue(error.message || "Failed to load data.");
}
}
);
export const loadAllDocuments = createAsyncThunk(
"neurojson/loadAllDocuments",
async (dbName: string, { rejectWithValue }) => {
try {
const data = await fetchDocuments(dbName);
return data;
} catch (error: any) {
return rejectWithValue(error.message || "Failed to load documents.");
}
}
);
// fetch dataset detail for dataset detail page
export const fetchDocumentDetails = createAsyncThunk(
"neurojson/fetchDocumentDetails",
async (
{ dbName, docId, rev }: { dbName: string; docId: string; rev?: string },
{ rejectWithValue }
) => {
try {
const data = await NeurojsonService.getDocumentById(dbName, docId, rev);
return data;
} catch (error: any) {
return rejectWithValue("Failed to fetch document details.");
}
}
);
export const fetchDbStats = createAsyncThunk(
"neurojson/fetchDbStats",
async (_, { rejectWithValue }) => {
try {
const response = await NeurojsonService.getDbStats();
return response;
} catch (error: any) {
return rejectWithValue("Failed to fetch db stats");
}
}
);
export const fetchMetadataSearchResults = createAsyncThunk(
"neurojson/fetchMetadataSearchResults",
async (formData: any, { rejectWithValue }) => {
try {
const data = await NeurojsonService.getMetadataSearchResults(formData);
return data;
} catch (error: any) {
return rejectWithValue("Failed to fetch metadata search results");
}
}
);
// fetch data for metadata panel in dataset detail page
export const fetchDbInfoByDatasetId = createAsyncThunk(
"neurojson/fetchDbInfoByDatasetId",
async (
{ dbName, docId }: { dbName: string; docId: string },
{ rejectWithValue }
) => {
try {
const data = await NeurojsonService.getDbInfoByDatasetId(dbName, docId);
return { ...data, dbName, docId };
} catch (error: any) {
return rejectWithValue(error.message || "Failed to fetch dataset info.");
}
}
);