Skip to content

Commit

Permalink
refactor(ui-matrix): encode query string parameters in matrix endpoin…
Browse files Browse the repository at this point in the history
…t calls
  • Loading branch information
laurent-laporte-pro committed Feb 21, 2024
1 parent 5c269c6 commit 200899d
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions webapp/src/services/api/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export const getMatrixList = async (
name = "",
filterOwn = false,
): Promise<MatrixDataSetDTO[]> => {
const res = await client.get(
`/v1/matrixdataset/_search?name=${encodeURI(name)}&filter_own=${filterOwn}`,
);
const res = await client.get(`/v1/matrixdataset/_search`, {
params: { name: name, filter_own: filterOwn },
});
return res.data;
};

Expand All @@ -28,7 +28,7 @@ export const getMatrix = async (id: string): Promise<MatrixDTO> => {

export const getExportMatrixUrl = (matrixId: string): string =>
`${
getConfig().downloadHostUrl ||
getConfig().downloadHostUrl ??
getConfig().baseUrl + getConfig().restEndpoint
}/v1/matrix/${matrixId}/download`;

Expand All @@ -48,24 +48,21 @@ export const createMatrixByImportation = async (
if (onProgress) {
options.onUploadProgress = (progressEvent): void => {
const percentCompleted = Math.round(
(progressEvent.loaded * 100) / (progressEvent.total || 1),
(progressEvent.loaded * 100) / (progressEvent.total ?? 1),
);
onProgress(percentCompleted);
};
}
const formData = new FormData();
formData.append("file", file);
const restconfig = {
const restConfig = {
...options,
headers: {
"content-type": "multipart/form-data",
},
params: { json: json },
};
const res = await client.post(
`/v1/matrix/_import?json=${json}`,
formData,
restconfig,
);
const res = await client.post(`/v1/matrix/_import`, formData, restConfig);
return res.data;
};

Expand Down Expand Up @@ -96,18 +93,17 @@ export const editMatrix = async (
path: string,
matrixEdit: MatrixEditDTO[],
): Promise<void> => {
const res = await client.put(
`/v1/studies/${sid}/matrix?path=${path}`,
matrixEdit,
);
const res = await client.put(`/v1/studies/${sid}/matrix`, matrixEdit, {
params: { path: path },
});
return res.data;
};

export const getStudyMatrixIndex = async (
sid: string,
path?: string,
): Promise<MatrixIndex> => {
const query = path ? `?path=${encodeURIComponent(path)}` : "";
const res = await client.get(`/v1/studies/${sid}/matrixindex${query}`);
const restConfig = path ? { params: { path: path } } : {};
const res = await client.get(`/v1/studies/${sid}/matrixindex`, restConfig);
return res.data;
};

0 comments on commit 200899d

Please sign in to comment.