Skip to content

Commit

Permalink
added link to rules; simplified rule parsing (opensearch-project#571)
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
amsiglan authored May 4, 2023
1 parent e90b633 commit 9e683e2
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 119 deletions.
31 changes: 30 additions & 1 deletion public/pages/Correlations/Correlations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,33 @@

.correlation_rule_field_condition .euiButtonGroup__buttons {
box-shadow: none;
}
}

#sa-correlations-network .vis-tooltip {
background-color: #535353;
padding: 0px;
}

.readonly-text-color-light-mode {
&.euiFieldText {
color: #535353;
-webkit-text-fill-color: #535353;
}

.euiComboBoxPill.euiComboBoxPill--plainText {
color: #535353;
-webkit-text-fill-color: #535353;
}
}

.readonly-text-color-dark-mode {
&.euiFieldText {
color: #DFE5EF;
-webkit-text-fill-color: #DFE5EF;
}

.euiComboBoxPill.euiComboBoxPill--plainText {
color: #DFE5EF;
-webkit-text-fill-color: #DFE5EF;
}
}
44 changes: 11 additions & 33 deletions public/pages/Correlations/containers/CorrelationRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,23 @@ import {
getCorrelationRulesTableColumns,
getCorrelationRulesTableSearchConfig,
} from '../utils/helpers';
import {
CorrelationRule,
CorrelationRuleHit,
CorrelationRuleSourceQueries,
CorrelationRuleTableItem,
} from '../../../../types';
import { CorrelationRule } from '../../../../types';
import { RouteComponentProps } from 'react-router-dom';
import { CorrelationsExperimentalBanner } from '../components/ExperimentalBanner';
import { DeleteCorrelationRuleModal } from '../components/DeleteModal';

export const CorrelationRules: React.FC<RouteComponentProps> = (props: RouteComponentProps) => {
const context = useContext(CoreServicesContext);
const [allRules, setAllRules] = useState<CorrelationRuleTableItem[]>([]);
const [filteredRules, setFilteredRules] = useState<CorrelationRuleTableItem[]>([]);
const [allRules, setAllRules] = useState<CorrelationRule[]>([]);
const [filteredRules, setFilteredRules] = useState<CorrelationRule[]>([]);
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const [selectedRule, setSelectedRule] = useState<CorrelationRule | undefined>(undefined);

const getCorrelationRules = useCallback(
async (ruleItem?) => {
const allCorrelationRules: CorrelationRuleHit[] = await DataStore.correlations.getCorrelationRules();
const allRuleItems: CorrelationRuleTableItem[] = allCorrelationRules.map(
(rule: CorrelationRuleHit) => ({
...rule,
...rule._source,
id: rule._id,
name: rule._source?.name || '-',
queries: rule._source?.correlate?.map((correlate: CorrelationRuleSourceQueries) => ({
...correlate,
logType: correlate.category,
})),
logTypes: rule._source?.correlate?.map((correlate) => correlate.category).join(', '),
})
);

setAllRules(allRuleItems);
setFilteredRules(allRuleItems);
},
[DataStore.correlations.getCorrelationRules]
);
const getCorrelationRules = useCallback(async () => {
const allRuleItems: CorrelationRule[] = await DataStore.correlations.getCorrelationRules();
setAllRules(allRuleItems);
setFilteredRules(allRuleItems);
}, [DataStore.correlations.getCorrelationRules]);

useEffect(() => {
context?.chrome.setBreadcrumbs([
Expand Down Expand Up @@ -103,15 +81,15 @@ export const CorrelationRules: React.FC<RouteComponentProps> = (props: RouteComp
const onRuleNameClick = useCallback((rule: CorrelationRule) => {
props.history.push({
pathname: ROUTES.CORRELATION_RULE_CREATE,
state: { rule },
state: { rule, isReadOnly: true },
});
}, []);

const closeDeleteModal = () => {
setIsDeleteModalVisible(false);
};

const onDeleteRuleConfirmed = async (rule: any) => {
const onDeleteRuleConfirmed = async () => {
if (selectedRule) {
const response = await DataStore.correlations.deleteCorrelationRule(selectedRule.id);

Expand Down Expand Up @@ -163,7 +141,7 @@ export const CorrelationRules: React.FC<RouteComponentProps> = (props: RouteComp
<EuiPanel>
{allRules.length ? (
<EuiInMemoryTable
columns={getCorrelationRulesTableColumns((rule) => {
columns={getCorrelationRulesTableColumns(onRuleNameClick, (rule) => {
setIsDeleteModalVisible(true);
setSelectedRule(rule);
})}
Expand Down
Loading

0 comments on commit 9e683e2

Please sign in to comment.