Skip to content

Commit

Permalink
Fix timeline search
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Oct 12, 2020
1 parent 92bb8e7 commit 720e0cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { CommentRequest } from '../../../../../case/common/api';
import { usePostComment } from '../../containers/use_post_comment';
import { Case } from '../../containers/types';
import { MarkdownEditorForm } from '../../../common/components/markdown_editor/eui_form';
import { InsertTimelinePopover } from '../../../timelines/components/timeline/insert_timeline_popover';
import { useInsertTimeline } from '../../../timelines/components/timeline/insert_timeline_popover/use_insert_timeline';
import { Form, useForm, UseField, useFormData } from '../../../shared_imports';

Expand Down Expand Up @@ -61,10 +60,7 @@ export const AddComment = React.memo(
setFieldValue,
]);

const { handleCursorChange, handleOnTimelineChange } = useInsertTimeline(
comment,
onCommentChange
);
const { handleCursorChange } = useInsertTimeline(comment, onCommentChange);

const addQuote = useCallback(
(quote) => {
Expand Down Expand Up @@ -116,13 +112,6 @@ export const AddComment = React.memo(
{i18n.ADD_COMMENT}
</EuiButton>
),
topRightContent: (
<InsertTimelinePopover
hideUntitled={true}
isDisabled={isLoading}
onTimelineChange={handleOnTimelineChange}
/>
),
}}
/>
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
} from '../../../shared_imports';
import { usePostCase } from '../../containers/use_post_case';
import { schema, FormProps } from './schema';
import { InsertTimelinePopover } from '../../../timelines/components/timeline/insert_timeline_popover';
import { useInsertTimeline } from '../../../timelines/components/timeline/insert_timeline_popover/use_insert_timeline';
import { MarkdownEditorForm } from '../../../common/components/markdown_editor/eui_form';
import { useGetTags } from '../../containers/use_get_tags';
Expand Down Expand Up @@ -136,10 +135,7 @@ export const Create = React.memo(() => {
setFieldValue,
]);

const { handleCursorChange, handleOnTimelineChange } = useInsertTimeline(
description,
onDescriptionChange
);
const { handleCursorChange } = useInsertTimeline(description, onDescriptionChange);

const handleTimelineClick = useTimelineClick();

Expand Down Expand Up @@ -221,20 +217,13 @@ export const Create = React.memo(() => {
isDisabled: isLoading,
onClickTimeline: handleTimelineClick,
onCursorPositionUpdate: handleCursorChange,
topRightContent: (
<InsertTimelinePopover
hideUntitled={true}
isDisabled={isLoading}
onTimelineChange={handleOnTimelineChange}
/>
),
}}
/>
</Container>
</>
),
}),
[isLoading, options, handleCursorChange, handleTimelineClick, handleOnTimelineChange]
[isLoading, options, handleCursorChange, handleTimelineClick]
);

const secondStep = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
EuiFilterGroup,
EuiFilterButton,
} from '@elastic/eui';
import { isEmpty } from 'lodash/fp';
import { isEmpty, debounce } from 'lodash/fp';
import React, { memo, useCallback, useMemo, useState, useEffect, useRef } from 'react';
import styled from 'styled-components';

Expand Down Expand Up @@ -120,9 +120,14 @@ const SelectableTimelineComponent: React.FC<SelectableTimelineProps> = ({
const selectableListOuterRef = useRef<HTMLDivElement | null>(null);
const selectableListInnerRef = useRef<HTMLDivElement | null>(null);

const onSearchTimeline = useCallback((val) => {
setSearchTimelineValue(val);
}, []);
const debouncedSetSearchTimelineValue = useMemo(() => debounce(500, setSearchTimelineValue), []);

const onSearchTimeline = useCallback(
(val) => {
debouncedSetSearchTimelineValue(val);
},
[debouncedSetSearchTimelineValue]
);

const handleOnToggleOnlyFavorites = useCallback(() => {
setOnlyFavorites(!onlyFavorites);
Expand Down Expand Up @@ -238,7 +243,7 @@ const SelectableTimelineComponent: React.FC<SelectableTimelineProps> = ({
isLoading: loading,
placeholder: useMemo(() => i18n.SEARCH_BOX_TIMELINE_PLACEHOLDER(timelineType), [timelineType]),
onSearch: onSearchTimeline,
incremental: false,
incremental: true,
inputRef: (node: HTMLInputElement | null) => {
setSearchRef(node);
},
Expand Down

0 comments on commit 720e0cf

Please sign in to comment.