Skip to content

Commit 5e131a3

Browse files
committed
block run button when nothing is selected
1 parent efa9f92 commit 5e131a3

2 files changed

Lines changed: 97 additions & 2 deletions

File tree

src/platform/plugins/shared/workflows_management/public/features/run_workflow/ui/workflow_execute_modal.test.tsx

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ describe('WorkflowExecuteModal', () => {
721721
});
722722

723723
it('disables execute button when there are errors', () => {
724-
const { getByTestId } = renderWithProviders(
724+
const { getByTestId, getByText } = renderWithProviders(
725725
<WorkflowExecuteModal
726726
isTestRun={false}
727727
definition={null}
@@ -730,10 +730,86 @@ describe('WorkflowExecuteModal', () => {
730730
/>
731731
);
732732

733+
fireEvent.click(getByText('Manual').closest('button')!);
734+
733735
const executeButton = getByTestId('executeWorkflowButton');
734736
expect(executeButton).not.toBeDisabled();
735737
});
736738

739+
it('disables execute button on the alert tab when no rows are selected', () => {
740+
const { getByTestId } = renderWithProviders(
741+
<WorkflowExecuteModal
742+
isTestRun={false}
743+
definition={null}
744+
onClose={mockOnClose}
745+
onSubmit={mockOnSubmit}
746+
/>
747+
);
748+
749+
expect(getByTestId('executeWorkflowButton')).toBeDisabled();
750+
});
751+
752+
it('enables execute button on the alert tab when rows are selected', () => {
753+
const { getByTestId } = renderWithProviders(
754+
<WorkflowExecuteModal
755+
isTestRun={false}
756+
definition={null}
757+
onClose={mockOnClose}
758+
onSubmit={mockOnSubmit}
759+
/>
760+
);
761+
762+
const alertFormCalls = mockWorkflowExecuteAlertForm.mock.calls;
763+
const lastAlertFormProps = alertFormCalls[alertFormCalls.length - 1]?.[0] as
764+
| { setValue?: (value: string) => void }
765+
| undefined;
766+
767+
act(() => {
768+
lastAlertFormProps!.setValue!('{"event":{"alertIds":[]}}');
769+
});
770+
771+
expect(getByTestId('executeWorkflowButton')).not.toBeDisabled();
772+
});
773+
774+
it('disables execute button on the document tab when no rows are selected', () => {
775+
const { getByTestId, getByText } = renderWithProviders(
776+
<WorkflowExecuteModal
777+
isTestRun={false}
778+
definition={null}
779+
onClose={mockOnClose}
780+
onSubmit={mockOnSubmit}
781+
/>
782+
);
783+
784+
fireEvent.click(getByText('Document').closest('button')!);
785+
786+
expect(getByTestId('executeWorkflowButton')).toBeDisabled();
787+
});
788+
789+
it('enables execute button on the document tab when rows are selected', () => {
790+
const { getByTestId, getByText } = renderWithProviders(
791+
<WorkflowExecuteModal
792+
isTestRun={false}
793+
definition={null}
794+
onClose={mockOnClose}
795+
onSubmit={mockOnSubmit}
796+
/>
797+
);
798+
799+
fireEvent.click(getByText('Document').closest('button')!);
800+
801+
const indexFormCalls = mockWorkflowExecuteIndexForm.mock.calls;
802+
const lastIndexFormProps = indexFormCalls[indexFormCalls.length - 1]?.[0] as
803+
| { setValue?: (value: string) => void }
804+
| undefined;
805+
806+
act(() => {
807+
lastIndexFormProps!.setValue!('{"event":{"documents":[]}}');
808+
});
809+
810+
expect(getByTestId('executeWorkflowButton')).not.toBeDisabled();
811+
});
812+
737813
it('disables execute button when the event trigger reports multiple table row selections', () => {
738814
const { getByTestId, getByText } = renderWithProviders(
739815
<WorkflowExecuteModal

src/platform/plugins/shared/workflows_management/public/features/run_workflow/ui/workflow_execute_modal.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ export const WorkflowExecuteModal = React.memo<WorkflowExecuteModalProps>(
163163
);
164164
return;
165165
}
166+
if (selectedTrigger === 'alert' && trimmed === '') {
167+
setExecutionInputErrors(
168+
i18n.translate('workflows.workflowExecuteModal.alertSelectionRequired', {
169+
defaultMessage: 'Select one or more alerts to use as the run input.',
170+
})
171+
);
172+
return;
173+
}
174+
if (selectedTrigger === 'index' && trimmed === '') {
175+
setExecutionInputErrors(
176+
i18n.translate('workflows.workflowExecuteModal.documentSelectionRequired', {
177+
defaultMessage: 'Select one or more documents to use as the run input.',
178+
})
179+
);
180+
return;
181+
}
166182
if (selectedTrigger === 'event' && eventTriggerTableSelectionCount > 1) {
167183
setExecutionInputErrors(
168184
i18n.translate('workflows.workflowExecuteModal.eventMultipleRowsSelected', {
@@ -326,10 +342,13 @@ export const WorkflowExecuteModal = React.memo<WorkflowExecuteModalProps>(
326342
selectedTrigger === 'manual' ||
327343
selectedTrigger === 'historical';
328344

345+
const isHitTableTriggerTab =
346+
selectedTrigger === 'alert' || selectedTrigger === 'index' || selectedTrigger === 'event';
347+
329348
const runIsDisabled =
330349
!canExecuteWorkflow ||
331350
Boolean(executionInputErrors) ||
332-
(selectedTrigger === 'event' && executionInput.trim() === '') ||
351+
(isHitTableTriggerTab && executionInput.trim() === '') ||
333352
(selectedTrigger === 'event' && eventTriggerTableSelectionCount > 1);
334353

335354
const renderRunWorkflowButton = () => (

0 commit comments

Comments
 (0)