Skip to content

Commit

Permalink
feat: option for configuring is_visible from globalConfig.json (#1345)
Browse files Browse the repository at this point in the history
**Issue number:** #1334 

## Summary
Provided option for configuring is_visible in globalConfig.json

### Changes

> Added the option `isVisible` in globalConfig.json, allowing users to
configure the add-on's UI visibility directly from the globalConfig.

### User experience

> Users will have additional option (`isVisible`) in meta tag of
globalConfig.json from where they can configure the add-on's UI
visibility.

## Checklist

If your change doesn't seem to apply, please leave them unchecked.

* [x] I have performed a self-review of this change
* [x] Changes have been tested
* [x] Changes are documented
* [x] PR title follows [conventional commit
semantics](https://www.conventionalcommits.org/en/v1.0.0/)
  • Loading branch information
hetangmodi-crest authored Sep 30, 2024
1 parent f124b5e commit 04c80e3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Metadata contains general information about add-on build.
| defaultView | string | Define which view should be loaded on TA load. One of `"inputs"`, `"configuration"`, `"dashboard"` or `"search"`. Default `configuration`. |
| [os-dependentLibraries](./advanced/os-dependent_libraries.md) | array | This feature allows you to download and unpack libraries with appropriate binaries for the indicated operating system during the build process. |
| supported_themes | array | This feature is allows you provide the themes supported by your add-on. Supported values: `light`, `dark`. No default. |
| isVisible | boolean | This option allows you to create apps which are not visible by default by setting isVisible=false. Default: true if globalConfig file exists in the repository, else false. |
7 changes: 4 additions & 3 deletions splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,9 @@ def generate(
app_manifest = _get_app_manifest(source)
ta_name = app_manifest.get_addon_name()
generated_files = []
ui_available = False

gc_path = _get_and_check_global_config_path(source, config_path)
if gc_path:
ui_available = True
logger.info(f"Using globalConfig file located @ {gc_path}")
global_config = global_config_lib.GlobalConfig(gc_path)
# handle the update of globalConfig before validating
Expand Down Expand Up @@ -506,7 +504,7 @@ def generate(
addon_name=ta_name,
app_manifest=app_manifest,
addon_version=addon_version,
has_ui=ui_available,
has_ui=global_config.meta.get("isVisible", True),
)
)
# TODO: all FILES GENERATED object: generated_files, use it for comparison
Expand Down Expand Up @@ -600,6 +598,9 @@ def generate(
f"Updated {app_manifest_lib.APP_MANIFEST_FILE_NAME} file in the output folder"
)

ui_available = False
if global_config:
ui_available = global_config.meta.get("isVisible", True)
# NOTE: merging source and generated 'app.conf' as per previous design
AppConf(
global_config=global_config,
Expand Down
5 changes: 5 additions & 0 deletions splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,11 @@
"dark"
]
}
},
"isVisible": {
"type": "boolean",
"default": true,
"description": "Ability to configure app.conf->ui.is_visible from globalConfig file."
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,7 @@
"supportedThemes": [
"light",
"dark"
]
],
"isVisible": true
}
}
15 changes: 11 additions & 4 deletions tests/unit/generators/conf_files/test_create_app_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def has_ui():
return True


@fixture
def has_ui_no_globalConfig():
return False


@fixture
def app_manifest():
mock_manifest = MagicMock()
Expand All @@ -60,7 +65,7 @@ def test_set_attributes_no_global_config_or_schema(
ucc_dir,
ta_name,
addon_version,
has_ui,
has_ui_no_globalConfig,
app_manifest,
):
"""Test _set_attributes when both _global_config and _gc_schema are None."""
Expand All @@ -71,14 +76,16 @@ def test_set_attributes_no_global_config_or_schema(
ucc_dir=ucc_dir,
addon_name=ta_name,
addon_version=addon_version,
has_ui=has_ui,
has_ui=has_ui_no_globalConfig,
app_manifest=app_manifest,
)
app_conf._global_config = None
app_conf._gc_schema = None

app_conf._set_attributes(
addon_version=addon_version, has_ui=has_ui, app_manifest=app_manifest
addon_version=addon_version,
has_ui=has_ui_no_globalConfig,
app_manifest=app_manifest,
)

assert app_conf.conf_file == "app.conf"
Expand All @@ -88,7 +95,7 @@ def test_set_attributes_no_global_config_or_schema(
assert app_conf.id == app_conf._addon_name
assert app_conf.supported_themes == ""
assert app_conf.addon_version == addon_version
assert app_conf.is_visible == "true"
assert app_conf.is_visible == "false"
assert app_conf.description == "Test Description"
assert app_conf.author == "Test Author"
assert app_conf.build == "1234"
Expand Down
2 changes: 2 additions & 0 deletions ui/src/types/globalConfig/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const meta = z.object({
hideUCCVersion: z.boolean().optional(),
checkForUpdates: z.boolean().default(true).optional(),
searchViewDefault: z.boolean().default(false).optional(),
isVisible: z.boolean().default(true).optional(),
supportedThemes: z.array(z.string()).optional(),
});

export type meta = z.infer<typeof meta>;

0 comments on commit 04c80e3

Please sign in to comment.