Skip to content

Commit

Permalink
feat: ability to get all data from get endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
henrychoy committed Sep 19, 2024
1 parent e2e3ce9 commit abbba24
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/frontend/src/components/TableComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
dense
v-model:pagination="pagination"
@request="onRequest"
:rows-per-page-options="[5,10,15,20,25,50]"
:rows-per-page-options="[5,10,15,20,25,50,0]"
>
<template v-slot:header="props">
<q-tr :props="props">
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/dialogs/AssignPluginsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
try {
const res = await api.getData('plugins', {
search: val,
rowsPerPage: 100,
rowsPerPage: 0, // get all
index: 0
})
pluginOptions.value = res.data.data
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/dialogs/AssignTagsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
async function getTags() {
try {
const res = await api.getData('tags', {index: 0, rowsPerPage: 50, search: ''})
const res = await api.getData('tags', {index: 0, rowsPerPage: 0, search: ''})
tags.value = res.data.data
if(props.editObj.tags.length > 0) {
props.editObj.tags.forEach((tag) => {
Expand Down
43 changes: 38 additions & 5 deletions src/frontend/src/services/dataApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,24 @@ export async function getData<T extends ItemType>(type: T, pagination: Paginatio
const res = await axios.get(`/api/${type}/${showDrafts ? 'drafts/' : ''}`, {
params: {
index: pagination.index,
pageLength: pagination.rowsPerPage,
pageLength: pagination.rowsPerPage === 0 ? 100 : pagination.rowsPerPage, // 0 means GET ALL
search: urlEncode(pagination.search),
draftType: showDrafts ? 'new' : '',
sortBy: pagination.sortBy,
descending: pagination.descending,
},
})

// if GET ALL (rowsPerPage = 0), then keep on getting next page until there is no next
if(pagination.rowsPerPage === 0 && res.data.next) {
let nextUrl = res.data.next.replace("/v1", "")
while (nextUrl) {
const response = await axios.get(nextUrl)
res.data.data.push(...response.data.data)
nextUrl = response.data.next ? response.data.next.replace("/v1", "") : null
}
}

if(showDrafts && res.data.data) {
res.data.data.forEach((obj: any) => {
Object.assign(obj, obj.payload)
Expand All @@ -145,15 +156,26 @@ export async function getData<T extends ItemType>(type: T, pagination: Paginatio
}

export async function getJobs(id: number, pagination: Pagination) {
return await axios.get(`/api/experiments/${id}/jobs`, {
const res = await axios.get(`/api/experiments/${id}/jobs`, {
params: {
index: pagination.index,
pageLength: pagination.rowsPerPage,
pageLength: pagination.rowsPerPage === 0 ? 100 : pagination.rowsPerPage, // 0 means GET ALL
search: urlEncode(pagination.search),
sortBy: pagination.sortBy,
descending: pagination.descending,
}
})

// if GET ALL (rowsPerPage = 0), then keep on getting next page until there is no next
if(pagination.rowsPerPage === 0 && res.data.next) {
let nextUrl = res.data.next.replace("/v1", "")
while (nextUrl) {
const response = await axios.get(nextUrl)
res.data.data.push(...response.data.data)
nextUrl = response.data.next ? response.data.next.replace("/v1", "") : null
}
}
return res
}

function urlEncode(string: string) {
Expand Down Expand Up @@ -230,15 +252,26 @@ export async function deleteDraft<T extends ItemType>(type: T, draftId: number)
}

export async function getFiles(id: number, pagination: Pagination) {
return await axios.get(`/api/plugins/${id}/files`, {
const res = await axios.get(`/api/plugins/${id}/files`, {
params: {
index: pagination.index,
pageLength: pagination.rowsPerPage,
pageLength: pagination.rowsPerPage === 0 ? 100 : pagination.rowsPerPage, // 0 means GET ALL
search: urlEncode(pagination.search),
sortBy: pagination.sortBy,
descending: pagination.descending,
}
})

// if GET ALL (rowsPerPage = 0), then keep on getting next page until there is no next
if(pagination.rowsPerPage === 0 && res.data.next) {
let nextUrl = res.data.next.replace("/v1", "")
while (nextUrl) {
const response = await axios.get(nextUrl)
res.data.data.push(...response.data.data)
nextUrl = response.data.next ? response.data.next.replace("/v1", "") : null
}
}
return res
}

export async function getFile(pluginID: string, fileID: string) {
Expand Down
6 changes: 2 additions & 4 deletions src/frontend/src/views/CreateEntryPoint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,9 @@
try {
const res = await api.getData('queues', {
search: val,
rowsPerPage: 100,
rowsPerPage: 0, // get all
index: 0
})
console.log('ressss = ', res)
queues.value = res.data.data
} catch(err) {
notify.error(err.response.data.message)
Expand All @@ -379,10 +378,9 @@
try {
const res = await api.getData('plugins', {
search: val,
rowsPerPage: 100,
rowsPerPage: 0, // get all
index: 0
})
console.log('ressss = ', res)
plugins.value = res.data.data
} catch(err) {
notify.error(err.response.data.message)
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/views/CreateExperiment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
try {
const res = await api.getData('entrypoints', {
search: val,
rowsPerPage: 100,
rowsPerPage: 0, // get all
index: 0
})
entrypoints.value = res.data.data
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/views/CreateJob.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
try {
const res = await api.getData('queues', {
search: val,
rowsPerPage: 100,
rowsPerPage: 0, // get all
index: 0
})
queues.value = res.data.data
Expand All @@ -253,7 +253,7 @@
try {
const res = await api.getData('entrypoints', {
search: val,
rowsPerPage: 100,
rowsPerPage: 0, // get all
index: 0
})
entrypoints.value = res.data.data
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/src/views/CreatePluginFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,12 @@
]
async function getPluginParameterTypes(pagination) {
console.log('pagination = ', pagination)
pagination.rowsPerPage = 0 // get all
try {
const res = await api.getData('pluginParameterTypes', pagination)
pluginParameterTypes.value = res.data.data
tableRef.value.updateTotalRows(res.data.totalNumResults)
} catch(err) {
console.log('err = ', err)
notify.error(err.response.data.message)
}
}
Expand Down

0 comments on commit abbba24

Please sign in to comment.