Skip to content

Commit

Permalink
Update ValueListsForm to manually abort import request
Browse files Browse the repository at this point in the history
These hooks no longer care about/expose an abort function. In this one
case where we need that functionality, we can do it ourselves relatively
simply.
  • Loading branch information
rylnd committed Jul 1, 2020
1 parent df70e5c commit 344b81c
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ export interface ValueListsFormProps {
}

export const ValueListsFormComponent: React.FC<ValueListsFormProps> = ({ onError, onSuccess }) => {
const ctrl = useRef(new AbortController());
const [files, setFiles] = useState<FileList | null>(null);
const [type, setType] = useState<Type>(defaultListType);
const filePickerRef = useRef<EuiFilePicker | null>(null);
const { http } = useKibana().services;
const { start: importList, abort: abortImport, ...importState } = useImportList();
const { start: importList, ...importState } = useImportList();

// EuiRadioGroup's onChange only infers 'string' from our options
const handleRadioChange = useCallback((t: string) => setType(t as Type), [setType]);
Expand All @@ -71,8 +72,8 @@ export const ValueListsFormComponent: React.FC<ValueListsFormProps> = ({ onError
}, [setType]);

const handleCancel = useCallback(() => {
abortImport();
}, [abortImport]);
ctrl.current.abort();
}, []);

const handleSuccess = useCallback(
(response: ListSchema) => {
Expand All @@ -90,10 +91,12 @@ export const ValueListsFormComponent: React.FC<ValueListsFormProps> = ({ onError

const handleImport = useCallback(() => {
if (!importState.loading && files && files.length) {
ctrl.current = new AbortController();
importList({
file: files[0],
listId: undefined,
http,
signal: ctrl.current.signal,
type,
});
}
Expand Down

0 comments on commit 344b81c

Please sign in to comment.