1 1
import { get } from '../api/client';
2

3 1
import { ADMIN_API } from '../config/wagtailConfig';
4

5
export interface WagtailPageAPI {
6
  id: number;
7
  meta: {
8
    status: {
9
      status: string;
10
      live: boolean;
11
      /* eslint-disable-next-line camelcase */
12
      has_unpublished_changes: boolean;
13
    }
14
    children: any;
15
    parent: {
16
      id: number;
17
    } | null;
18
    locale?: string;
19
  };
20
  /* eslint-disable-next-line camelcase */
21
  admin_display_title?: string;
22
}
23

24
interface WagtailPageListAPI {
25
  meta: {
26
    /* eslint-disable-next-line camelcase */
27
    total_count: number;
28
  };
29
  items: WagtailPageAPI[];
30
}
31

32 1
export const getPage: (id: number) => Promise<WagtailPageAPI> = (id) => {
33 1
  const url = `${ADMIN_API.PAGES}${id}/`;
34

35 1
  return get(url);
36
};
37

38
interface GetPageChildrenOptions {
39
  fields?: string[];
40
  onlyWithChildren?: boolean;
41
  offset?: number;
42
}
43

44
type GetPageChildren = (id: number, options: GetPageChildrenOptions) => Promise<WagtailPageListAPI>;
45 1
export const getPageChildren: GetPageChildren = (id, options = {}) => {
46 1
  let url = `${ADMIN_API.PAGES}?child_of=${id}&for_explorer=1`;
47

48 1
  if (options.fields) {
49 1
    url += `&fields=parent,${window.encodeURIComponent(options.fields.join(','))}`;
50
  } else {
51 1
    url += '&fields=parent';
52
  }
53

54 1
  if (options.onlyWithChildren) {
55 1
    url += '&has_children=1';
56
  }
57

58 1
  if (options.offset) {
59 1
    url += `&offset=${options.offset}`;
60
  }
61

62 1
  url += ADMIN_API.EXTRA_CHILDREN_PARAMETERS;
63

64 1
  return get(url);
65
};

Read our documentation on viewing source code .

Loading