Skip to content

Commit

Permalink
Merge branch 'main' into fix-cognito
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Romero <[email protected]>
  • Loading branch information
joshuarrrr authored Oct 3, 2023
2 parents e1f3a1a + 9601c6c commit ffb56f1
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 39 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Table Vis] Fix filter actions on data table vis cells ([#4837](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4837))
- Fix broken app when management is turned off ([#4891](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4891))
- Correct the generated path for downloading plugins by their names on Windows ([#4953](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4953))
- Fix `buildPointSeriesData` unit test fails due to local timezone ([#4992](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4992))
- [Data Explorer][Discover] Fix total hits issue for no time based data ([#5087](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5087))
- [Data Explorer][Discover] Add onQuerySubmit to top nav and allow force update to embeddable ([#5160](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5160))
- [Discover] Fix misc navigation issues ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168))
- [Discover] Fix mobile view ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168))
- Fix `visAugmenter` forming empty key-value pairs in its calls to the `SavedObject` API ([#5190](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5190))
- [BUG] Fix buildPointSeriesData unit test fails due to local timezone ([#4992](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4992))
- [BUG][Data Explorer][Discover] Fix total hits issue for no time based data ([#5087](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5087))
- [BUG][Data Explorer][Discover] Add onQuerySubmit to top nav and allow force update to embeddable ([#5160](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5160))
- [BUG][Discover] Fix misc navigation issues ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168))
- [BUG][Discover] Fix mobile view ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168))
- [BUG][Data Explorer][Discover] Automatically load solo added default index pattern ([#5171](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5171))

### 🚞 Infrastructure

Expand Down
8 changes: 7 additions & 1 deletion src/plugins/data_explorer/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ export function plugin() {
}
export { DataExplorerPluginSetup, DataExplorerPluginStart, DataExplorerServices } from './types';
export { ViewProps, ViewDefinition, DefaultViewState } from './services/view_service';
export { RootState, useTypedSelector, useTypedDispatch } from './utils/state_management';
export {
RootState,
Store,
useTypedSelector,
useTypedDispatch,
setIndexPattern,
} from './utils/state_management';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
*/

import { TypedUseSelectorHook } from 'react-redux';
import { RootState, useTypedDispatch, useTypedSelector } from '../../../../../data_explorer/public';
import {
RootState,
Store as StoreType,
setIndexPattern as updateIndexPattern,
useTypedDispatch,
useTypedSelector,
} from '../../../../../data_explorer/public';
import { DiscoverState } from './discover_slice';

export * from './discover_slice';
Expand All @@ -15,3 +21,4 @@ export interface DiscoverRootState extends RootState {

export const useSelector: TypedUseSelectorHook<DiscoverRootState> = useTypedSelector;
export const useDispatch = useTypedDispatch;
export { StoreType, updateIndexPattern };
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const DiscoverTable = ({ history }: Props) => {
query: { filterManager },
},
} = services;
const { data$, refetch$, indexPattern } = useDiscoverContext();
const { data$, refetch$, indexPattern, savedSearch } = useDiscoverContext();
const [fetchState, setFetchState] = useState<SearchData>({
status: data$.getValue().status,
rows: [],
Expand Down Expand Up @@ -71,7 +71,6 @@ export const DiscoverTable = ({ history }: Props) => {
);

const { rows } = fetchState || {};
const { savedSearch } = useSearch(services);

useEffect(() => {
const subscription = data$.subscribe((next) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,72 @@
import { useEffect, useState } from 'react';
import { i18n } from '@osd/i18n';
import { IndexPattern } from '../../../../../data/public';
import { useSelector } from '../../utils/state_management';
import { useSelector, updateIndexPattern, StoreType } from '../../utils/state_management';
import { DiscoverServices } from '../../../build_services';
import { getIndexPatternId } from '../../helpers/get_index_pattern_id';

export const useIndexPattern = (services: DiscoverServices) => {
const indexPatternId = useSelector((state) => state.metadata.indexPattern);
/**
* Custom hook to fetch and manage the index pattern based on the provided services.
*
* This hook does the following:
* 1. Check if there's an `indexPatternId` from the state.
* 2. If not, fetch a list of index patterns, determine the default, and update the store with it.
* 3. Once an `indexPatternId` is determined (either from the state or by fetching the default),
* it fetches the details of the index pattern.
* 4. If there's any error fetching the index pattern details, a warning notification is shown.
*
* @param services - The services needed to fetch the index patterns and show notifications.
* @param store - The redux store in data_explorer to dispatch actions.
* @returns - The fetched index pattern.
*/
export const useIndexPattern = (services: DiscoverServices, store: StoreType) => {
const indexPatternIdFromState = useSelector((state) => state.metadata.indexPattern);
const [indexPattern, setIndexPattern] = useState<IndexPattern | undefined>(undefined);
const { data, toastNotifications } = services;
const { data, toastNotifications, uiSettings: config } = services;

useEffect(() => {
let isMounted = true;
if (!indexPatternId) return;
const indexPatternMissingWarning = i18n.translate(
'discover.valueIsNotConfiguredIndexPatternIDWarningTitle',
{
defaultMessage: '{id} is not a configured index pattern ID',
values: {
id: `"${indexPatternId}"`,
},
}
);

data.indexPatterns
.get(indexPatternId)
.then((result) => {
if (isMounted) {
setIndexPattern(result);
}
})
.catch(() => {
if (isMounted) {
toastNotifications.addDanger({
title: indexPatternMissingWarning,
});
}
const fetchIndexPatternDetails = (id: string) => {
data.indexPatterns
.get(id)
.then((result) => {
if (isMounted) {
setIndexPattern(result);
}
})
.catch(() => {
if (isMounted) {
const indexPatternMissingWarning = i18n.translate(
'discover.valueIsNotConfiguredIndexPatternIDWarningTitle',
{
defaultMessage: '{id} is not a configured index pattern ID',
values: {
id: `"${id}"`,
},
}
);
toastNotifications.addDanger({
title: indexPatternMissingWarning,
});
}
});
};

if (!indexPatternIdFromState) {
data.indexPatterns.getCache().then((indexPatternList) => {
const newId = getIndexPatternId('', indexPatternList, config.get('defaultIndex'));
store!.dispatch(updateIndexPattern(newId));
fetchIndexPatternDetails(newId);
});
} else {
fetchIndexPatternDetails(indexPatternIdFromState);
}

return () => {
isMounted = false;
};
}, [indexPatternId, data.indexPatterns, toastNotifications]);
}, [indexPatternIdFromState, data.indexPatterns, toastNotifications, config, store]);

return indexPattern;
};
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const useSearch = (services: DiscoverViewServices) => {
const initalSearchComplete = useRef(false);
const [savedSearch, setSavedSearch] = useState<SavedSearch | undefined>(undefined);
const { savedSearch: savedSearchId, sort, interval } = useSelector((state) => state.discover);
const indexPattern = useIndexPattern(services);
const { data, filterManager, getSavedSearchById, core, toastNotifications } = services;
const { data, filterManager, getSavedSearchById, core, toastNotifications, store } = services;
const indexPattern = useIndexPattern(services, store);
const timefilter = data.query.timefilter.timefilter;
const fetchStateRef = useRef<{
abortController: AbortController | undefined;
Expand Down

0 comments on commit ffb56f1

Please sign in to comment.