Skip to content

Commit

Permalink
Parse data and total count as tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Oct 21, 2023
1 parent c7b060e commit 7a6fc10
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
10 changes: 4 additions & 6 deletions client/src/components/Grid/GridList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,19 @@ function applyFilter(filter: string, value: string, quoted = false) {
async function getGridData() {
if (gridConfig.value) {
try {
const response = await gridConfig.value.getData(
const [responseData, responseTotal] = await gridConfig.value.getData(
currentPage.value,
props.perPage,
sortBy.value,
sortDesc.value,
searchTerm.value
);
if (response.headers.total_matches) {
totalRows.value = parseInt(response.headers.total_matches);
}
gridData.value = response.data;
gridData.value = responseData;
totalRows.value = responseTotal;
errorMessage.value = "";
loading.value = false;
} catch (e) {
errorMessage.value = "Failed to obtain grid data.";
errorMessage.value = `Failed to obtain grid data: ${e}`;
loading.value = false;
}
}
Expand Down
10 changes: 1 addition & 9 deletions client/src/components/Grid/configs/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { AxiosResponse } from "axios";

import Filtering from "@/utils/filtering";

interface Action {
Expand Down Expand Up @@ -33,13 +31,7 @@ export interface Config {
actions: Array<Action>;
fields: Array<Field>;
filtering: Filtering<string>;
getData: (
currentPage: number,
perPage: number,
sortBy: string,
sortDesc: boolean,
search: string
) => Promise<AxiosResponse>;
getData: (currentPage: number, perPage: number, sortBy: string, sortDesc: boolean, search: string) => Promise<any>;
item: string;
plural: string;
sortBy: string;
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/Grid/configs/visualizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { errorMessageAsString, rethrowSimple } from "@/utils/simple-error";
/**
* Request and return data from server
*/
function getData(currentPage, perPage, sortBy, sortDesc, searchTerm) {
async function getData(currentPage, perPage, sortBy, sortDesc, searchTerm) {
const offset = perPage * (currentPage - 1);
let q = `/api/visualizations/detailed?limit=${perPage}&offset=${offset}&sort_by=${sortBy}&sort_desc=${sortDesc}`;
if (searchTerm) {
q += `&search=${searchTerm}`;
}
return axios.get(withPrefix(q));
const response = await axios.get(withPrefix(q));
const responseTotal = parseInt(response.headers.total_matches);
return [response.data, responseTotal];
}

/**
Expand Down

0 comments on commit 7a6fc10

Please sign in to comment.