Skip to content

Commit

Permalink
fixes add filter and dismissible callout
Browse files Browse the repository at this point in the history
Signed-off-by: Ashwin P Chandran <[email protected]>
  • Loading branch information
ashwin-pc committed Sep 14, 2023
1 parent a925581 commit 9eeca43
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 25 deletions.
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 @@ export interface DiscoverLegacyProps {
vis?: Vis;
}

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

export function DiscoverLegacy({
addColumn,
fetch,
Expand Down Expand Up @@ -132,7 +134,9 @@ export function DiscoverLegacy({
vis,
}: DiscoverLegacyProps) {
const [isSidebarClosed, setIsSidebarClosed] = useState(false);
const [isCallOutVisible, setIsCallOutVisible] = useState(true);
const [isCallOutVisible, setIsCallOutVisible] = useState(
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 @@ export function DiscoverLegacy({
: undefined;
const [fixedScrollEl, setFixedScrollEl] = useState<HTMLElement | undefined>();

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

let callOut;

Expand Down

0 comments on commit 9eeca43

Please sign in to comment.