Skip to content

Commit

Permalink
ensure table still updates editing job
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Sep 1, 2020
1 parent e9187c9 commit daece4c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ export const DataFrameAnalyticsList: FC<Props> = ({
}
};

const filterList = () => {
if (searchQueryText !== '' && selectedIdFromUrlInitialized === true) {
// trigger table filtering with query for job id to trigger table filter
const query = EuiSearchBar.Query.parse(searchQueryText);
let clauses: any = [];
if (query && query.ast !== undefined && query.ast.clauses !== undefined) {
clauses = query.ast.clauses;
}
setQueryClauses(clauses);
} else {
setQueryClauses([]);
}
};

useEffect(() => {
if (selectedIdFromUrlInitialized === false && analytics.length > 0) {
const { jobId, groupIds } = getSelectedIdFromUrl(window.location.href);
Expand All @@ -151,19 +165,13 @@ export const DataFrameAnalyticsList: FC<Props> = ({

setSelectedIdFromUrlInitialized(true);
setSearchQueryText(queryText);
} else {
filterList();
}
}, [selectedIdFromUrlInitialized, analytics]);

useEffect(() => {
if (searchQueryText !== '' && selectedIdFromUrlInitialized === true) {
// trigger table filtering with query for job id to trigger table filter
const query = EuiSearchBar.Query.parse(searchQueryText);
let clauses: any = [];
if (query && query.ast !== undefined && query.ast.clauses !== undefined) {
clauses = query.ast.clauses;
}
setQueryClauses(clauses);
}
filterList();
}, [selectedIdFromUrlInitialized, searchQueryText]);

const getAnalyticsCallback = useCallback(() => getAnalytics(true), []);
Expand Down Expand Up @@ -267,7 +275,7 @@ export const DataFrameAnalyticsList: FC<Props> = ({
<AnalyticsSearchBar
filters={filters}
searchQueryText={searchQueryText}
setQueryClauses={setQueryClauses}
setSearchQueryText={setSearchQueryText}
/>
<EuiSpacer size="l" />
<EuiBasicTable<DataFrameAnalyticsListRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import { i18n } from '@kbn/i18n';
import { stringMatch } from '../../../../../util/string_utils';
import {
Clause,
TermClause,
FieldClause,
Value,
Expand Down Expand Up @@ -105,21 +104,17 @@ function getError(errorMessage: string | null) {
interface Props {
filters: EuiSearchBarProps['filters'];
searchQueryText: string;
setQueryClauses: Dispatch<SetStateAction<any[]>>;
setSearchQueryText: Dispatch<SetStateAction<string>>;
}

export const AnalyticsSearchBar: FC<Props> = ({ filters, searchQueryText, setQueryClauses }) => {
export const AnalyticsSearchBar: FC<Props> = ({ filters, searchQueryText, setSearchQueryText }) => {
const [errorMessage, setErrorMessage] = useState<null | string>(null);

const onChange: EuiSearchBarProps['onChange'] = ({ query, error }) => {
if (error) {
setErrorMessage(error.message);
} else {
let clauses: Clause[] = [];
if (query && query.ast !== undefined && query.ast.clauses !== undefined) {
clauses = query.ast.clauses;
}
setQueryClauses(clauses);
} else if (query !== null && query.text !== undefined) {
setSearchQueryText(query.text);
setErrorMessage(null);
}
};
Expand Down

0 comments on commit daece4c

Please sign in to comment.