Skip to content

Commit

Permalink
null pointer
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Jul 23, 2024
1 parent 3cdda3c commit d6f8485
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/plugins/data/public/antlr/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
})
Expand Down
30 changes: 16 additions & 14 deletions src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | undefined>();
const [selectedObject, setSelectedObject] = useState<SimpleDataSet | undefined>();
const [selectedDataSource, setSelectedDataSource] = useState<SimpleDataSource | undefined>();
const [selectedDataSourceObjects, setSelectedDataSourceObjects] = useState<SimpleObject[]>([]);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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!,
Expand All @@ -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));
Expand Down Expand Up @@ -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"
/>
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const QueryAssistBar: React.FC<QueryAssistInputProps> = (props) => {
const subscription = props.connectionsService
.getSelectedConnection$()
.subscribe((connection) => {
dataSourceIdRef.current = connection?.dataSource.id;
dataSourceIdRef.current = connection?.dataSource?.id;
});
return () => subscription.unsubscribe();
}, [props.connectionsService]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d6f8485

Please sign in to comment.