Skip to content

Commit

Permalink
fix: custom row loading on many tabs (#1336)
Browse files Browse the repository at this point in the history
  • Loading branch information
soleksy-splunk authored Sep 25, 2024
1 parent 7ce9ecf commit f124b5e
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docs/custom_ui_extensions/custom_row.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
When a row is expanded on the Inputs table, Custom Row is utilized to incorporate a customized element. By clicking on the icon provided on the left side of each row, the input-specific details are displayed.
When a row is expanded on the Inputs table or Configuration Table, Custom Row is utilized to incorporate a customized element. By clicking on the icon provided on the left side of each row, the input-specific details are displayed.

### Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#
import json
from typing import Dict, List, Set, Any
from typing import Dict, List, Any

from splunk_add_on_ucc_framework import global_config as global_config_lib

Expand Down Expand Up @@ -54,9 +54,9 @@ def _is_true(val: Any) -> bool:
class GlobalConfigBuilderSchema:
def __init__(self, global_config: global_config_lib.GlobalConfig):
self.global_config = global_config
self._settings_conf_file_names: Set[str] = set()
self._configs_conf_file_names: Set[str] = set()
self._oauth_conf_file_names: Set[str] = set()
self._settings_conf_file_names: List[str] = list()
self._configs_conf_file_names: List[str] = list()
self._oauth_conf_file_names: List[str] = list()
self._endpoints: Dict[str, RestEndpointBuilder] = {}
self._parse_builder_schema()

Expand All @@ -69,15 +69,15 @@ def namespace(self) -> str:
return self.global_config.namespace

@property
def settings_conf_file_names(self) -> Set[str]:
def settings_conf_file_names(self) -> List[str]:
return self._settings_conf_file_names

@property
def configs_conf_file_names(self) -> Set[str]:
def configs_conf_file_names(self) -> List[str]:
return self._configs_conf_file_names

@property
def oauth_conf_file_names(self) -> Set[str]:
def oauth_conf_file_names(self) -> List[str]:
return self._oauth_conf_file_names

@property
Expand Down Expand Up @@ -124,8 +124,11 @@ def _builder_configs(self) -> None:
log_level_field=log_details.get("entity", [{}])[0].get("field"),
)
self._endpoints["oauth"] = oauth_endpoint
self._oauth_conf_file_names.add(oauth_endpoint.conf_name)
self._configs_conf_file_names.add(endpoint.conf_name)
if oauth_endpoint.conf_name not in self._oauth_conf_file_names:
self._oauth_conf_file_names.append(oauth_endpoint.conf_name)

if endpoint.conf_name not in self._configs_conf_file_names:
self._configs_conf_file_names.append(endpoint.conf_name)

def _builder_settings(self) -> None:
if not self.global_config.settings:
Expand All @@ -146,7 +149,8 @@ def _builder_settings(self) -> None:
fields,
)
endpoint.add_entity(entity)
self._settings_conf_file_names.add(endpoint.conf_name)
if endpoint.conf_name not in self._settings_conf_file_names:
self._settings_conf_file_names.append(endpoint.conf_name)

def _builder_inputs(self) -> None:
for input_item in self.global_config.inputs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ redirect_url =
refresh_token =
token =
url =
username =
username =
text_test =
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

import import_declare_test

from splunktaucclib.rest_handler.endpoint import (
field,
validator,
RestModel,
SingleModel,
)
from splunktaucclib.rest_handler import admin_external, util
from splunktaucclib.rest_handler.admin_external import AdminExternalHandler
import logging

util.remove_http_proxy_env_vars()


fields = [
field.RestField(
'example_help_link',
required=False,
encrypted=False,
default=None,
validator=None
),
field.RestField(
'config1_help_link',
required=False,
encrypted=False,
default=None,
validator=None
),
field.RestField(
'config2_help_link',
required=False,
encrypted=False,
default=None,
validator=None
),
field.RestField(
'text_test',
required=True,
encrypted=False,
default=None,
validator=validator.String(
max_len=100,
min_len=1,
)
)
]
model = RestModel(fields, name=None)


endpoint = SingleModel(
'splunk_ta_uccexample_custom_row_tab',
model,
config_name='custom_row_tab'
)


if __name__ == '__main__':
logging.getLogger().addHandler(logging.NullHandler())
admin_external.handle(
endpoint,
handler=AdminExternalHandler,
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ name = Splunk_TA_UCCExample
version = 5.5.8R5fd76615

[triggers]
reload.splunk_ta_uccexample_settings = simple
reload.splunk_ta_uccexample_custom_row_tab = simple
reload.splunk_ta_uccexample_account = simple
reload.splunk_ta_uccexample_oauth = simple
reload.splunk_ta_uccexample_settings = simple
reload.splunk_ta_uccexample_oauth = simple
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[admin:splunk_ta_uccexample]
match = /
members = splunk_ta_uccexample_account, splunk_ta_uccexample_example_input_four, splunk_ta_uccexample_example_input_one, splunk_ta_uccexample_example_input_three, splunk_ta_uccexample_example_input_two, splunk_ta_uccexample_oauth, splunk_ta_uccexample_settings
members = splunk_ta_uccexample_account, splunk_ta_uccexample_custom_row_tab, splunk_ta_uccexample_example_input_four, splunk_ta_uccexample_example_input_one, splunk_ta_uccexample_example_input_three, splunk_ta_uccexample_example_input_two, splunk_ta_uccexample_oauth, splunk_ta_uccexample_settings

[admin_external:splunk_ta_uccexample_account]
handlertype = python
Expand All @@ -16,6 +16,13 @@ handlerfile = splunk_ta_uccexample_rh_oauth.py
handleractions = edit
handlerpersistentmode = true

[admin_external:splunk_ta_uccexample_custom_row_tab]
handlertype = python
python.version = python3
handlerfile = splunk_ta_uccexample_rh_custom_row_tab.py
handleractions = edit, list, remove, create
handlerpersistentmode = true

[admin_external:splunk_ta_uccexample_settings]
handlertype = python
python.version = python3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[shclustering]
conf_replication_include.splunk_ta_uccexample_settings = true
conf_replication_include.splunk_ta_uccexample_account = true
conf_replication_include.splunk_ta_uccexample_custom_row_tab = true
conf_replication_include.splunk_ta_uccexample_oauth = true
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ methods = POST, GET
pattern = splunk_ta_uccexample_oauth/*
methods = POST, GET, DELETE

[expose:splunk_ta_uccexample_custom_row_tab]
pattern = splunk_ta_uccexample_custom_row_tab
methods = POST, GET

[expose:splunk_ta_uccexample_custom_row_tab_specified]
pattern = splunk_ta_uccexample_custom_row_tab/*
methods = POST, GET, DELETE

[expose:splunk_ta_uccexample_settings]
pattern = splunk_ta_uccexample_settings
methods = POST, GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,77 @@
]
}
]
},
{
"name": "custom_row_tab",
"table": {
"actions": [
"edit",
"delete",
"clone"
],
"header": [
{
"label": "Name",
"field": "name"
},
{
"label": "Text Test",
"field": "text_test"
}
],
"moreInfo": [
{
"field": "name",
"label": "Name"
},
{
"field": "text_test",
"label": "Text Test"
}
],
"customRow": {
"src": "custom_input_row_replace",
"type": "external"
}
},
"entity": [
{
"type": "text",
"label": "Name",
"validators": [
{
"type": "string",
"errorMsg": "Length of ID should be between 1 and 50",
"minLength": 1,
"maxLength": 50
},
{
"type": "regex",
"errorMsg": "Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.",
"pattern": "^[a-zA-Z]\\w*$"
}
],
"field": "name",
"help": "Enter a unique name for this account.",
"required": true
},
{
"field": "text_test",
"label": "Text Test",
"help": "This is a text test",
"type": "text",
"validators": [
{
"type": "string",
"minLength": 1,
"maxLength": 100
}
],
"required": true
}
],
"title": "Custom table row"
}
],
"title": "Configuration",
Expand Down Expand Up @@ -1551,10 +1622,10 @@
"meta": {
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.48.2Ra94cdc9a8",
"version": "5.49.0Rcc63ee532",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.8",
"_uccVersion": "5.48.2",
"_uccVersion": "5.49.0",
"supportedThemes": [
"light",
"dark"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class CustomInputRow {
/**
* Custom Row Cell
* @constructor
* @param {Object} globalConfig - Global configuration.
* @param {string} serviceName - Input service name.
* @param {element} el - The element of the custom cell.
* @param {Object} row - custom row object,
* use this.row.<field_name>, where <field_name> is a field name
*/
constructor(globalConfig, serviceName, el, row) {
this.globalConfig = globalConfig;
this.serviceName = serviceName;
this.el = el;
this.row = row;
}

render() {
const content_html_template = "Custom Input Row";
this.el.innerHTML = content_html_template;
return this;
}
}

export default CustomInputRow;
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ def test_global_config_builder_schema(global_config_all_json):
# TODO: add more tests to check the endpoints.
assert global_config_builder_schema.product == "Splunk_TA_UCCExample"
assert global_config_builder_schema.namespace == "splunk_ta_uccexample"
assert global_config_builder_schema.settings_conf_file_names == {
assert global_config_builder_schema.settings_conf_file_names == [
"splunk_ta_uccexample_settings"
}
assert global_config_builder_schema.configs_conf_file_names == {
]
assert global_config_builder_schema.configs_conf_file_names == [
"splunk_ta_uccexample_account"
}
assert global_config_builder_schema.oauth_conf_file_names == {
]
assert global_config_builder_schema.oauth_conf_file_names == [
"splunk_ta_uccexample_oauth"
}
]


def test_global_config_builder_schema_custom_rh_config(global_config_all_json):
Expand Down
7 changes: 6 additions & 1 deletion ui/src/components/table/CustomTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ const CustomTable: React.FC<CustomTableProps> = ({
handleToggleActionClick={handleToggleActionClick}
{...(moreInfo
? {
expansionRow: getExpansionRow(columns.length, row, moreInfo),
expansionRow: getExpansionRow(
columns.length,
row,
moreInfo,
tableConfig?.customRow
),
}
: {})}
/>
Expand Down
9 changes: 1 addition & 8 deletions ui/src/components/table/TableExpansionRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@ import Table from '@splunk/react-ui/Table';
import styled from 'styled-components';

import CustomTableControl from './CustomTableControl';
import { getUnifiedConfigs } from '../../util/util';
import { getExpansionRowData } from './TableExpansionRowData';

const TableCellWrapper = styled(Table.Cell)`
border-top: none;
`;

export function getExpansionRow(colSpan, row, moreInfo) {
const inputs = getUnifiedConfigs().pages?.inputs;

const customRow = inputs?.table
? inputs.table.customRow
: inputs.services.find((service) => service.name === row.serviceName).table?.customRow;

export function getExpansionRow(colSpan, row, moreInfo, customRow) {
return (
<Table.Row key={`${row.id}-expansion`} style={{ wordBreak: 'break-word' }}>
<TableCellWrapper colSpan={colSpan}>
Expand Down

0 comments on commit f124b5e

Please sign in to comment.