【问题标题】:Adding installation parameters to a contentful App向内容应用程序添加安装参数
【发布时间】:2021-10-18 11:58:41
【问题描述】:

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

非常感谢任何帮助。

【问题讨论】:

    标签: contentful contentful-management contentful-api contentful-vault


    【解决方案1】:

    迟到的答案,但我也很挣扎。我在这里找到了一个教程: 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] });
    

    【讨论】:

      【解决方案2】:

      您的应用很可能有 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,则可以使用 Content Management API 更新应用的 parameters,如文档 here 中所述。

      【讨论】:

        猜你喜欢
        • 2017-03-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多