frappe / frappe/frappe-react-sdk

request new function to get the childtable

Open
#69 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
189
Forks
63
PR merge metrics
No merged PRs in 30d

Description

For example, Delivery Note and Delivery Note Item have a parent-child relationship.

I expect a function that can query the fields of the parent table Delivery Note and the child table Delivery Note Item at once.

I tried reading using something like the following, but I couldn't read the ChildDocType.

After carefully studying Frappe's logic for reading child table data, it should be similar to the following reading logic, note the parameter **parent=Delivery%20Note**

```
http://192.168.32.2:8001/api/resource/Delivery%20Item?&parent=Delivery%20Note&fields=[%20"name",%20"item_code",%20"qty"%20]&filters=[[%20"parent",%20"=",%20"MAT-DN-2024-00001%20"]]
```

```
*/
export const useFrappeCascadeGetDocList = >(MainDocType: string, ChildDocType: string, mainArgs?: GetDocListArgs, childArgs?: GetDocListArgs, swrKey?: Key, options?: SWRConfiguration) => {

const { url, db } = useContext(FrappeContext) as FrappeConfig;


const swrResult = useSWR(
swrKey === undefined ? `${getRequestURL(MainDocType, url)}?${getDocListQueryString(mainArgs)}` : swrKey,
() => db.getDocList(MainDocType, mainArgs),
options
);


const childSWRKey = swrResult.data ? `${getRequestURL(ChildDocType, url)}?${getDocListQueryString(childArgs)}` : null;


const childSWRResult = useSWR(childSWRKey, () => db.getDocList(ChildDocType, childArgs), {
...options,
revalidateOnFocus: false,
shouldRetryOnError: false,
});

return {
mainDocs: swrResult,
childDocs: childSWRResult,
};
};
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the existing db.getDocList entry point and the proposed useFrappeCascadeGetDocList hook, then inspect getRequestURL and getDocListQueryString to understand how parent and child queries are built. Define the expected parent-child result shape and query behavior, then add coverage for retrieving Delivery Note and Delivery Note Item data together.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
api, frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.