From d6f84850e44cb78658c41784c976e1f000be8bbb Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Tue, 23 Jul 2024 21:19:33 +0000 Subject: [PATCH] null pointer Signed-off-by: Kawika Avilla --- src/plugins/data/public/antlr/shared/utils.ts | 2 +- .../dataset_navigator/dataset_navigator.tsx | 30 ++++++++++--------- .../components/query_assist_bar.tsx | 2 +- .../query_assist/utils/create_extension.tsx | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/plugins/data/public/antlr/shared/utils.ts b/src/plugins/data/public/antlr/shared/utils.ts index 48533048d70b..94236aa81387 100644 --- a/src/plugins/data/public/antlr/shared/utils.ts +++ b/src/plugins/data/public/antlr/shared/utils.ts @@ -25,7 +25,7 @@ export const getRawSuggestionData$ = ( if (connection === undefined) { return from(defaultReuqstHandler()); } - const dataSourceId = connection?.dataSource.id; + const dataSourceId = connection?.dataSource?.id; const title = connection?.attributes?.title; return from(dataSourceReuqstHandler({ dataSourceId, title })); }) diff --git a/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx b/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx index f104a9dea9f9..fefe37b36a00 100644 --- a/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx +++ b/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx @@ -67,6 +67,7 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { const [isLoading, setIsLoading] = useState(false); const [isMounted, setIsMounted] = useState(false); const [isExternalDataSourcesEnabled, setIsExternalDataSourcesEnabled] = useState(false); + const [selectedTimeFieldName, setSelectedTimeFieldName] = useState(); const [selectedObject, setSelectedObject] = useState(); const [selectedDataSource, setSelectedDataSource] = useState(); const [selectedDataSourceObjects, setSelectedDataSourceObjects] = useState([]); @@ -293,20 +294,21 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { }); const timeFields = fields.filter((field: any) => field.type === 'date'); - + const timeFieldName = timeFields?.length > 0 ? timeFields[0].name : undefined; + setSelectedTimeFieldName(timeFieldName); setSelectedObject({ id: object.id, title: object.title, fields, timeFields, - ...(timeFields[0]?.name ? { timeFieldName: timeFields[0].name } : {}), + timeFieldName: selectedTimeFieldName, dataSourceRef: object.dataSourceRef, type: SIMPLE_DATA_SET_TYPES.TEMPORARY, }); setIsLoading(false); } }, - [indexPatternsService] + [indexPatternsService, selectedTimeFieldName] ); const handleSelectedDataSet = useCallback( @@ -336,13 +338,13 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { const fieldsMap = dataSet.fields?.reduce((acc: any, field: any) => { acc[field.name] = field; return acc; - }); + }, {}); const temporaryIndexPattern = await indexPatternsService.create( { id: dataSet.id, title: dataSet.title, + // type: dataSet.type, fields: fieldsMap, - type: dataSet.type, dataSourceRef: { id: dataSet.dataSourceRef?.id!, name: dataSet.dataSourceRef?.name!, @@ -365,6 +367,7 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { id: dataSet.id, title: dataSet.title, dataSourceRef: dataSet.dataSourceRef, + timeFieldName: dataSet.timeFieldName, type: dataSet.type, }); queryService.queryString.setQuery(getInitialQuery(dataSet)); @@ -606,14 +609,10 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { : []), { value: 'no-time-filter', text: "I don't want to use a time filter" }, ]} - onChange={async (event) => { - await handleSelectedObject({ - ...selectedObject, - timeFieldName: - event.target.value !== 'no-time-filter' - ? event.target.value - : undefined, - } as SimpleDataSet); + onChange={(event) => { + setSelectedTimeFieldName( + event.target.value !== 'no-time-filter' ? event.target.value : undefined + ); }} aria-label="Select a date field" /> @@ -622,7 +621,10 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { size="s" fullWidth onClick={async () => { - await handleSelectedDataSet(selectedObject); + await handleSelectedDataSet({ + ...selectedObject, + timeFieldName: selectedTimeFieldName, + } as SimpleDataSet); }} > Select diff --git a/src/plugins/query_enhancements/public/query_assist/components/query_assist_bar.tsx b/src/plugins/query_enhancements/public/query_assist/components/query_assist_bar.tsx index 92393ef1a6c0..c28c5cb8b0be 100644 --- a/src/plugins/query_enhancements/public/query_assist/components/query_assist_bar.tsx +++ b/src/plugins/query_enhancements/public/query_assist/components/query_assist_bar.tsx @@ -45,7 +45,7 @@ export const QueryAssistBar: React.FC = (props) => { const subscription = props.connectionsService .getSelectedConnection$() .subscribe((connection) => { - dataSourceIdRef.current = connection?.dataSource.id; + dataSourceIdRef.current = connection?.dataSource?.id; }); return () => subscription.unsubscribe(); }, [props.connectionsService]); diff --git a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx index c76cd13bbf5e..23611e39501e 100644 --- a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx +++ b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx @@ -28,7 +28,7 @@ const getAvailableLanguages$ = ( connectionsService.getSelectedConnection$().pipe( distinctUntilChanged(), switchMap(async (connection) => { - const dataSourceId = connection?.dataSource.id; + const dataSourceId = connection?.dataSource?.id; const cached = availableLanguagesByDataSource.get(dataSourceId); if (cached !== undefined) return cached; const languages = await http