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

Added search-bar in minedRules #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,29 @@ img.tutorialSmallImage {

/* cluster view */

.search-bar-container {
position: relative;
margin-bottom: 20px;
}

.search-input {
width: 30%;
padding: 10px 20px 10px 40px;
font-size: 16px;
border: 2px solid #ccc;
border-radius: 5px;
transition: border-color 0.3s;
}

.search-icon {
position: absolute;
left: 10px;
top: 50%;
transform: translateY(-50%);
color: #ccc;
font-size: 20px;
}

.minedRulesComponent .guiBoundingBox {
padding-top: 5px !important;
}
Expand Down
151 changes: 89 additions & 62 deletions src/ui/MiningRules/minedRulesComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Button} from "react-bootstrap";
import {
FaAngleDown, FaAngleUp,
FaCaretDown,
FaCaretUp,
FaCaretUp, FaSearch,
} from "react-icons/fa";
import "rc-slider/assets/index.css";

Expand Down Expand Up @@ -57,6 +57,7 @@ class MinedRulesComponent extends Component {
view: this.views.default_view,
minedRules: [],
minedRulesGrouped: [], // [{key, value}]
searchTerm: "",
loadingTitle: "Mining Rules",
message: "",
cluster: [],
Expand Down Expand Up @@ -302,78 +303,104 @@ class MinedRulesComponent extends Component {

renderClusters() {
const countRules = this.state.minedRules.reduce((sum, group) => sum + group.rulePadStates.length, 0);
const handleSearchChange = (event) => {
this.setState({searchTerm: event.target.value});
};
if (this.state.minedRules.length > 0 && countRules === 0) {
return (
<div>
<h4><strong>No rule is found.</strong></h4>
</div>);
}
const filteredRules = this.state.minedRulesGrouped.filter((group) =>
group.key.toLowerCase().includes(this.state.searchTerm.toLowerCase()),
);

return this.state.minedRulesGrouped.map((identifierGroup, index) => {
const childrenKeys = Object.keys(identifierGroup.value.children);
if (childrenKeys.length === 0) {
return null;
}
const keyParts = identifierGroup.key.split("%");
const identifierType = keyParts[0];
const identifierValue = keyParts[1];
const parentElementId =
featureGroupInformation[identifierGroup.value.children[childrenKeys[0]].fileGroup].rootId[0];
const expandedClass = "expanded";

const thenParts = childrenKeys.map((key) => {
const fileGroup = identifierGroup.value.children[key].fileGroup;
const title = featureGroupInformation[fileGroup].mergeKeys[1]
.replace(/\b\w/g, (char) => char.toUpperCase());
const content = this.renderThenPart(key, identifierGroup);
return {title, content};
});
return (
<div>
{/* ADDED: Search bar */}
<div className="search-bar-container">
<FaSearch className="search-icon"/>
<input
className="search-input"
type="text"
placeholder="Search rules..."
value={this.state.searchTerm}
onChange={handleSearchChange}
/>
</div>

const isRuleExpanded = this.state.isExpanded && this.state.expandedIdentifierGroupIndex === index;
const hidden = !this.state.isExpanded || this.state.expandedIdentifierGroupIndex !== index;
const classNameHidden = hidden ? "hidden" : "";
{filteredRules.map((identifierGroup, index) => {
const childrenKeys = Object.keys(identifierGroup.value.children);
if (childrenKeys.length === 0) {
return null;
}
const keyParts = identifierGroup.key.split("%");
const identifierType = keyParts[0];
const identifierValue = keyParts[1];
const parentElementId =
featureGroupInformation[identifierGroup.value.children[childrenKeys[0]].fileGroup].rootId[0];
const expandedClass = "expanded";

const thenParts = childrenKeys.map((key) => {
const fileGroup = identifierGroup.value.children[key].fileGroup;
const title = featureGroupInformation[fileGroup].mergeKeys[1]
.replace(/\b\w/g, (char) => char.toUpperCase());
const content = this.renderThenPart(key, identifierGroup);
return {title, content};
});

return (
<div className={"generateRuleGui guiBoundingBox minedRuleBoundingBox"} key={index}>
<div className={"identifierContainer"}>
<div className={"identifierHeader"}>
{"Rules applied on "}
<strong>{identifierType}</strong>
{" "}
<span
className={"inputText activeElement frequency-color frequency-identifier"}>
{identifierValue}
</span>
</div>
{isRuleExpanded ?
<div className={"expandIcons"}
onClick={() => this.setState({isExpanded: false})}>
<FaAngleUp size={20}/></div> :
<div className={"expandIcons"}
onClick={() => this.setState({isExpanded: true, expandedIdentifierGroupIndex: index})}>
<FaAngleDown size={20}/>
const isRuleExpanded = this.state.isExpanded && this.state.expandedIdentifierGroupIndex === index;
const hidden = !this.state.isExpanded || this.state.expandedIdentifierGroupIndex !== index;
const classNameHidden = hidden ? "hidden" : "";

return (
<div className={"generateRuleGui guiBoundingBox minedRuleBoundingBox"} key={index}>
<div className={"identifierContainer"}>
<div className={"identifierHeader"}>
{"Rules applied on "}
<strong>{identifierType}</strong>
{" "}
<span
className={"inputText activeElement frequency-color frequency-identifier"}>
{identifierValue}
</span>
</div>
{isRuleExpanded ?
<div className={"expandIcons"}
onClick={() => this.setState({isExpanded: false})}>
<FaAngleUp size={20}/></div> :
<div className={"expandIcons"}
onClick={() => this.setState({
isExpanded: true,
expandedIdentifierGroupIndex: index,
})}>
<FaAngleDown size={20}/>
</div>
}
</div>
<div className={`clusterRuleContainer ${classNameHidden}`}>
<div className={"ifKeyword"}>
<strong>{`IF a ${identifierType} is named ${identifierValue}`}</strong></div>
<div className={`ifPart ${expandedClass}`}>
<MinedRulePad key={new Date()} rulePadState={identifierGroup.value.parent}
isCluster={true}
featureMetaData={this.props.featureMetaData}
fileGroup={identifierGroup.value.children[childrenKeys[0]].fileGroup}
elementId={parentElementId}
isColorCodingEnabled={this.state.isColorCodingEnabled}/>
</div>
<div className={"thenKeyword"}><strong>{`THEN the ${identifierType} may have:`}</strong>
</div>
<div className={"thenParts"}>
<Accordion items={thenParts}/>
</div>
</div>
}
</div>
<div className={`clusterRuleContainer ${classNameHidden}`}>
<div className={"ifKeyword"}>
<strong>{`IF a ${identifierType} is named ${identifierValue}`}</strong></div>
<div className={`ifPart ${expandedClass}`}>
<MinedRulePad key={new Date()} rulePadState={identifierGroup.value.parent}
isCluster={true}
featureMetaData={this.props.featureMetaData}
fileGroup={identifierGroup.value.children[childrenKeys[0]].fileGroup}
elementId={parentElementId}
isColorCodingEnabled={this.state.isColorCodingEnabled}/>
</div>
<div className={"thenKeyword"}><strong>{`THEN the ${identifierType} may have:`}</strong></div>
<div className={"thenParts"}>
<Accordion items={thenParts}/>
</div>
</div>
</div>
);
});
);
})}
</div>
);
}

renderThenPart(key, identifierGroup) {
Expand Down
Loading