Skip to content

Commit

Permalink
feat: deprecated placeholder prop (#835)
Browse files Browse the repository at this point in the history
* feat: deprecated placeholder prop

* test: validate deprecation message being used
  • Loading branch information
artemrys authored Sep 18, 2023
1 parent c08dc01 commit 085e2b3
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 72 deletions.
6 changes: 5 additions & 1 deletion docs/advanced/oauth_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ Auth can be used inside the entity tag. Use `type: "oauth"` in the entity list a
- `field`: For now this user must keep it as it is for mandatory fields as mentioned above.
- `help` : This can be changed if user wants to change the help text displayed below field.
- `encrypted` : This should be true if user wants that particular field encrypted else no need to have this parameter.
- `placeholder`: The placeholder for the field.
- `required`: To specify whether the field is required or not. The default value is true.
- `options`:
- `placeholder`: The placeholder for the field.

> [!WARNING]
> [Placeholder](https://splunkui.splunkeng.com/Packages/react-ui/Text?section=develop) attribute is deprecated and will be removed in one of the following versions. Instead, we recommend using "help" attribute.
### Usage

Expand Down
2 changes: 1 addition & 1 deletion docs/custom_ui_extensions/custom_menu.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Custom Menu can be created when there is more than one input present on the inputs page.

> This feature is deprecated (will be removed in the next major version) as [`Multilevel Menu`](https://splunk.github.io/addonfactory-ucc-generator/tabs/#multi-level-menu) is now ready to use if more than one input is available.
> This feature is deprecated (will be removed in the next major version) as [`Multilevel Menu`](../inputs/multilevel_menu) is now ready to use if more than one input is available.
In addition to the multiple inputs, we can use this menu to create a custom component at the top right corner of the Input page.

Expand Down
3 changes: 2 additions & 1 deletion docs/entity/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ Multiselect allows the user to select multiple options at once.
| denyList | string | It filters options that don't match the regex based on the name attribute when received via API call using `endpointUrl` and `referenceName`. | - |
| labelField | string | TBD | - |
| [dependencies](../advanced/dependent_dropdown.md) | array | It is used to update options via an API call when the value of any field in the dependencies list is updated. | - |
| [autoCompleteFields](#autoCompleteFields) | array | It is used to add options in the Single select or Multiple select component. | - |

Example usage below:

Expand Down Expand Up @@ -368,7 +369,7 @@ It supports files that can be opened in text mode or with a text editor. Files w

It only sends file content to the server by reading it using the [readAsArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsArrayBuffer) method of the FileReader class and then decoding it into **UTF-8** format using the [decode](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode) method of the TextDecoder class.

File content can be validated using in-built validators like [string](../validators/#string) and [regex](../validators/#regex), and a custom validator can also be implemented using a [custom hook](../../custom_ui_extensions/custom_hook) and [saveValidator](../advances/../advanced/save_validator).
File content can be validated using in-built validators like [string](../validators/#string) and [regex](../validators/#regex), and a custom validator can also be implemented using a [custom hook](../../custom_ui_extensions/custom_hook) and [saveValidator](../advanced/save_validator).

This feature allows you to upload a single file.

Expand Down
8 changes: 6 additions & 2 deletions docs/entity/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ title: Entity
| field<span class="required-asterisk">*</span> | string | To define a particular entity field. | - |
| label<span class="required-asterisk">*</span> | string | It represents a caption for a field in a user interface. | - |
| [type](./components)<span class="required-asterisk">*</span> | string | To specify the type of entity to be rendered in inputs or configuration form. | - |
| help | string | Help text gives context about a field’s input, such as how the input will be used. It is displayed directly under an input field. | - |
| help | string | Help text gives context about a fields input, such as how the input will be used. It is displayed directly below an input field. | - |
| tooltip | string | Displays a tooltip beside the label. | - |
| defaultValue | string, number or boolean | The initial input value. | - |
| [options](#common-options) | object | To specify an additional attribute for a particular type of entity, such as `items` for a radio bar. | - |
| required | boolean | To specify whether the field is required or not. | false |
| encrypted | boolean | To encrypt that particular field. | false |
| [validators](./validators) | array | It is used to validate the values of fields using various validators. | - |

> [!WARNING]
> [Placeholder](https://splunkui.splunkeng.com/Packages/react-ui/Text?section=develop) attribute is deprecated and will be removed in the next major version. Instead, we recommend to use "help" attribute.
## Common Options

| Property | Type | Description | Default Value |
| ------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| placeholder | string | The grey text is shown when the input is empty.<br> This option will be removed when Splunk UI deprecates it in their next major release. | - |
| placeholder | string | `Deprecated` The grey text is shown when the input is empty. | - |
| display | boolean | Whether show or hide the field. | true |
| disableonEdit | boolean | When the form is in edit mode, the field becomes uneditable. | false |
| enable | boolean | The enable property sets whether a field is enabled, or not. | true |
4 changes: 2 additions & 2 deletions docs/inputs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Developers are required to add services in the global config file to create a ne
### Services Properties

| Property | Type | Description |
| ----------------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|-------------------------------------------------------------| ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name<span class="required-asterisk">*</span> | string | To define the particular service name. |
| title<span class="required-asterisk">*</span> | string | To show the title of the service. |
| subTitle | string | To show the subtitle (or additional information) of the service. |
| [entity](../entity)<span class="required-asterisk">*</span> | array | A list of fields and their properties. |
| [groups](../advanced/groups) | array | It is used to divide forms into distinct sections, each comprising relevant fields. |
| [groups](../advanced/groups_feature) | array | It is used to divide forms into distinct sections, each comprising relevant fields. |
| style | string | By specifying this property in the global config file, the forms can either be opened as a new page or in a dialog. <br>Supported values are "page" or "dialog". <br> Default value is **dialog**. |
| options | object | This property allows you to enable the [saveValidator](../advanced/save_validator) feature. |
| hook | object | It is used to add custom behaviour to forms. Visit the [Custom Hook](../custom_ui_extensions/custom_hook) page to learn more. |
Expand Down
2 changes: 1 addition & 1 deletion get-ucc-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
wget https://github.com/splunk/addonfactory-ucc-base-ui/releases/download/v1.29.2/splunk-ucc-ui.tgz
wget https://github.com/splunk/addonfactory-ucc-base-ui/releases/download/v1.29.3/splunk-ucc-ui.tgz
33 changes: 33 additions & 0 deletions splunk_add_on_ucc_framework/global_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import re
from typing import Any, Dict
import warnings

import jsonschema

Expand Down Expand Up @@ -440,6 +441,37 @@ def _validate_panels(self):
f"Supported panel names: {dashboard_lib.SUPPORTED_PANEL_NAMES_READABLE}"
)

def _warn_on_placeholder_usage(self):
"""
Warns if placeholder is used.
More details here: https://github.com/splunk/addonfactory-ucc-generator/issues/831.
"""
pages = self._config["pages"]
configuration = pages["configuration"]
tabs = configuration["tabs"]
for tab in tabs:
for entity in tab["entity"]:
if "placeholder" in entity.get("options", {}):
warnings.warn(
f"`placeholder` option found for configuration tab '{tab['name']}' "
f"-> entity field '{entity['field']}'. "
f"Please take a look at https://github.com/splunk/addonfactory-ucc-generator/issues/831.",
DeprecationWarning,
)
inputs = pages.get("inputs")
if inputs is None:
return
services = inputs["services"]
for service in services:
for entity in service["entity"]:
if "placeholder" in entity.get("options", {}):
warnings.warn(
f"`placeholder` option found for input service '{service['name']}' "
f"-> entity field '{entity['field']}'. "
f"Please take a look at https://github.com/splunk/addonfactory-ucc-generator/issues/831.",
DeprecationWarning,
)

def validate(self) -> None:
self._validate_config_against_schema()
self._validate_configuration_tab_table_has_name_field()
Expand All @@ -450,3 +482,4 @@ def validate(self) -> None:
self._validate_duplicates()
self._validate_alerts()
self._validate_panels()
self._warn_on_placeholder_usage()
11 changes: 0 additions & 11 deletions tests/ui/test_account_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,6 @@ def test_account_oauth_fields_label_entity(
self.assert_util(account.entity.client_secret.get_input_label, "Client Secret")
self.assert_util(account.entity.redirect_url.get_input_label, "Redirect url")

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.forwarder
@pytest.mark.account
def test_account_fields_placeholder_value(
self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper
):
"""Verifies account field placeholder value"""
account = AccountPage(ucc_smartx_selenium_helper, ucc_smartx_rest_helper)
account.entity.open()
self.assert_util(account.entity.name.get_placeholder_value, "Required")

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.account
def test_account_help_text_entity(
Expand Down
16 changes: 0 additions & 16 deletions tests/ui/test_custom_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,6 @@ def test_custom_fields_label_entity(
self.assert_util(custom.test_date.get_input_label, "Test Date")
self.assert_util(custom.test_url.get_input_label, "Test Url")

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.forwarder
@pytest.mark.custom
def test_custom_fields_placeholder_value(
self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper
):
"""Verifies custom fields placeholder value"""
custom = CustomPage(ucc_smartx_selenium_helper, ucc_smartx_rest_helper)
self.assert_util(custom.test_string.get_placeholder_value, "optional")
self.assert_util(custom.test_number.get_placeholder_value, "optional")
self.assert_util(custom.test_regex.get_placeholder_value, "optional")
self.assert_util(custom.test_email.get_placeholder_value, "optional")
self.assert_util(custom.test_ipv4.get_placeholder_value, "optional")
self.assert_util(custom.test_date.get_placeholder_value, "optional")
self.assert_util(custom.test_url.get_placeholder_value, "optional")

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.forwarder
@pytest.mark.custom
Expand Down
26 changes: 0 additions & 26 deletions tests/ui/test_input_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,32 +901,6 @@ def test_example_input_two_fields_label_entity(
input_page.entity2.query_start_date.get_input_label, "Query Start Date"
)

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.forwarder
@pytest.mark.input
def test_example_input_one_fields_placeholder_value(
self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper
):
"""Verifies example input one field placeholder value"""
input_page = InputPage(ucc_smartx_selenium_helper, ucc_smartx_rest_helper)
input_page.create_new_input.select("Example Input One")
self.assert_util(
input_page.entity1.query_start_date.get_placeholder_value, "optional"
)

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.forwarder
@pytest.mark.input
def test_example_input_two_fields_placeholder_value(
self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper
):
"""Verifies example input two field placeholder value"""
input_page = InputPage(ucc_smartx_selenium_helper, ucc_smartx_rest_helper)
input_page.create_new_input.select("Example Input Two")
self.assert_util(
input_page.entity1.query_start_date.get_placeholder_value, "optional"
)

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.forwarder
@pytest.mark.input
Expand Down
6 changes: 0 additions & 6 deletions tests/ui/test_proxy_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ def test_proxy_misc(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper):
self.assert_util(proxy.password.get_input_label, "Password")
self.assert_util(proxy.dns_enable.get_input_label, "Reverse DNS resolution")

# Placeholder
self.assert_util(proxy.host.get_placeholder_value, "optional")
self.assert_util(proxy.port.get_placeholder_value, "optional")
self.assert_util(proxy.username.get_placeholder_value, "optional")
self.assert_util(proxy.password.get_placeholder_value, "optional")

# Default values
self.assert_util(proxy.proxy_enable.is_checked(), False)
self.assert_util(proxy.type.get_value(), "http")
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_global_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,26 @@ def test_config_validation_when_valid(filename, is_yaml):
global_config_path = helpers.get_testdata_file_path(filename)
global_config = global_config_lib.GlobalConfig()
global_config.parse(global_config_path, is_yaml)

validator = GlobalConfigValidator(_path_to_source_dir(), global_config)

with does_not_raise():
validator.validate()


def test_config_validation_when_deprecated_placeholder_is_used():
global_config_path = helpers.get_testdata_file_path(
"valid_config_deprecated_placeholder_usage.json"
)
global_config = global_config_lib.GlobalConfig()
global_config.parse(global_config_path, False)

validator = GlobalConfigValidator(_path_to_source_dir(), global_config)

with pytest.warns(DeprecationWarning):
validator._warn_on_placeholder_usage()


@pytest.mark.parametrize(
"filename,is_yaml,exception_message",
[
Expand Down Expand Up @@ -257,8 +272,10 @@ def test_config_validation_when_error(filename, is_yaml, exception_message):
global_config_path = helpers.get_testdata_file_path(filename)
global_config = global_config_lib.GlobalConfig()
global_config.parse(global_config_path, is_yaml)

validator = GlobalConfigValidator(_path_to_source_dir(), global_config)
with pytest.raises(GlobalConfigValidatorException) as exc_info:
validator.validate()

(msg,) = exc_info.value.args
assert msg == exception_message
3 changes: 0 additions & 3 deletions tests/unit/testdata/valid_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
"pattern": "^[a-zA-Z]\\w*$"
}
],
"options": {
"placeholder": "Required"
},
"field": "name",
"help": "Enter a unique name for this account.",
"required": true
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/testdata/valid_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ pages:
errorMsg: Name must begin with a letter and consist exclusively of alphanumeric
characters and underscores.
pattern: "^[a-zA-Z]\\w*$"
options:
placeholder: Required
field: name
help: Enter a unique name for this account.
required: true
Expand Down
Loading

0 comments on commit 085e2b3

Please sign in to comment.