Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from chec/bugfix/contentful-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ScopeyNZ authored Nov 23, 2021
2 parents d2dc5e4 + a3843f7 commit 1fb6ff2
Show file tree
Hide file tree
Showing 14 changed files with 1,150 additions and 33 deletions.
6 changes: 6 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default interface ContentfulConfig {
contentManagementApiKey: string;
environmentName: string;
selectedSpaces: Array<string>;
installed?: boolean;
}
62 changes: 44 additions & 18 deletions configuration-app/index.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,65 @@
import { createSDK } from '@chec/integration-configuration-sdk';

interface Option {
value: string,
label: string,
}

interface ContentfulConfig {
contentManagementApiKey: string
}
import {createSDK, Schema, SchemaFieldTypes, SelectSchemaItem,} from '@chec/integration-configuration-sdk';
import ContentfulConfig from '../config';

(async () => {
const sdk = await createSDK();

// Track changes over time to the API key and chosen organisation
let existingKey: string = '';

const baseFields = [
if (sdk.editMode) {
// Check if the integration is still running
// @ts-ignore
if (!Object.hasOwnProperty.call(sdk.config, 'installed') || !sdk.config.installed) {
sdk.setSchema([
{
type: SchemaFieldTypes.Html,
content: '<p>Please wait while the Commerce.js app is configured on contentful</p>',
}
]);
return;
}

// Fix dashboard to not have excessive spacing around p tags
sdk.setSchema([
{
type: SchemaFieldTypes.Html,
content: `
<p>Your contentful app is configured. When you create "short_text" content models, "Commerce.js" will appear under the
appearance tab for your model.</p>
<p>For more details, use the "Learn more" link on the right.</p>
`,
}
]);

return;
}

const baseFields: Schema<ContentfulConfig> = [
{
type: SchemaFieldTypes.Html,
content: `
<p><strong>This integration requires a Contentful personal access token.</strong> You can issue an access token
<a href="https://app.contentful.com/account/profile/cma_tokens" target="_blank" rel="noopener noreferrer">here</a></p>
`,
},
{
key: 'contentManagementApiKey',
label: 'Contentful Manangement API key',
type: 'api_key',
description: 'A Contentful Management API key is required to install the "Commerce.js for Contentful" app to your organisations, and configure the app on your selected spaces.',
label: 'Personal access token',
type: SchemaFieldTypes.ApiKey,
},
{
key: 'environmentName',
label: 'Environment name',
type: 'short_text',
type: SchemaFieldTypes.ShortText,
default: 'master',
description: 'The "environment" to install the app to in Contentful. Currently only one shared environment name is supported across all spaces. You may create multiple integrations if more environments are required.'
}
];
const spacesField = {
const spacesField: SelectSchemaItem<ContentfulConfig> = {
key: 'selectedSpaces',
label: 'Contentful spaces to install to',
type: 'select',
type: SchemaFieldTypes.Select,
options: [],
disabled: true,
multiselect: true,
Expand All @@ -56,7 +82,7 @@ interface ContentfulConfig {
const spaces = (await response.json()).items;

// Asynchronously load organisations for the dropdown, and set the schema to have these new options
sdk.setSchema([
sdk.setSchema<ContentfulConfig>([
...baseFields,
{
...spacesField,
Expand Down
9 changes: 9 additions & 0 deletions dist/config/index.179f86ed.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/config/index.179f86ed.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions dist/config/index.5eedff1e.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/config/index.5eedff1e.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/config/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Configuration App</title></head><body> <div id="app"></div> <script src="/index.ef6e8e99.js" type="module"></script><script src="/index.07e30950.js" nomodule="" defer></script> </body></html>
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Configuration App</title></head><body> <div id="app"></div> <script src="/index.5eedff1e.js" type="module"></script><script src="/index.179f86ed.js" nomodule="" defer></script> </body></html>
Loading

1 comment on commit 1fb6ff2

@vercel
Copy link

@vercel vercel bot commented on 1fb6ff2 Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.