-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add UIConfig and UserUIConfig [EXT-3738] (#1415)
* feat: add UIConfig and UserUIConfig * feat: export & move new types * fix: remove `isFolder` & `folderId` * fix: remove roles prop from UserUIConfig * test: add unit tests * test: unit test REST endpoints * docs: update js docs * fix: add page field * feat: remove page prop Co-authored-by: Kado <kadodamball@hotmail.com>
- Loading branch information
1 parent
166dd3d
commit 0fb8626
Showing
21 changed files
with
675 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { AxiosInstance } from 'contentful-sdk-core' | ||
import { SetOptional } from 'type-fest' | ||
import { GetUIConfigParams } from '../../../common-types' | ||
import { UIConfigProps } from '../../../entities/ui-config' | ||
import { RestEndpoint } from '../types' | ||
import * as raw from './raw' | ||
import copy from 'fast-copy' | ||
|
||
const getUrl = (params: GetUIConfigParams) => | ||
`/spaces/${params.spaceId}/environments/${params.environmentId}/ui_config` | ||
|
||
export const get: RestEndpoint<'UIConfig', 'get'> = ( | ||
http: AxiosInstance, | ||
params: GetUIConfigParams | ||
) => { | ||
return raw.get<UIConfigProps>(http, getUrl(params)) | ||
} | ||
|
||
export const update: RestEndpoint<'UIConfig', 'update'> = ( | ||
http: AxiosInstance, | ||
params: GetUIConfigParams, | ||
rawData: UIConfigProps | ||
) => { | ||
const data: SetOptional<typeof rawData, 'sys'> = copy(rawData) | ||
delete data.sys | ||
return raw.put<UIConfigProps>(http, getUrl(params), data, { | ||
headers: { | ||
'X-Contentful-Version': rawData.sys.version ?? 0, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { AxiosInstance } from 'contentful-sdk-core' | ||
import copy from 'fast-copy' | ||
import { SetOptional } from 'type-fest' | ||
import { GetUserUIConfigParams } from '../../../common-types' | ||
import { UserUIConfigProps } from '../../../entities/user-ui-config' | ||
import { RestEndpoint } from '../types' | ||
import * as raw from './raw' | ||
|
||
const getUrl = (params: GetUserUIConfigParams) => | ||
`/spaces/${params.spaceId}/environments/${params.environmentId}/ui_config/me` | ||
|
||
export const get: RestEndpoint<'UserUIConfig', 'get'> = ( | ||
http: AxiosInstance, | ||
params: GetUserUIConfigParams | ||
) => { | ||
return raw.get<UserUIConfigProps>(http, getUrl(params)) | ||
} | ||
|
||
export const update: RestEndpoint<'UserUIConfig', 'update'> = ( | ||
http: AxiosInstance, | ||
params: GetUserUIConfigParams, | ||
rawData: UserUIConfigProps | ||
) => { | ||
const data: SetOptional<typeof rawData, 'sys'> = copy(rawData) | ||
delete data.sys | ||
return raw.put<UserUIConfigProps>(http, getUrl(params), data, { | ||
headers: { | ||
'X-Contentful-Version': rawData.sys.version ?? 0, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { MakeRequest } from './common-types' | ||
import entities from './entities' | ||
import { UIConfig } from './entities/ui-config' | ||
|
||
/** | ||
* @private | ||
*/ | ||
export type ContentfulUIConfigApi = ReturnType<typeof createUIConfigApi> | ||
|
||
/** | ||
* @private | ||
*/ | ||
export default function createUIConfigApi(makeRequest: MakeRequest) { | ||
const { wrapUIConfig } = entities.uiConfig | ||
|
||
const getParams = (self: UIConfig) => { | ||
const uiConfig = self.toPlainObject() | ||
|
||
return { | ||
params: { | ||
spaceId: uiConfig.sys.space.sys.id, | ||
environmentId: uiConfig.sys.environment.sys.id, | ||
}, | ||
raw: uiConfig, | ||
} | ||
} | ||
|
||
return { | ||
/** | ||
* Sends an update to the server with any changes made to the object's properties | ||
* @return Object returned from the server with updated changes. | ||
* @example ```javascript | ||
* const contentful = require('contentful-management') | ||
* | ||
* const client = contentful.createClient({ | ||
* accessToken: '<content_management_api_key>' | ||
* }) | ||
* | ||
* client.getSpace('<space_id>') | ||
* .then((space) => space.getEnvironment('<environment_id>')) | ||
* .then((environment) => environment.getUIConfig()) | ||
* .then((uiConfig) => { | ||
* uiConfig.entryListViews = [...] | ||
* return uiConfig.update() | ||
* }) | ||
* .then((uiConfig) => console.log(`UIConfig updated.`)) | ||
* .catch(console.error) | ||
* ``` | ||
*/ | ||
update: async function update() { | ||
const { raw, params } = getParams(this) | ||
|
||
const data = await makeRequest({ | ||
entityType: 'UIConfig', | ||
action: 'update', | ||
params, | ||
payload: raw, | ||
}) | ||
return wrapUIConfig(makeRequest, data) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { MakeRequest } from './common-types' | ||
import entities from './entities' | ||
import { UserUIConfig } from './entities/user-ui-config' | ||
|
||
/** | ||
* @private | ||
*/ | ||
export type ContentfulUIConfigApi = ReturnType<typeof createUserUIConfigApi> | ||
|
||
/** | ||
* @private | ||
*/ | ||
export default function createUserUIConfigApi(makeRequest: MakeRequest) { | ||
const { wrapUserUIConfig } = entities.userUIConfig | ||
|
||
const getParams = (self: UserUIConfig) => { | ||
const userUIConfig = self.toPlainObject() | ||
|
||
return { | ||
params: { | ||
spaceId: userUIConfig.sys.space.sys.id, | ||
environmentId: userUIConfig.sys.environment.sys.id, | ||
}, | ||
raw: userUIConfig, | ||
} | ||
} | ||
|
||
return { | ||
/** | ||
* Sends an update to the server with any changes made to the object's properties | ||
* @return Object returned from the server with updated changes. | ||
* @example ```javascript | ||
* const contentful = require('contentful-management') | ||
* | ||
* const client = contentful.createClient({ | ||
* accessToken: '<content_management_api_key>' | ||
* }) | ||
* | ||
* client.getSpace('<space_id>') | ||
* .then((space) => space.getEnvironment('<environment_id>')) | ||
* .then((environment) => environment.getUserUIConfig()) | ||
* .then((uiConfig) => { | ||
* uiConfig.entryListViews = [...] | ||
* return uiConfig.update() | ||
* }) | ||
* .then((uiConfig) => console.log(`UserUIConfig updated.`)) | ||
* .catch(console.error) | ||
* ``` | ||
*/ | ||
update: async function update() { | ||
const { raw, params } = getParams(this) | ||
|
||
const data = await makeRequest({ | ||
entityType: 'UserUIConfig', | ||
action: 'update', | ||
params, | ||
payload: raw, | ||
}) | ||
return wrapUserUIConfig(makeRequest, data) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.