Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover 2.0] fixes add filter and dismissible callout #5029

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ export const DiscoverChartContainer = ({ hits, bucketInterval, chartData }: Sear
indexPattern,
]);

if (!hits || !chartData || !bucketInterval) return null;

return (
hits && (
<DiscoverChart
bucketInterval={bucketInterval}
chartData={chartData}
config={uiSettings}
data={data}
hits={hits}
resetQuery={() => {
window.location.href = `#/view/${savedSearch?.id}`;
window.location.reload();
}}
services={services}
showResetButton={!!savedSearch && !!savedSearch.id}
isTimeBased={isTimeBased}
/>
)
<DiscoverChart
bucketInterval={bucketInterval}
chartData={chartData}
config={uiSettings}
data={data}
hits={hits}
resetQuery={() => {
window.location.href = `#/view/${savedSearch?.id}`;
window.location.reload();
}}
services={services}
showResetButton={!!savedSearch && !!savedSearch.id}
isTimeBased={isTimeBased}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ export const DiscoverTable = ({ history }: Props) => {
refetch$.next();
};
const onAddFilter = useCallback(
(field: IndexPatternField, values: string, operation: '+' | '-') => {
(field: string | IndexPatternField, values: string, operation: '+' | '-') => {
if (!indexPattern) return;

const newFilters = opensearchFilters.generateFilters(
filterManager,
field,
values,
operation,
indexPattern.id
indexPattern.id ?? ''
);
return filterManager.addFilters(newFilters);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_re
import { filterColumns } from '../utils/filter_columns';
import { DEFAULT_COLUMNS_SETTING } from '../../../../common';

const KEY_SHOW_NOTICE = 'discover:deprecation-notice:show';

// eslint-disable-next-line import/no-default-export
export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewProps) {
const { data$, refetch$, indexPattern } = useDiscoverContext();
Expand All @@ -41,8 +43,13 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro
bucketInterval: {},
});

const [isCallOutVisible, setIsCallOutVisible] = useState(true);
const closeCallOut = () => setIsCallOutVisible(false);
const [isCallOutVisible, setIsCallOutVisible] = useState(
localStorage.getItem(KEY_SHOW_NOTICE) !== 'false'
);
const closeCallOut = () => {
localStorage.setItem(KEY_SHOW_NOTICE, 'false');
setIsCallOutVisible(false);
};

let callOut;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { ViewProps } from '../../../../../data_explorer/public';
import {
addColumn,
Expand All @@ -15,9 +15,18 @@ import {
import { DiscoverSidebar } from '../../components/sidebar';
import { useDiscoverContext } from '../context';
import { ResultStatus, SearchData } from '../utils/use_search';
import { IndexPatternField, opensearchFilters } from '../../../../../data/public';
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public';
import { DiscoverViewServices } from '../../../build_services';

// eslint-disable-next-line import/no-default-export
export default function DiscoverPanel(props: ViewProps) {
const { services } = useOpenSearchDashboards<DiscoverViewServices>();
const {
data: {
query: { filterManager },
},
} = services;
const { data$, indexPattern } = useDiscoverContext();
const [fetchState, setFetchState] = useState<SearchData>(data$.getValue());

Expand All @@ -36,6 +45,22 @@ export default function DiscoverPanel(props: ViewProps) {
};
}, [data$, fetchState]);

const onAddFilter = useCallback(
(field: string | IndexPatternField, values: string, operation: '+' | '-') => {
if (!indexPattern) return;

const newFilters = opensearchFilters.generateFilters(
filterManager,
field,
values,
operation,
indexPattern.id ?? ''
);
return filterManager.addFilters(newFilters);
},
[filterManager, indexPattern]
);

return (
<DiscoverSidebar
columns={columns || []}
Expand All @@ -61,7 +86,7 @@ export default function DiscoverPanel(props: ViewProps) {
);
}}
selectedIndexPattern={indexPattern}
onAddFilter={() => {}}
onAddFilter={onAddFilter}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { IndexPattern } from '../../../opensearch_dashboards_services';
*/
export function filterColumns(
columns: string[],
indexPattern: IndexPattern,
indexPattern: IndexPattern | undefined,
defaultColumns: string[]
) {
const fieldsName = indexPattern?.fields.getAll().map((fld) => fld.name) || [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
vis?: Vis;
}

const KEY_SHOW_NOTICE = 'discover:deprecation-notice:show';

export function DiscoverLegacy({
addColumn,
fetch,
Expand Down Expand Up @@ -132,7 +134,9 @@
vis,
}: DiscoverLegacyProps) {
const [isSidebarClosed, setIsSidebarClosed] = useState(false);
const [isCallOutVisible, setIsCallOutVisible] = useState(true);
const [isCallOutVisible, setIsCallOutVisible] = useState(

Check warning on line 137 in src/plugins/discover_legacy/public/application/components/discover_legacy.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover_legacy/public/application/components/discover_legacy.tsx#L137

Added line #L137 was not covered by tests
localStorage.getItem(KEY_SHOW_NOTICE) !== 'false'
);
const { TopNavMenu } = getServices().navigation.ui;
const { savedSearch, indexPatternList } = opts;
const bucketAggConfig = vis?.data?.aggs?.aggs[1];
Expand All @@ -142,7 +146,10 @@
: undefined;
const [fixedScrollEl, setFixedScrollEl] = useState<HTMLElement | undefined>();

const closeCallOut = () => setIsCallOutVisible(false);
const closeCallOut = () => {
localStorage.setItem(KEY_SHOW_NOTICE, 'false');
setIsCallOutVisible(false);

Check warning on line 151 in src/plugins/discover_legacy/public/application/components/discover_legacy.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover_legacy/public/application/components/discover_legacy.tsx#L149-L151

Added lines #L149 - L151 were not covered by tests
};

let callOut;

Expand Down
Loading