Skip to content

Commit c771885

Browse files
committed
docs: add fieldsToReturn param usage example in background jobs plugin
AdminForth/1838/update-background-jobs-api-doc
1 parent 31163a5 commit c771885

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

adminforth/documentation/docs/tutorial/09-Plugins/23-background-jobs.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ const taskStatusLabels: Record<JobTask['status'], string> = {
410410

411411
const props = defineProps<{
412412
meta: any;
413-
getJobTasks: (limit?: number, offset?: number) => Promise<JobTask[]>;
413+
getJobTasks: (limit?: number, offset?: number, fieldsToReturn?: string[]) => Promise<JobTask[]>;
414414
subscribeToJobStateFields: (fieldNames: string[]) => () => void;
415415
subscribeToJobTaskFields: (fieldNames: string[]) => () => void;
416416
job: {
@@ -556,7 +556,6 @@ in the open job. Both helpers return an unsubscribe function, though the plugin
556556
remaining field subscriptions when the job dialog closes.
557557
558558
559-
560559
## Frontend API
561560
### Job info popup
562561
If you want to immediately open the job info popup, return the job ID from the API that creates the job:
@@ -591,6 +590,26 @@ For example:
591590

592591
```
593592
593+
### Filtering task fields you are getting on the frontend
594+
595+
Sometimes task state fields can be very complex and big, so when you run such a task with a big dataset and then fetch the tasks on the frontend, it can overload the browser with information you are not using. For those cases you can use the `fieldsToReturn` param in your custom component on the frontend to receive only the fields that you need.
596+
597+
```vue title="./custom/JobCustomComponent.vue"
598+
599+
...
600+
601+
async function loadTasks() {
602+
/**
603+
* props.getJobTasks will return only 'task_number' and 'task_counter',
604+
* so if you have data you don't want to send to the frontend, you can use this param
605+
*/
606+
tasks.value = await props.getJobTasks(100, 0, ['task_number', 'task_counter']);
607+
}
608+
609+
...
610+
611+
```
612+
594613
## Backend API
595614
596615
The plugin provides some handy methods that can be used in different situations:

0 commit comments

Comments
 (0)