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

[D&D] Fix index pattern state and loading #1949

Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -16,7 +16,7 @@ import { FieldSelectorField } from './field_selector_field';

import './field_selector.scss';
import { useTypedSelector } from '../../utils/state_management';
import { useIndexPattern } from '../../utils/use';
import { useIndexPatterns } from '../../utils/use';
import { getAvailableFields } from './utils';

interface IFieldCategories {
Expand All @@ -33,7 +33,7 @@ const META_FIELDS: string[] = [
];

export const FieldSelector = () => {
const indexPattern = useIndexPattern();
const indexPattern = useIndexPatterns().selected;
const fieldSearchValue = useTypedSelector((state) => state.visualization.searchField);
const [filteredFields, setFilteredFields] = useState<IndexPatternField[]>([]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { cloneDeep } from 'lodash';
import { useTypedDispatch, useTypedSelector } from '../../utils/state_management';
import { DefaultEditorAggParams } from '../../../../../vis_default_editor/public';
import { Title } from './title';
import { useIndexPattern, useVisualizationType } from '../../utils/use';
import { useIndexPatterns, useVisualizationType } from '../../utils/use';
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public';
import { WizardServices } from '../../../types';
import { IAggType } from '../../../../../data/public';
Expand All @@ -20,7 +20,7 @@ export function SecondaryPanel() {
const [touched, setTouched] = useState(false);
const dispatch = useTypedDispatch();
const vizType = useVisualizationType();
const indexPattern = useIndexPattern();
const indexPattern = useIndexPatterns().selected;
const {
services: {
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
reorderAgg,
updateAggConfigParams,
} from '../../../utils/state_management/visualization_slice';
import { useIndexPattern } from '../../../utils/use/use_index_pattern';
import { useIndexPatterns } from '../../../utils/use/use_index_pattern';
import { useOpenSearchDashboards } from '../../../../../../opensearch_dashboards_react/public';
import { WizardServices } from '../../../../types';

Expand All @@ -31,7 +31,7 @@ export const useDropbox = (props: UseDropboxProps): DropboxProps => {
const { id: dropboxId, label, schema } = props;
const [validAggTypes, setValidAggTypes] = useState<string[]>([]);
const dispatch = useTypedDispatch();
const indexPattern = useIndexPattern();
const indexPattern = useIndexPatterns().selected;
const {
services: {
data: {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/wizard/public/application/components/top_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getTopNavConfig } from '../utils/get_top_nav_config';
import { WizardServices } from '../../types';

import './top_nav.scss';
import { useIndexPattern, useSavedWizardVis } from '../utils/use';
import { useIndexPatterns, useSavedWizardVis } from '../utils/use';
import { useTypedSelector } from '../utils/state_management';

export const TopNav = () => {
Expand Down Expand Up @@ -48,7 +48,7 @@ export const TopNav = () => {
);
}, [hasUnappliedChanges, rootState, savedWizardVis, services, visualizationIdFromUrl]);

const indexPattern = useIndexPattern();
const indexPattern = useIndexPatterns().selected;

return (
<div className="wizTopNav">
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/wizard/public/application/utils/use/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
*/

export { useVisualizationType } from './use_visualization_type';
export { useIndexPattern, useIndexPatterns } from './use_index_pattern';
export { useIndexPatterns } from './use_index_pattern';
export { useSavedWizardVis } from './use_saved_wizard_vis';
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,6 @@ import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_re
import { WizardServices } from '../../../types';
import { useTypedSelector } from '../state_management';

export const useIndexPattern = (): IndexPattern | undefined => {
const { indexPattern: indexId = '' } = useTypedSelector((state) => state.visualization);
const [indexPattern, setIndexPattern] = useState<IndexPattern>();
const {
services: {
data: { indexPatterns },
},
} = useOpenSearchDashboards<WizardServices>();

useEffect(() => {
const handleIndexUpdate = async () => {
const currentIndex = await indexPatterns.get(indexId);
setIndexPattern(currentIndex);
};

handleIndexUpdate();
}, [indexId, indexPatterns]);

return indexPattern;
};

export const useIndexPatterns = () => {
const { indexPattern: indexId = '' } = useTypedSelector((state) => state.visualization);
const [indexPatterns, setIndexPatterns] = useState<IndexPattern[]>([]);
Expand Down