Skip to content

Commit

Permalink
Revert "[Data Explorer][Discover 2.0] Fix issues when change index pa…
Browse files Browse the repository at this point in the history
…ttern (opensearch-project#4875) (opensearch-project#4885)"

This reverts commit 0102a32.
try revert:
  • Loading branch information
MadaniKK committed Nov 18, 2023
1 parent f6ce6e7 commit 9f7d04a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,18 @@ export function getIndexPatternFieldList(
fieldCounts?: Record<string, number>
) {
if (!indexPattern || !fieldCounts) return [];
return [...indexPattern.fields.getAll()];

const fieldNamesInDocs = Object.keys(fieldCounts);
const fieldNamesInIndexPattern = indexPattern.fields.getAll().map((fld) => fld.name);
const unknownTypes: IndexPatternField[] = [];

difference(fieldNamesInDocs, fieldNamesInIndexPattern).forEach((unknownFieldName) => {
unknownTypes.push({
displayName: String(unknownFieldName),
name: String(unknownFieldName),
type: 'unknown',
} as IndexPatternField);
});

return [...indexPattern.fields.getAll(), ...unknownTypes];
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ import './discover_canvas.scss';
// eslint-disable-next-line import/no-default-export
export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewProps) {
const { data$, refetch$, indexPattern } = useDiscoverContext();
const {
services: { uiSettings },
} = useOpenSearchDashboards<DiscoverViewServices>();
const { columns } = useSelector((state) => state.discover);
const filteredColumns = filterColumns(
columns,
indexPattern,
uiSettings.get(DEFAULT_COLUMNS_SETTING)
);
const dispatch = useDispatch();
const prevIndexPattern = useRef(indexPattern);

const [fetchState, setFetchState] = useState<SearchData>({
status: data$.getValue().status,
Expand Down Expand Up @@ -80,13 +69,6 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro
};
}, [data$, fetchState]);

useEffect(() => {
if (indexPattern !== prevIndexPattern.current) {
dispatch(setColumns({ columns: filteredColumns }));
prevIndexPattern.current = indexPattern;
}
}, [dispatch, filteredColumns, indexPattern]);

const timeField = indexPattern?.timeFieldName ? indexPattern.timeFieldName : undefined;

return (
Expand Down

0 comments on commit 9f7d04a

Please sign in to comment.