Skip to content

Commit

Permalink
Improve UX when editing an alert
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Sep 7, 2020
1 parent 6b1b32b commit 11f824b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ describe('api', () => {
});

describe('fieldsByIssueType', () => {
test('it returns the issue types correctly', async () => {
test('it returns the fields correctly', async () => {
const res = await api.fieldsByIssueType({
externalService,
params: { id: '10006' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
actionParams.subActionParams || {};

const [issueTypesSelectOptions, setIssueTypesSelectOptions] = useState<EuiSelectOption[]>([]);
const [firstLoad, setFirstLoad] = useState(false);
const [prioritiesSelectOptions, setPrioritiesSelectOptions] = useState<EuiSelectOption[]>([]);
const { http, toastNotifications } = useAppDependencies();

useEffect(() => {
setFirstLoad(true);
}, []);

const { isLoading: isLoadingIssueTypes, issueTypes } = useGetIssueTypes({
http,
toastNotifications,
actionConnector,
});

const { isLoading: isLoadingFields, fields } = useGetFieldsByIssueType({
http,
toastNotifications,
Expand Down Expand Up @@ -90,15 +97,27 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara

// Reset parameters when changing connector
useEffect(() => {
if (!firstLoad) {
return;
}

setIssueTypesSelectOptions([]);
editAction('subActionParams', { savedObjectId }, index);
editAction('subActionParams', { title, comments, description: '', savedObjectId }, index);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [actionConnector]);

// Reset fields when changing connector or issue type
useEffect(() => {
if (!firstLoad) {
return;
}

setPrioritiesSelectOptions([]);
editAction('subActionParams', { issueType, savedObjectId }, index);
editAction(
'subActionParams',
{ title, issueType, comments, description: '', savedObjectId },
index
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [issueType, savedObjectId]);

Expand All @@ -121,15 +140,15 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara

// Set default issue type
useEffect(() => {
if (issueTypesSelectOptions.length > 0) {
if (!issueType && issueTypesSelectOptions.length > 0) {
editSubActionProperty('issueType', issueTypesSelectOptions[0].value as string);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [issueTypes, issueTypesSelectOptions]);

// Set default priority
useEffect(() => {
if (prioritiesSelectOptions.length > 0) {
if (!priority && prioritiesSelectOptions.length > 0) {
editSubActionProperty('priority', prioritiesSelectOptions[0].value as string);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down

0 comments on commit 11f824b

Please sign in to comment.