Skip to content

Commit

Permalink
Update actions menu after start/stop detector action for the selected…
Browse files Browse the repository at this point in the history
… detector (#895)

* updated selected items state after action

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

* added cypress test for detector toggle action

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

* simplified code

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

---------

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan authored Mar 14, 2024
1 parent 533cbcc commit 8e2ae0a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
34 changes: 34 additions & 0 deletions cypress/integration/1_detectors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,40 @@ describe('Detectors', () => {
validateFieldMappingsTable('rules are changed');
});

it('...can be stopped and started back from detectors list action menu', () => {
cy.wait(1000);
cy.get('tbody > tr')
.first()
.within(() => {
cy.get('[class="euiCheckbox__input"]').click({ force: true });
});

// Waiting for Actions menu button to be enabled
cy.wait(1000);

setupIntercept(cy, '/_plugins/_security_analytics/detectors/_search', 'detectorsSearch');

cy.get('[data-test-subj="detectorsActionsButton').click({ force: true });
cy.get('[data-test-subj="toggleDetectorButton').contains('Stop');
cy.get('[data-test-subj="toggleDetectorButton').click({ force: true });

cy.wait('@detectorsSearch').should('have.property', 'state', 'Complete');
// Need this extra wait time for the Actions button to become enabled again
cy.wait(1000);

setupIntercept(cy, '/_plugins/_security_analytics/detectors/_search', 'detectorsSearch');
cy.get('[data-test-subj="detectorsActionsButton').click({ force: true });
cy.get('[data-test-subj="toggleDetectorButton').contains('Start');
cy.get('[data-test-subj="toggleDetectorButton').click({ force: true });

cy.wait('@detectorsSearch').should('have.property', 'state', 'Complete');
// Need this extra wait time for the Actions button to become enabled again
cy.wait(1000);

cy.get('[data-test-subj="detectorsActionsButton').click({ force: true });
cy.get('[data-test-subj="toggleDetectorButton').contains('Stop');
});

it('...can be deleted', () => {
setupIntercept(cy, '/rules/_search', 'getRules');

Expand Down
8 changes: 6 additions & 2 deletions public/pages/Detectors/containers/Detectors/Detectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ export default class Detectors extends Component<DetectorsProps, DetectorsState>
} catch (e: any) {
errorNotificationToast(notifications, 'update', 'detector', e);
}
this.getDetectors();
this.setState({ loadingDetectors: false });
await this.getDetectors();
const selectedItemIds = new Set(this.state.selectedItems.map(({ _id }) => _id));
const updatedSelectedItems: DetectorHit[] = this.state.detectorHits.filter((hit) =>
selectedItemIds.has(hit._id)
);
this.setState({ loadingDetectors: false, selectedItems: updatedSelectedItems });
};

onClickDelete = async () => {
Expand Down

0 comments on commit 8e2ae0a

Please sign in to comment.