Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Oct 6, 2020
1 parent e8c8f4e commit b87113d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,9 @@ const JiraSettingFieldsComponent: React.FunctionComponent<SettingFieldsProps<Jir
toastNotifications: notifications.toasts,
});

const hasPriority = useMemo(
() => Object.prototype.hasOwnProperty.call(fieldsByIssueType, 'priority'),
[fieldsByIssueType]
);
const hasPriority = useMemo(() => fieldsByIssueType.priority != null, [fieldsByIssueType]);

const hasParent = useMemo(
() => Object.prototype.hasOwnProperty.call(fieldsByIssueType, 'parent'),
[fieldsByIssueType]
);
const hasParent = useMemo(() => fieldsByIssueType.parent != null, [fieldsByIssueType]);

const prioritiesSelectOptions = useMemo(() => {
const priorities = fieldsByIssueType.priority?.allowedValues ?? [];
Expand Down Expand Up @@ -164,10 +158,8 @@ const JiraSettingFieldsComponent: React.FunctionComponent<SettingFieldsProps<Jir
<EuiFormRow fullWidth label={i18n.PARENT_ISSUE}>
<SearchIssues
actionConnector={connector}
http={http}
onChange={(parentIssueKey) => onFieldChange('parent', parentIssueKey)}
selectedValue={parent}
toastNotifications={notifications.toasts}
/>
</EuiFormRow>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,36 @@
import React, { useMemo, useEffect, useCallback, useState, memo } from 'react';
import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';

import { HttpSetup, ToastsApi } from 'kibana/public';
import { useKibana } from '../../../../common/lib/kibana';
import { ActionConnector } from '../../../containers/types';
import { useGetIssues } from './use_get_issues';
import { useGetSingleIssue } from './use_get_single_issue';
import * as i18n from './translations';

interface Props {
selectedValue: string | null;
http: HttpSetup;
toastNotifications: Pick<
ToastsApi,
'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError'
>;
actionConnector?: ActionConnector;
onChange: (parentIssueKey: string) => void;
}

const SearchIssuesComponent: React.FC<Props> = ({
selectedValue,
http,
toastNotifications,
actionConnector,
onChange,
}) => {
const SearchIssuesComponent: React.FC<Props> = ({ selectedValue, actionConnector, onChange }) => {
const [query, setQuery] = useState<string | null>(null);
const [selectedOptions, setSelectedOptions] = useState<Array<EuiComboBoxOptionOption<string>>>(
[]
);
const [options, setOptions] = useState<Array<EuiComboBoxOptionOption<string>>>([]);
const { http, notifications } = useKibana().services;

const { isLoading: isLoadingIssues, issues } = useGetIssues({
http,
toastNotifications,
toastNotifications: notifications.toasts,
actionConnector,
query,
});

const { isLoading: isLoadingSingleIssue, issue: singleIssue } = useGetSingleIssue({
http,
toastNotifications,
toastNotifications: notifications.toasts,
actionConnector,
id: selectedValue,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ describe('usePostPushToService', () => {
title: pushedCase.title,
updatedAt: pushedCase.updatedAt,
updatedBy: serviceConnectorUser,
issueType: 'Task',
parent: null,
priority: 'Low',
};

const sampleCaseServices = {
'123': {
...basicPush,
Expand All @@ -87,6 +85,7 @@ describe('usePostPushToService', () => {
hasDataToPush: false,
},
};

it('init', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, UsePostPushToService>(() =>
Expand Down Expand Up @@ -224,7 +223,6 @@ describe('usePostPushToService', () => {
const result = formatServiceRequestData(pushedCase, connector as CaseConnector, caseServices);
expect(result).toEqual({
...sampleServiceRequestData,
...connector.fields,
externalId: 'other_external_id',
});
});
Expand All @@ -242,7 +240,6 @@ describe('usePostPushToService', () => {
const result = formatServiceRequestData(pushedCase, connector as CaseConnector, caseServices);
expect(result).toEqual({
...sampleServiceRequestData,
...connector.fields,
externalId: null,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export const formatServiceRequestData = (
description,
externalId: actualExternalService?.externalId ?? null,
title,
...(connector.fields ?? {}),
updatedAt,
updatedBy:
updatedBy != null
Expand Down

0 comments on commit b87113d

Please sign in to comment.