Skip to content

Commit 7c27e20

Browse files
authored
Merge pull request #190 from pneumaticapp/frontend/templates/45407__datasets
45407 frontend [ templates ] Datasets
2 parents 1ea0118 + c4f8dac commit 7c27e20

147 files changed

Lines changed: 5617 additions & 783 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frontend/.storybook/initData.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ window['__pneumaticConfig'] = {
144144
tenantsCount: '/tenants/count',
145145
tenants: '/tenants',
146146
tenantToken: '/tenants/:id/token',
147+
datasets: '/datasets',
148+
dataset: '/datasets/:id',
147149
getFaq: '/faq',
148150
wsNotifications: '/ws/notifications',
149151
wsNewTask: '/ws/workflows/new-task',

frontend/config/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@
150150
"tenantsCount": "/tenants/count",
151151
"tenants": "/tenants",
152152
"tenantToken": "/tenants/:id/token",
153+
"datasets": "/datasets",
154+
"dataset": "/datasets/:id",
153155
"getFaq": "/faq",
154156
"wsNotifications": "/ws/notifications",
155157
"wsNewTask": "/ws/workflows/new-task",

frontend/package-lock.json

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
"@types/react-input-autosize": "^2.2.1",
164164
"@types/react-redux": "^7.1.2",
165165
"@types/react-responsive": "^8.0.2",
166-
"@types/react-router-dom": "^4.3.5",
166+
"@types/react-router-dom": "^5.3.3",
167167
"@types/react-table": "^7.7.14",
168168
"@types/react-transition-group": "^4.2.2",
169169
"@types/react-visibility-sensor": "^5.0.1",

frontend/src/public/api/commonRequest.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,23 @@ axiosInstance.interceptors.response.use(
9393
},
9494
);
9595

96+
export async function commonRequest(
97+
rawUrl: string,
98+
params: Partial<AxiosRequestConfig>,
99+
options: Partial<ICommonRequestOptions> & { responseType: 'empty' },
100+
): Promise<void>;
101+
export async function commonRequest<T>(
102+
rawUrl: string,
103+
params?: Partial<AxiosRequestConfig>,
104+
options?: Partial<ICommonRequestOptions>,
105+
): Promise<T>;
106+
107+
/* eslint-disable consistent-return */
96108
export async function commonRequest<T>(
97109
rawUrl: string,
98110
params: Partial<AxiosRequestConfig> = {},
99111
options: Partial<ICommonRequestOptions> = {},
100-
): Promise<T> {
112+
): Promise<T | void> {
101113
const {
102114
api: { publicUrl, urls },
103115
} = getBrowserConfigEnv();
@@ -114,14 +126,14 @@ export async function commonRequest<T>(
114126
const config: AxiosRequestConfig = {
115127
...params,
116128
timeout: timeOut,
117-
responseType: options.responseType === 'text' ? 'text' : 'json',
129+
responseType: options.responseType === 'text' || options.responseType === 'empty' ? 'text' : 'json',
118130
validateStatus: (status) => successStatusCodes.includes(status),
119131
};
120132

121133
const response = await axiosInstance(fullUrl, config);
122134

123-
if (options.responseType === 'text') {
124-
return response.data as T;
135+
if (options.responseType === 'empty') {
136+
return;
125137
}
126138

127139
return response.data as T;
@@ -130,6 +142,7 @@ export async function commonRequest<T>(
130142
throw error;
131143
}
132144
logger.error(error);
133-
return undefined as unknown as T;
145+
134146
}
135147
}
148+
/* eslint-enable consistent-return */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { commonRequest } from '../commonRequest';
2+
import { IDataset, ICreateDatasetParams } from '../../types/dataset';
3+
import { getBrowserConfigEnv } from '../../utils/getConfig';
4+
import { mapRequestBody } from '../../utils/mappers';
5+
6+
export function createDataset({ name, description, items }: ICreateDatasetParams) {
7+
const {
8+
api: { urls },
9+
} = getBrowserConfigEnv();
10+
11+
return commonRequest<IDataset>(
12+
urls.datasets,
13+
{
14+
method: 'POST',
15+
data: mapRequestBody({ name, description, items }),
16+
},
17+
{
18+
shouldThrow: true,
19+
},
20+
);
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { commonRequest } from '../commonRequest';
2+
import { IDeleteDatasetParams } from '../../types/dataset';
3+
import { getBrowserConfigEnv } from '../../utils/getConfig';
4+
5+
export function deleteDataset({ id }: IDeleteDatasetParams) {
6+
const {
7+
api: { urls },
8+
} = getBrowserConfigEnv();
9+
10+
const url = urls.dataset.replace(':id', String(id));
11+
12+
return commonRequest<void>(
13+
url,
14+
{
15+
method: 'DELETE',
16+
},
17+
{
18+
shouldThrow: true,
19+
responseType: 'empty',
20+
},
21+
);
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { commonRequest } from '../commonRequest';
2+
import { IDataset, IGetDatasetParams } from '../../types/dataset';
3+
import { getBrowserConfigEnv } from '../../utils/getConfig';
4+
5+
export function getDataset({ id, signal }: IGetDatasetParams) {
6+
const {
7+
api: { urls },
8+
} = getBrowserConfigEnv();
9+
10+
const url = urls.dataset.replace(':id', String(id));
11+
12+
return commonRequest<IDataset>(
13+
url,
14+
{
15+
method: 'GET',
16+
signal,
17+
},
18+
{
19+
shouldThrow: true,
20+
},
21+
);
22+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { commonRequest } from '../commonRequest';
2+
import { IGetDatasetsResponse, IGetDatasetsParams } from '../../types/dataset';
3+
import { datasetsOrderingMap } from '../../constants/sortings';
4+
import { getBrowserConfigEnv } from '../../utils/getConfig';
5+
6+
export function getDatasets(config: IGetDatasetsParams = {}) {
7+
const {
8+
api: { urls },
9+
} = getBrowserConfigEnv();
10+
11+
const { signal } = config;
12+
const queryString = getDatasetsQueryString(config);
13+
const url = queryString ? `${urls.datasets}?${queryString}` : urls.datasets;
14+
15+
return commonRequest<IGetDatasetsResponse>(
16+
url,
17+
{
18+
method: 'GET',
19+
signal,
20+
},
21+
{
22+
shouldThrow: true,
23+
},
24+
);
25+
}
26+
27+
function getDatasetsQueryString({ ordering, limit, offset }: IGetDatasetsParams): string {
28+
const backendOrdering = ordering ? datasetsOrderingMap[ordering] || ordering : undefined;
29+
30+
return [
31+
backendOrdering && `ordering=${backendOrdering}`,
32+
limit !== undefined && `limit=${limit}`,
33+
offset !== undefined && `offset=${offset}`,
34+
].filter(Boolean).join('&');
35+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { commonRequest } from '../commonRequest';
2+
import { IDataset, IUpdateDatasetParams } from '../../types/dataset';
3+
import { getBrowserConfigEnv } from '../../utils/getConfig';
4+
import { mapRequestBody } from '../../utils/mappers';
5+
6+
export function updateDataset({ id, signal, ...data }: IUpdateDatasetParams) {
7+
const {
8+
api: { urls },
9+
} = getBrowserConfigEnv();
10+
11+
const url = urls.dataset.replace(':id', String(id));
12+
13+
return commonRequest<IDataset>(
14+
url,
15+
{
16+
method: 'PATCH',
17+
data: mapRequestBody(data),
18+
signal,
19+
},
20+
{
21+
shouldThrow: true,
22+
},
23+
);
24+
}

0 commit comments

Comments
 (0)