Skip to content

NocoBase 0.15:New plugin settings manager

Posted on:November 13, 2023 at 02:36 AM

Features

Plugin settings manager

Breaking changes

Plugin configuration page registration API

以前使用 SettingsCenterProvider 注册插件配置页面,现在需要通过插件注册。

Previously, the plugin configuration page was registered using SettingsCenterProvider, and now it needs to be registered through the plugin.

When there is only one Tab on the page, the new version of the Tab will be deleted, leaving only the title and icon of the page.

const HelloProvider = React.memo(props => {
  return (
    <SettingsCenterProvider
      settings={{
        hello: {
          title: "Hello",
          icon: "ApiOutlined",
          tabs: {
            tab1: {
              title: "Hello tab",
              component: HelloPluginSettingPage,
            },
          },
        },
      }}
    >
      {props.children}
    </SettingsCenterProvider>
  );
});

Now it needs to be changed to:

class HelloPlugin extends Plugin {
  async load() {
    this.app.pluginSettingsManager.add("hello", {
      title: "Hello",
      icon: "ApiOutlined",
      Component: HelloPluginSettingPage,
      // It is not necessary to pass this parameter if it is a new plugin
      aclSnippet: "pm.hello.tab1",
    });
  }
}

The Hello Tab of tab1 is deleted.

aclSnippet parameter pm.hello.tab1 corresponds to the key of the original settings object:

<SettingsCenterProvider
  settings={{
    hello: {
      // This `hello` corresponds to `hello` in `pm.hello.tab1`
      tabs: {
        tab1: {
          // Here, `tab1` corresponds to `tab1` in `pm.hello.tab1`
        },
      },
    },
  }}
></SettingsCenterProvider>
const HelloProvider = React.memo(props => {
  return (
    <SettingsCenterProvider
      settings={{
        hello: {
          title: "Hello",
          icon: "ApiOutlined",
          tabs: {
            tab1: {
              title: "Hello tab1",
              component: HelloPluginSettingPage1,
            },
            tab2: {
              title: "Hello tab2",
              component: HelloPluginSettingPage2,
            },
          },
        },
      }}
    >
      {props.children}
    </SettingsCenterProvider>
  );
});

Now it needs to be changed to:

import { Outlet } from "react-router-dom";

class HelloPlugin extends Plugin {
  async load() {
    this.app.pluginSettingsManager.add("hello", {
      title: "Hello",
      icon: "ApiOutlined",
      Component: Outlet,
    });

    this.app.pluginSettingsManager.add("hello.tab1", {
      title: "Hello tab1",
      Component: HelloPluginSettingPage1,
    });

    this.app.pluginSettingsManager.add("hello.tab2", {
      title: "Hello tab2",
      Component: HelloPluginSettingPage1,
    });
  }
}

Get the routing information corresponding to the pluginSettingsManager

const baseName = app.pluginSettingsManager.getRouteName("hello");
// admin.settings.hello
const basePath = app.pluginSettingsManager.getRoutePath("hello"); // /admin/settings.
// /admin/settings/hello

If there is a link jump inside the plugin configuration page, you need to change it accordingly, for example:

navigate("/admin/settings/hello/1").navigate("/admin/settings/hello/2");

// This can be changed to
const basePath = app.pluginSettingsManager.getRoutePath("hello");
navigate(`${basePath}/1`);
navigate(`${basePath}/2`);

For more information, see the plugin settings manager.

Changelog

For a complete changelog, please refer to Changelog.