Skip to content

Commit

Permalink
Added filter bar
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbnr committed Aug 14, 2024
1 parent 81ab887 commit 500a4ac
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
32 changes: 27 additions & 5 deletions nerdlets/drop-rule-explorer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ function DropRuleExplorer() {
const [sortingType, setSortingType] = useState(0);
const [sortColumn, setSortColumn] = useState(0);
const [selectedItem, setSelectedItem] = useState(null);
const [filterTerm, setFilterTerm] = useState(null);

const [newNRQL, setNewNRQL] = useState("");
const [newDescription, setNewDescription] = useState("");
const [newType, setNewType] = useState("DROP_DATA" );
const [newSource, setNewSource] = useState("NerdGraph");

//reset state and clear form
const resetFormAndState = () => {
const resetFormAndState = (cb) => {
setSelectedItem(null);
setNewType("DROP_DATA");
setNewSource("NerdGraph");
Expand All @@ -46,7 +47,6 @@ function DropRuleExplorer() {
}
})


const _onClickTableHeaderCell = (column, evt, { nextSortingType }) => {
if (column === sortColumn) {
setSortingType(nextSortingType);
Expand Down Expand Up @@ -284,16 +284,38 @@ function DropRuleExplorer() {
}
}

if(data.actor.dropRules.nrqlDropRules.list.rules.length > 0) {
const drawFilterBar = () => {
return <div className="filterForm">
<Form>
<TextField labelInline info="A (case insensitive) regex search pattern on description and NRQL fields" style={{width:'100%'}} label="Filter" value={filterTerm} onChange={event => {resetFormAndState(); setFilterTerm(event.target.value); }} />
</Form>
</div>
};


const filterData = (rules) => {
if(filterTerm == null || filterTerm.length == 0 || filterTerm == "") {
return rules;
} else {
const regex = new RegExp(filterTerm,'i');
return rules.filter(rule => {return regex.test(rule.nrql) || regex.test(rule.description)});
}
};

const filteredRules=filterData(data.actor.dropRules.nrqlDropRules.list.rules);

if(filteredRules.length > 0) {
return <>
{drawFilterBar()}
<BlockText className="summaryLine">
<strong>{data.actor.dropRules.nrqlDropRules.list.rules.length}</strong>{` drop rules found for account "${data.actor.accountDetails.name}"`}. Select a rule to view details.
<strong>{filteredRules.length}</strong>{` drop rules found for account "${data.actor.accountDetails.name}"`}. Select a rule to view details.
</BlockText>
{tableRender(data.actor.dropRules.nrqlDropRules.list.rules,refetch,createForm)}
{tableRender(filteredRules,refetch,createForm)}

</>
} else {
return <>
{drawFilterBar()}
<div className="dropRulesContainer">There are no drop rules for account: "{data.actor.accountDetails.name}" ({selectedAccountId}).</div>
{createForm()}
</>
Expand Down
8 changes: 7 additions & 1 deletion nerdlets/drop-rule-explorer/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}

.summaryLine {
margin-top: 2em;
margin-top: 1em;
padding-left: 0.5em;
}

Expand Down Expand Up @@ -47,6 +47,12 @@
margin-bottom: 1em;
}


.filterForm {
width: 20%;
margin-top:2em;
padding-left:0.5em;
}
.docsLink {
margin-top:4em;
}
2 changes: 1 addition & 1 deletion nr1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaType": "NERDPACK",
"id": "xxx-xxx-xxx-xxx",
"id": "3530a816-ad8d-4882-bfdd-563c8452b6f1",
"displayName": "Drop Rule Explorer",
"description": "For exploring drop rules in account"
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "drop-rule-explorer",
"version": "0.1.2",
"version": "0.1.3",
"scripts": {
"start": "nr1 nerdpack:serve",
"test": "exit 0"
Expand Down

0 comments on commit 500a4ac

Please sign in to comment.