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

[Backport 2.8] Check for empty document in the finding flyout #850

Merged
merged 2 commits into from
Mar 13, 2024
Merged
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
24 changes: 21 additions & 3 deletions cypress/integration/4_findings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ describe('Findings', () => {
});
});

// TODO - upon reaching rules page, trigger appropriate rules detail flyout
// see github issue #124 at https://github.com/opensearch-project/security-analytics-dashboards-plugin/issues/124

it('opens rule details flyout when rule name inside accordion drop down is clicked', () => {
// filter table to show only sample_detector findings
cy.get(`input[placeholder="Search findings"]`).ospSearch(indexName);
Expand All @@ -166,5 +163,26 @@ describe('Findings', () => {
});
});

it('shows document not found warning when the document is empty', () => {
cy.deleteIndex(indexName);
cy.reload();

// Wait for page to load
cy.waitForPageLoad('findings', {
contains: 'Findings',
});

// filter table to show only sample_detector findings
cy.get(`input[placeholder="Search findings"]`).ospSearch(indexName);

// open Finding details flyout via finding id link. cy.wait essential, timeout insufficient.
cy.getTableFirstRow('[data-test-subj="view-details-icon"]').then(($el) => {
cy.get($el).click({ force: true });
});

// Flyout should show 'Document not found' warning
cy.contains('Document not found');
});

after(() => cy.cleanUpTests());
});
25 changes: 23 additions & 2 deletions public/pages/Findings/components/FindingDetailsFlyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
EuiInMemoryTable,
EuiBasicTableColumn,
EuiLoadingContent,
EuiEmptyPrompt,
} from '@elastic/eui';
import { capitalizeFirstLetter, renderTime } from '../../../utils/helpers';
import { DEFAULT_EMPTY_DATA, ROUTES } from '../../../utils/constants';
Expand Down Expand Up @@ -306,9 +307,16 @@ export default class FindingDetailsFlyout extends Component<
const docId = related_doc_ids[0];
const matchedDocuments = documents.filter((doc) => doc.id === docId);
const document = matchedDocuments.length > 0 ? matchedDocuments[0].document : '';
let formattedDocument = '';
try {
formattedDocument = document ? JSON.stringify(JSON.parse(document), null, 2) : '';
} catch {
// no-op
}

const { indexPatternId } = this.state;

return (
return document ? (
<>
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem>
Expand Down Expand Up @@ -367,10 +375,23 @@ export default class FindingDetailsFlyout extends Component<
isCopyable
data-test-subj={'finding-details-flyout-rule-document'}
>
{JSON.stringify(JSON.parse(document), null, 2)}
{formattedDocument}
</EuiCodeBlock>
</EuiFormRow>
</>
) : (
<>
<EuiTitle size={'s'}>
<h3>Documents</h3>
</EuiTitle>
<EuiSpacer />
<EuiEmptyPrompt
iconType="alert"
iconColor="danger"
title={<h2>Document not found</h2>}
body={<p>The document that generated this finding could not be loaded.</p>}
/>
</>
);
}

Expand Down
Loading