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

feat: add CheckboxTree component #1495

Open
wants to merge 36 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e22c7bd
test(ui): added unit test case for enable count
rohanm-crest Nov 15, 2024
f47cbf1
Merge branch 'develop' of https://github.com/splunk/addonfactory-ucc-…
rohanm-crest Nov 20, 2024
d256182
Merge branch 'develop' of https://github.com/splunk/addonfactory-ucc-…
rohanm-crest Nov 21, 2024
9e22d4f
feat(checkboxTree): added the layout for new component for checkbox tree
rohanm-crest Nov 29, 2024
bd7fd13
feat(storybook): added storybook and sample in input service
rohanm-crest Dec 4, 2024
0ae19f7
Merge branch 'develop' of https://github.com/splunk/addonfactory-ucc-…
rohanm-crest Dec 4, 2024
f23a4c0
chore: remove unwanted files
rohanm-crest Dec 4, 2024
ca2a5eb
Merge branch 'develop' into feat/checkbox-tree-component
rohanm-crest Dec 4, 2024
0cb0bb7
test: added jest test case for checkboxtree
rohanm-crest Dec 4, 2024
0b6d995
Merge branch 'feat/checkbox-tree-component' of https://github.com/spl…
rohanm-crest Dec 4, 2024
a8c4f68
update screenshots
srv-rr-github-token Dec 4, 2024
4bba2e1
feat: added UTC and documentation for checkboxtree component
rohanm-crest Dec 9, 2024
a1d0212
Merge branch 'develop' of https://github.com/splunk/addonfactory-ucc-…
rohanm-crest Dec 9, 2024
4a2512c
Merge branch 'develop' into feat/checkbox-tree-component
rohanm-crest Dec 9, 2024
6bc85b8
update screenshots
srv-rr-github-token Dec 9, 2024
b274197
fix: added dependency for the variable in input.conf
rohanm-crest Dec 9, 2024
5d0501d
Merge branch 'feat/checkbox-tree-component' of https://github.com/spl…
rohanm-crest Dec 9, 2024
53a7753
refactor: update the logic for search to collapse/expand on input
rohanm-crest Dec 10, 2024
627510f
update screenshots
srv-rr-github-token Dec 10, 2024
1685dc7
revert(search): remove the search functionality from checkboxtree
rohanm-crest Dec 12, 2024
08ba881
refactor: change styling and storybook
rohanm-crest Dec 13, 2024
e4ccd69
update screenshots
srv-rr-github-token Dec 13, 2024
7f4e6f7
docs: change screenshot for checkboxtree
rohanm-crest Dec 13, 2024
ed56993
Merge branch 'feat/checkbox-tree-component' of https://github.com/spl…
rohanm-crest Dec 13, 2024
0dba61a
revert: delete search screenshot
rohanm-crest Dec 13, 2024
3df9abb
Merge branch 'develop' into feat/checkbox-tree-component
rohanm-crest Dec 13, 2024
b502f45
update screenshots
srv-rr-github-token Dec 13, 2024
4631fb4
feat: add support for disable and prisma
rohanm-crest Dec 18, 2024
aeed161
Merge branch 'feat/checkbox-tree-component' of https://github.com/spl…
rohanm-crest Dec 18, 2024
7611965
update screenshots
srv-rr-github-token Dec 18, 2024
7666043
Merge branch 'develop' into feat/checkbox-tree-component
rohanm-crest Dec 18, 2024
d8b278c
fix: resolve issue for disable in group checkbox
rohanm-crest Dec 18, 2024
ac152cf
update screenshots
srv-rr-github-token Dec 18, 2024
e9fe08e
revert(disable): remove the disable, disableonedit is already present
rohanm-crest Dec 26, 2024
bf69c7e
Merge branch 'feat/checkbox-tree-component' of https://github.com/spl…
rohanm-crest Dec 26, 2024
7fbbbea
update screenshots
srv-rr-github-token Dec 26, 2024
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
112 changes: 112 additions & 0 deletions splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,115 @@
],
"additionalProperties": false
},
"CheckboxTreeEntity": {
"type": "object",
"properties": {
"field": {
"$ref": "#/definitions/Field"
},
"label": {
"type": "string",
"maxLength": 30,
"description": "Text displayed next to entity field"
},
"type": {
"const": "CheckboxTree",
"type": "string",
"description": "Exactly: CheckboxTree"
},
"options": {
"type": "object",
"properties": {
"groups": {
"type": "array",
"items": {
"type": "object",
"properties": {
"label": {
"type": "string",
"maxLength": 30,
"description": "Text displayed next to entity field"
},
"options": {
"type": "object",
"properties": {
"isExpandable": {
"type": "boolean",
"default": false
},
"expand": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false
},
"fields": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
},
"uniqueItems": true
}
},
"required": ["label", "fields"],
"additionalProperties": false
}
},
"rows": {
"type": "array",
"items": {
"type": "object",
"properties": {
"field": {
"type": "string"
},
"checkbox": {
"type": "object",
"properties": {
"label": {
"type": "string",
"maxLength": 30,
"description": "Text displayed next to entity field"
},
"defaultValue": {
"type": "boolean",
"description": "The initial input value."
}
},
"additionalProperties": false
}
},
"required": ["field"],
"additionalProperties": false
},
"minItems": 1
},
"disableonEdit": {
"$ref": "#/definitions/disableonEdit"
}
},
"required": ["rows"],
"additionalProperties": false
},
"validators": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/definitions/RegexValidator"
}
]
}
},
"required": {
"type": "boolean"
}
},
"required": ["field", "label", "type", "options"],
"additionalProperties": false
},
"RadioEntity": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1864,6 +1973,9 @@
{
"$ref": "#/definitions/CheckboxGroupEntity"
},
{
"$ref": "#/definitions/CheckboxTreeEntity"
},
{
"$ref": "#/definitions/TextEntity"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
validator=None
)

field.RestField(
'apis',
required=False,
encrypted=False,
default=None,
validator=None
),

]
model = RestModel(fields, name=None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,81 @@
"label": "Interval",
"help": "Time interval of the data input, in seconds.",
"required": true
},
{
"type": "CheckboxTree",
"label": "Event Filters",
"field": "apis",
rohanm-crest marked this conversation as resolved.
Show resolved Hide resolved
"required": true,
"options": {
"groups": [
{
"label": "Transactions",
"options": {
"isExpandable": true,
"expand": true
},
"fields": [
"slow_request",
"transaction_stall"
]
},
{
"label": "others",
"options": {
"isExpandable": true,
"expand": true
},
"fields": [
"custom_events",
"cluster_events",
"network_events"
]
}
],
"rows": [
{
"field": "code_problems",
"checkbox": {
"label": "Code Problems",
"defaultValue": true
}
},
{
"field": "slow_request",
"checkbox": {
"label": "Slow Request",
"defaultValue": true
}
},
{
"field": "transaction_stall",
"checkbox": {
"label": "Transactions Stall",
"defaultValue": false
}
},
{
"field": "custom_events",
"checkbox": {
"label": "Custom Events",
"defaultValue": true
}
},
{
"field": "cluster_events",
"checkbox": {
"label": "Cluster Events"
}
},
{
"field": "network_events",
"checkbox": {
"label": "Network Events"
}
}
]
}
}
],
"title": "Example Input Three"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@
'disabled',
required=False,
validator=None
)
),

field.RestField(
'apis',
required=False,
encrypted=False,
default=None,
validator=None
),

]
model = RestModel(fields, name=None)
Expand Down
110 changes: 110 additions & 0 deletions ui/src/components/CheckboxTree/CheckboxSubTree.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import React, { useMemo, useState } from 'react';
import CheckboxRowWrapper from './CheckboxTreeRowWrapper';
import { getCheckedCheckboxesCount } from './CheckboxTree.utils';
import {
CheckboxContainer,
CheckboxWrapper,
Description,
GroupLabel,
RowContainer,
StyledCollapsiblePanel,
} from './StyledComponent';
import { GroupWithRows, ValueByField } from './types';

interface CheckboxSubTreeProps {
group: GroupWithRows;
values: ValueByField;
handleRowChange: (newValue: { field: string; checkbox: boolean; text?: string }) => void;
disabled?: boolean;
handleParentCheckboxTree: (groupLabel: string, newCheckboxValue: boolean) => void;
}

const CheckboxSubTree: React.FC<CheckboxSubTreeProps> = ({
group,
values,
handleRowChange,
disabled,
handleParentCheckboxTree,
}) => {
const [isExpanded, setIsExpanded] = useState(true);

const isParentChecked = useMemo(
() => group.rows.every((row) => values.get(row.field)?.checkbox),
[group.rows, values]
);

const isIndeterminate = useMemo(
() => group.rows.some((row) => values.get(row.field)?.checkbox) && !isParentChecked,
rohanm-crest marked this conversation as resolved.
Show resolved Hide resolved
[group.rows, values, isParentChecked]
);

const checkedCheckboxesCount = useMemo(
() => getCheckedCheckboxesCount(group, values),
[group, values]
);

const toggleCollapse = () => setIsExpanded((prev) => !prev);

const ParentCheckbox = (
<CheckboxWrapper>
<input
rohanm-crest marked this conversation as resolved.
Show resolved Hide resolved
type="checkbox"
checked={isParentChecked}
ref={(el) => {
const inputElement = el as HTMLInputElement | null;
if (inputElement) {
inputElement.indeterminate = isIndeterminate;
}
}}
onChange={() => handleParentCheckboxTree(group.label, !isParentChecked)}
disabled={disabled}
/>
<span>{group.label}</span>
</CheckboxWrapper>
);

const childRows = (
<RowContainer>
{group.rows.map((row) => (
<CheckboxRowWrapper
key={`row_${row.field}`}
disabled={disabled}
row={row}
values={values}
handleRowChange={handleRowChange}
/>
))}
</RowContainer>
);

const description = (
<Description>
{checkedCheckboxesCount} of {group.fields.length}
</Description>
);

return (
<CheckboxContainer>
{group.options?.isExpandable ? (
<StyledCollapsiblePanel
open={isExpanded}
onChange={toggleCollapse}
title={ParentCheckbox}
actions={description}
>
{childRows}
</StyledCollapsiblePanel>
) : (
<>
<GroupLabel>
{ParentCheckbox}
{description}
</GroupLabel>
{childRows}
</>
)}
</CheckboxContainer>
);
};

export default CheckboxSubTree;
Loading