add sendToChat button to SourcesTab for mobile usage
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
ab5ead3416
commit
bf4916b447
1 changed files with 29 additions and 1 deletions
|
|
@ -15,7 +15,9 @@
|
|||
import React, { useCallback, useMemo, useState } from 'react';
|
||||
import type { UdbContext } from './UnifiedDataBar';
|
||||
import { FormGeneratorTree } from '../FormGenerator/FormGeneratorTree';
|
||||
import type { TreeNode } from '../FormGenerator/FormGeneratorTree';
|
||||
import { createUdbSourcesProvider } from './UdbSourcesProvider';
|
||||
import type { UdbBackendNode } from './UdbSourcesProvider';
|
||||
import { DataSourceSettingsModal } from './DataSourceSettingsModal';
|
||||
import { useLanguage } from '../../providers/language/LanguageContext';
|
||||
|
||||
|
|
@ -29,7 +31,11 @@ interface SourcesTabProps {
|
|||
onAttachDataSource?: (dsId: string) => void;
|
||||
}
|
||||
|
||||
const SourcesTab: React.FC<SourcesTabProps> = ({ context }) => {
|
||||
const SourcesTab: React.FC<SourcesTabProps> = ({
|
||||
context,
|
||||
onSendToChat_FeatureSource,
|
||||
onAttachDataSource,
|
||||
}) => {
|
||||
const { t } = useLanguage();
|
||||
const instanceId = context.instanceId;
|
||||
|
||||
|
|
@ -42,6 +48,27 @@ const SourcesTab: React.FC<SourcesTabProps> = ({ context }) => {
|
|||
setSettingsModal({ dataSourceId, title: label });
|
||||
}, []);
|
||||
|
||||
const _handleSendToChat = useCallback((node: TreeNode<UdbBackendNode>) => {
|
||||
const data = node.data;
|
||||
if (!data) return;
|
||||
|
||||
if (data.kind === 'featureNode' || data.kind === 'fdsTable' || data.kind === 'fdsRecord') {
|
||||
const tableName = data.tableName || (data.kind === 'featureNode' ? '*' : '');
|
||||
const objectKey = data.objectKey
|
||||
|| (data.kind === 'featureNode' ? `data.feature.${data.featureCode}.*` : '');
|
||||
onSendToChat_FeatureSource?.({
|
||||
featureInstanceId: data.featureInstanceId || '',
|
||||
featureCode: data.featureCode || '',
|
||||
tableName,
|
||||
objectKey,
|
||||
label: data.label,
|
||||
});
|
||||
} else if (data.kind === 'connection' || data.kind === 'service'
|
||||
|| data.kind === 'folder' || data.kind === 'file') {
|
||||
onAttachDataSource?.(data.connectionId || data.key);
|
||||
}
|
||||
}, [onSendToChat_FeatureSource, onAttachDataSource]);
|
||||
|
||||
const provider = useMemo(
|
||||
() => instanceId
|
||||
? createUdbSourcesProvider(instanceId, _handleOpenSettings)
|
||||
|
|
@ -68,6 +95,7 @@ const SourcesTab: React.FC<SourcesTabProps> = ({ context }) => {
|
|||
selectable={false}
|
||||
allowCreateFolder={false}
|
||||
emptyMessage={t('Keine Datenquellen.')}
|
||||
onSendToChat={_handleSendToChat}
|
||||
/>
|
||||
</div>
|
||||
<DataSourceSettingsModal
|
||||
|
|
|
|||
Loading…
Reference in a new issue