Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Checkbox,
} from '@contentful/f36-components';
import { ExternalLinkIcon } from '@contentful/f36-icons';
import { ContentTypeProps, createClient } from 'contentful-management';
import { ContentTypeProps } from 'contentful-management';
import { KnownAppSDK, EditorInterface } from '@contentful/app-sdk';
import { KeyValueMap } from '@contentful/app-sdk/dist/types/entities';
import { useSDK } from '@contentful/react-apps-toolkit';
Expand Down Expand Up @@ -163,17 +163,13 @@ const AssignContentTypeSection = (props: Props) => {
}, [isContentTypeAssignmentValid, onIsValidContentTypeAssignment]);

const fetchAllContentTypes = async (sdk: KnownAppSDK): Promise<ContentTypeProps[]> => {
const cma = createClient({ apiAdapter: sdk.cmaAdapter });
const space = await cma.getSpace(sdk.ids.space);
const environment = await space.getEnvironment(sdk.ids.environment);

let allContentTypes: ContentTypeProps[] = [];
let skip = 0;
const limit = 100;
let areMoreContentTypes = true;

while (areMoreContentTypes) {
const response = await environment.getContentTypes({ skip, limit });
const response = await sdk.cma.contentType.getMany({ query: { skip, limit } });
if (response.items) {
allContentTypes = allContentTypes.concat(response.items as ContentTypeProps[]);
areMoreContentTypes = response.items.length === limit;
Expand Down
26 changes: 3 additions & 23 deletions apps/google-analytics-4/frontend/test/mocks/mockSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,9 @@ const mockSdk: any = {
appSignedRequest: {
create: () => ({}),
},
getSpace: () => ({
getEnvironment: () => ({
getContentTypes: () => ({
description:
'A series of lessons designed to teach sets of concepts that enable students to master Contentful.',
displayField: 'title',
name: 'Course',
fields: [
{
course: {
disabled: false,
id: 'title',
localized: true,
name: 'Title',
omitted: false,
required: true,
type: 'Symbol',
},
},
],
}),
}),
}),
contentType: {
getMany: vi.fn().mockResolvedValue({ items: [] }),
},
},
ids: {
app: 'test-app',
Expand Down
13 changes: 2 additions & 11 deletions apps/mux/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
} from './util/types';

import './index.css';
import { createClient, PlainClientAPI } from 'contentful-management';
import { PlainClientAPI } from 'contentful-management';
import {
MuxApiService,
MuxApiError,
Expand Down Expand Up @@ -105,16 +105,7 @@ export class App extends React.Component<AppProps, AppState> {
const { muxAccessTokenId, muxAccessTokenSecret } = this.props.sdk.parameters
.installation as InstallationParams;

this.cmaClient = createClient(
{ apiAdapter: this.props.sdk.cmaAdapter },
{
type: 'plain',
defaults: {
environmentId: this.props.sdk.ids.environmentAlias ?? this.props.sdk.ids.environment,
spaceId: this.props.sdk.ids.space,
},
}
);
this.cmaClient = this.props.sdk.cma;

const field = props.sdk.field.getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { Config, ParameterDefinition, ValidateParametersFn } from '@interfaces';

import { styles } from '@components/AppConfig/AppConfig.styles';
import { useSDK } from '@contentful/react-apps-toolkit';
import { createClient } from 'contentful-management';

interface Props {
parameterDefinitions: ParameterDefinition[];
Expand Down Expand Up @@ -83,13 +82,9 @@ export default function AppConfig({

useEffect(() => {
(async () => {
const cma = createClient({ apiAdapter: sdk.cmaAdapter });
const space = await cma.getSpace(sdk.ids.space);
const environment = await space.getEnvironment(sdk.ids.environment);

const [contentTypesResponse, eisResponse, parameters] = await Promise.all([
environment.getContentTypes(),
environment.getEditorInterfaces(),
sdk.cma.contentType.getMany({}),
sdk.cma.editorInterface.getMany({}),
sdk.app.getParameters(),
]);

Expand Down
Loading