Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: custom row loading on many tabs #1336

Merged
merged 16 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ 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._configs_conf_file_names: List[str] = list()
self._oauth_conf_file_names: Set[str] = set()
sgoral-splunk marked this conversation as resolved.
Show resolved Hide resolved
self._endpoints: Dict[str, RestEndpointBuilder] = {}
self._parse_builder_schema()
Expand All @@ -73,7 +73,7 @@ def settings_conf_file_names(self) -> Set[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
Expand Down Expand Up @@ -125,7 +125,9 @@ def _builder_configs(self) -> None:
)
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 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 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 @@ -17,9 +17,9 @@ def test_global_config_builder_schema(global_config_all_json):
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 == {
"splunk_ta_uccexample_oauth"
}
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
Loading