Skip to content

Commit

Permalink
fix: allow apps to opt out of plugin logic [LIBS-579] (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed May 6, 2024
1 parent 1cb93fb commit d450758
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
1 change: 1 addition & 0 deletions cli/config/plugin.webpack.config.js
Expand Up @@ -36,6 +36,7 @@ module.exports = ({ env: webpackEnv, config, paths }) => {
const shellEnv = getShellEnv({
plugin: 'true',
requiredProps: config.requiredProps ? config.requiredProps.join() : '',
skipPluginLogic: config.skipPluginLogic,
name: config.title,
...getPWAEnvVars(config),
})
Expand Down
39 changes: 20 additions & 19 deletions docs/config/d2-config-js-reference.md
Expand Up @@ -11,25 +11,26 @@ All properties are technically optional, but it is recommended to set them expli

The following configuration properties are supported:

| Property | Type | Default | Description |
| :--------------------: | :---------------------------: | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **type** | _string_ | **app** | Either **app**, **login_app** or **lib** |
| **name** | _string_ | `pkg.name` | A short, machine-readable unique name for this app |
| **title** | _string_ | `config.name` | The human-readable application title, which will appear in the HeaderBar |
| **direction** | `'ltr'`, `'rtl'`, or `'auto'` | `'ltr'` | Sets the `dir` HTML attribute on the `document` of the app. If set to `'auto'`, the direction will be inferred from the current user's UI locale setting. The header bar will always be considered 'auto' and is unaffected by this setting. |
| **id** | _string_ | | The ID of the app on the [App Hub](https://apps.dhis2.org/). Used when publishing the app to the App Hub with [d2 app scripts publish](../scripts/publish). See [this guide](https://developers.dhis2.org/docs/guides/publish-apphub/) to learn how to set up continuous delivery. |
| **description** | _string_ | `pkg.description` | A full-length description of the application |
| **author** | _string_ or _object_ | `pkg.author` | The name of the developer to include in the DHIS2 manifest, following [package.json author field syntax](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#people-fields-author-contributors). |
| **entryPoints.app** | _string_ | **./src/App** | The path to the application entrypoint (not used for libraries) |
| **entryPoints.plugin** | _string_ | | The path to the application's plugin entrypoint (not used for libraries) |
| **entryPoints.lib** | _string_ or _object_ | **./src/index** | The path to the library entrypoint(s) (not used for applications). Supports [conditional exports](https://nodejs.org/dist/latest-v16.x/docs/api/packages.html#packages_conditional_exports) |
| **dataStoreNamespace** | _string_ | | The DataStore and UserDataStore namespace to reserve for this application. The reserved namespace **must** be suitably unique, as other apps will fail to install if they attempt to reserve the same namespace - see the [webapp manifest docs](https://docs.dhis2.org/en/develop/loading-apps.html) |
| **customAuthorities** | _Array(string)_ | | An array of custom authorities to create when installing the app, these do not provide security protections in the DHIS2 REST API but can be assigned to user roles and used to modify the interface displayed to a user - see the [webapp manifest docs](https://docs.dhis2.org/en/develop/loading-apps.html) |
| **minDHIS2Version** | _string_ | | The minimum DHIS2 version the App supports (eg. '2.35'). Required when uploading an app to the App Hub. The app's major version in the app's package.json needs to be increased when changing this property. |
| **maxDHIS2Version** | _string_ | | The maximum DHIS2 version the App supports. |
| **coreApp** | _boolean_ | **false** | **ADVANCED** If true, build an app artifact to be included as a root-level core application |
| **standalone** | _boolean_ | **false** | **ADVANCED** If true, do NOT include a static BaseURL in the production app artifact. This includes the `Server` field in the login dialog, which is usually hidden and pre-configured in production. |
| **pwa** | _object_ | | **ADVANCED** Opts into and configures PWA settings for this app. Read more about the options in [the PWA docs](../pwa). |
| Property | Type | Default | Description |
| :--------------------: | :---------------------------: | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **type** | _string_ | **app** | Either **app**, **login_app** or **lib** |
| **name** | _string_ | `pkg.name` | A short, machine-readable unique name for this app |
| **title** | _string_ | `config.name` | The human-readable application title, which will appear in the HeaderBar |
| **direction** | `'ltr'`, `'rtl'`, or `'auto'` | `'ltr'` | Sets the `dir` HTML attribute on the `document` of the app. If set to `'auto'`, the direction will be inferred from the current user's UI locale setting. The header bar will always be considered 'auto' and is unaffected by this setting. |
| **id** | _string_ | | The ID of the app on the [App Hub](https://apps.dhis2.org/). Used when publishing the app to the App Hub with [d2 app scripts publish](../scripts/publish). See [this guide](https://developers.dhis2.org/docs/guides/publish-apphub/) to learn how to set up continuous delivery. |
| **description** | _string_ | `pkg.description` | A full-length description of the application |
| **author** | _string_ or _object_ | `pkg.author` | The name of the developer to include in the DHIS2 manifest, following [package.json author field syntax](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#people-fields-author-contributors). |
| **entryPoints.app** | _string_ | **./src/App** | The path to the application entrypoint (not used for libraries) |
| **entryPoints.plugin** | _string_ | | The path to the application's plugin entrypoint (not used for libraries) |
| **entryPoints.lib** | _string_ or _object_ | **./src/index** | The path to the library entrypoint(s) (not used for applications). Supports [conditional exports](https://nodejs.org/dist/latest-v16.x/docs/api/packages.html#packages_conditional_exports) |
| **skipPluginLogic** | _boolean_ | **false** | By default, plugin entry points will be wrapped with logic to allow the passing of properties and resizing between the parent app and the child plugin. This logic will allow users to use the plugin inside an app when wrapped in `<Plugin>` component from app-runtime. If set to true, this logic will not be loaded. |
| **dataStoreNamespace** | _string_ | | The DataStore and UserDataStore namespace to reserve for this application. The reserved namespace **must** be suitably unique, as other apps will fail to install if they attempt to reserve the same namespace - see the [webapp manifest docs](https://docs.dhis2.org/en/develop/loading-apps.html) |
| **customAuthorities** | _Array(string)_ | | An array of custom authorities to create when installing the app, these do not provide security protections in the DHIS2 REST API but can be assigned to user roles and used to modify the interface displayed to a user - see the [webapp manifest docs](https://docs.dhis2.org/en/develop/loading-apps.html) |
| **minDHIS2Version** | _string_ | | The minimum DHIS2 version the App supports (eg. '2.35'). Required when uploading an app to the App Hub. The app's major version in the app's package.json needs to be increased when changing this property. |
| **maxDHIS2Version** | _string_ | | The maximum DHIS2 version the App supports. |
| **coreApp** | _boolean_ | **false** | **ADVANCED** If true, build an app artifact to be included as a root-level core application |
| **standalone** | _boolean_ | **false** | **ADVANCED** If true, do NOT include a static BaseURL in the production app artifact. This includes the `Server` field in the login dialog, which is usually hidden and pre-configured in production. |
| **pwa** | _object_ | | **ADVANCED** Opts into and configures PWA settings for this app. Read more about the options in [the PWA docs](../pwa). |

> _Note_: Dynamic defaults above may reference `pkg` (a property of the local `package.json` file) or `config` (another property within `d2.config.js`).
Expand Down
3 changes: 2 additions & 1 deletion shell/src/App.js
Expand Up @@ -29,6 +29,7 @@ const parseRequiredProps = (propsEnvVariable) => {
}

const isPlugin = process.env.REACT_APP_DHIS2_APP_PLUGIN === 'true'
const skipPluginLogic = process.env.REACT_APP_DHIS2_APP_SKIPPLUGINLOGIC
const requiredPluginProps = parseRequiredProps(
process.env.REACT_APP_DHIS2_APP_REQUIREDPROPS
)
Expand Down Expand Up @@ -86,7 +87,7 @@ Plugin.propTypes = {
}

const AppOrPlugin = () => {
if (isPlugin) {
if (isPlugin && !skipPluginLogic) {
return <Plugin config={pluginConfig} />
}
return <App config={appConfig} />
Expand Down

0 comments on commit d450758

Please sign in to comment.