向内容丰富的应用程序添加安装参数

问题描述 投票:0回答:3

努力寻找一个工作示例或文档来解释如何设置内容丰富的应用程序安装参数。我可以看到如何从 SDK 中获取它们,但我无法设置它们。

非常感谢任何帮助。

contentful contentful-management contentful-api contentful-vault
3个回答
1
投票

很可能您的应用程序有一个Config Location,这意味着您正在构建将在安装应用程序期间和之后向用户显示的 UI。在这个位置,有一个叫做

sdk.app.onConfigure
的SDK方法。此方法采用一个函数,该函数将返回一个名为
targetState
.

的对象

targetState
文档可以在here.

中找到

让我们以 React Config 应用程序为例,我们将设置

{foo: 'bar'}
作为我们的安装参数:

export default class Config extends Component<ConfigProps, ConfigState> {
  constructor(props: ConfigProps) {
    super(props);
    // letting the SDK know we have a configuration function which will
    // return `targetState`
    props.sdk.app.onConfigure(() => this.onConfigure());
  }

  // This method will be called when a user clicks on "Install"
  // or "Save" on the configuration screen.
  onConfigure = async () => {
    // the object returned here is what Contentful calls `targetState`.
    // it is simply a configuration object set when the app is installed or updated
    return {
        parameters: { installation: { foo: 'bar' } }
    };
  };

在上面的示例中,当用户在应用程序的配置位置点击“安装”或“保存”时,

{foo: 'bar'}
的安装参数对象将被保存,然后可以通过 SDK 在其他应用程序位置访问。

如果您纯粹使用 API 来创建或修改

AppInstallation
,您可以使用内容管理 API 更新应用程序的
parameters
,如文档 here 中所述。


0
投票

迟到的答案,但我也为此苦苦挣扎。我在这里找到了一个教程: https://dev.to/wiommi/how-i-built-a-contentful-app-combined-with-commerce-js-iii-33fo

它们在 ConfigScreen.tsx 中手动添加

您需要将它们添加到您的界面

export interface AppInstallationParameters {}

效果:

export interface AppInstallationParameters {
  apiKey?: string;
  projectId?: string;
}

然后用fx手动设置它们。

setParameters({ ...parameters, [PARAMETERNAME]: [PARAMETERVALUE] });

0
投票

您也可以在安装时设置安装参数,但是,您需要使用此端点进行安装并提供参数:

PUT /spaces/{space_id}/environments/{environment_id}/app_installations/{app_definition_id}
{
  "parameters": {
    "hello": "world"
  }
}

https://www.contentful.com/developers/docs/references/content-management-api/#/reference/app-installations/app-installation/install-or-update-an-app/console/curl

© www.soinside.com 2019 - 2024. All rights reserved.