kopia lustrzana https://github.com/wagtail/wagtail
Add typings for API
rodzic
61692b3ffa
commit
ae80df24b7
|
@ -1,30 +0,0 @@
|
|||
import { get } from '../api/client';
|
||||
|
||||
import { ADMIN_API } from '../config/wagtailConfig';
|
||||
|
||||
|
||||
export const getPage = (id) => {
|
||||
const url = `${ADMIN_API.PAGES}${id}/`;
|
||||
|
||||
return get(url);
|
||||
};
|
||||
|
||||
export const getPageChildren = (id, options = {}) => {
|
||||
let url = `${ADMIN_API.PAGES}?child_of=${id}&for_explorer=1`;
|
||||
|
||||
if (options.fields) {
|
||||
url += `&fields=${global.encodeURIComponent(options.fields.join(','))}`;
|
||||
}
|
||||
|
||||
if (options.onlyWithChildren) {
|
||||
url += '&has_children=1';
|
||||
}
|
||||
|
||||
if (options.offset) {
|
||||
url += `&offset=${options.offset}`;
|
||||
}
|
||||
|
||||
url += ADMIN_API.EXTRA_CHILDREN_PARAMETERS;
|
||||
|
||||
return get(url);
|
||||
};
|
|
@ -0,0 +1,59 @@
|
|||
import { get } from '../api/client';
|
||||
|
||||
import { ADMIN_API } from '../config/wagtailConfig';
|
||||
|
||||
export interface WagtailPageAPI {
|
||||
id: number;
|
||||
meta: {
|
||||
status: {
|
||||
status: string;
|
||||
live: boolean;
|
||||
/* eslint-disable-next-line camelcase */
|
||||
has_unpublished_changes: boolean;
|
||||
}
|
||||
children: any;
|
||||
};
|
||||
/* eslint-disable-next-line camelcase */
|
||||
admin_display_title?: string;
|
||||
}
|
||||
|
||||
interface WagtailPageListAPI {
|
||||
meta: {
|
||||
/* eslint-disable-next-line camelcase */
|
||||
total_count: number;
|
||||
};
|
||||
items: WagtailPageAPI[];
|
||||
}
|
||||
|
||||
export const getPage: (id: number) => Promise<WagtailPageAPI> = (id) => {
|
||||
const url = `${ADMIN_API.PAGES}${id}/`;
|
||||
|
||||
return get(url);
|
||||
};
|
||||
|
||||
interface GetPageChildrenOptions {
|
||||
fields?: string[];
|
||||
onlyWithChildren?: boolean;
|
||||
offset?: number;
|
||||
}
|
||||
|
||||
type GetPageChildren = (id: number, options: GetPageChildrenOptions) => Promise<WagtailPageListAPI>;
|
||||
export const getPageChildren: GetPageChildren = (id, options = {}) => {
|
||||
let url = `${ADMIN_API.PAGES}?child_of=${id}&for_explorer=1`;
|
||||
|
||||
if (options.fields) {
|
||||
url += `&fields=${window.encodeURIComponent(options.fields.join(','))}`;
|
||||
}
|
||||
|
||||
if (options.onlyWithChildren) {
|
||||
url += '&has_children=1';
|
||||
}
|
||||
|
||||
if (options.offset) {
|
||||
url += `&offset=${options.offset}`;
|
||||
}
|
||||
|
||||
url += ADMIN_API.EXTRA_CHILDREN_PARAMETERS;
|
||||
|
||||
return get(url);
|
||||
};
|
|
@ -5,7 +5,7 @@ import { createAction } from '../../utils/actions';
|
|||
import { MAX_EXPLORER_PAGES } from '../../config/wagtailConfig';
|
||||
|
||||
import { State as ExplorerState, Action as ExplorerAction } from './reducers/explorer';
|
||||
import { State as NodeState, WagtailPageAPI, Action as NodeAction } from './reducers/nodes';
|
||||
import { State as NodeState, Action as NodeAction } from './reducers/nodes';
|
||||
|
||||
interface State {
|
||||
explorer: ExplorerState,
|
||||
|
@ -15,7 +15,7 @@ interface State {
|
|||
type Action = ExplorerAction | NodeAction;
|
||||
type ThunkActionType = ThunkAction<void, State, unknown, Action>;
|
||||
|
||||
const getPageSuccess = createAction('GET_PAGE_SUCCESS', (id: number, data: WagtailPageAPI) => ({ id, data }));
|
||||
const getPageSuccess = createAction('GET_PAGE_SUCCESS', (id: number, data: admin.WagtailPageAPI) => ({ id, data }));
|
||||
const getPageFailure = createAction('GET_PAGE_FAILURE', (id: number, error: Error) => ({ id, error }));
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ function getPage(id: number): ThunkActionType {
|
|||
const getChildrenStart = createAction('GET_CHILDREN_START', (id: number) => ({ id }));
|
||||
const getChildrenSuccess = createAction(
|
||||
'GET_CHILDREN_SUCCESS',
|
||||
(id, items: WagtailPageAPI[], meta: any) => ({ id, items, meta })
|
||||
(id, items: admin.WagtailPageAPI[], meta: any) => ({ id, items, meta })
|
||||
);
|
||||
const getChildrenFailure = createAction('GET_CHILDREN_FAILURE', (id: number, error: Error) => ({ id, error }));
|
||||
|
||||
|
|
|
@ -1,20 +1,6 @@
|
|||
import { WagtailPageAPI } from '../../../api/admin';
|
||||
import { OPEN_EXPLORER } from './explorer';
|
||||
|
||||
export interface WagtailPageAPI {
|
||||
id: number;
|
||||
meta: {
|
||||
status: {
|
||||
status: string;
|
||||
live: boolean;
|
||||
/* eslint-disable-next-line camelcase */
|
||||
has_unpublished_changes: boolean;
|
||||
}
|
||||
children: any;
|
||||
};
|
||||
/* eslint-disable-next-line camelcase */
|
||||
admin_display_title?: string;
|
||||
}
|
||||
|
||||
export interface PageState extends WagtailPageAPI {
|
||||
isFetching: boolean;
|
||||
isError: boolean;
|
||||
|
|
Ładowanie…
Reference in New Issue