@antscorp/antsomi-ui 2.0.103 → 2.0.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/__mocks__/sql-query.json +56 -0
- package/es/assets/css/main.scss +2 -2
- package/es/components/atoms/App/App.d.ts +7 -0
- package/es/components/atoms/App/App.js +5 -0
- package/es/components/atoms/App/index.d.ts +1 -0
- package/es/components/atoms/App/index.js +1 -0
- package/es/components/atoms/Input/Input.d.ts +11 -17
- package/es/components/atoms/Input/Input.js +11 -12
- package/es/components/atoms/List/List.d.ts +1 -0
- package/es/components/atoms/List/List.js +1 -0
- package/es/components/atoms/List/index.d.ts +1 -0
- package/es/components/atoms/List/index.js +1 -0
- package/es/components/atoms/Scrollbars/Scrollbars.d.ts +3 -4
- package/es/components/atoms/Scrollbars/Scrollbars.js +2 -1
- package/es/components/atoms/SlideBar/SlideBar.js +1 -1
- package/es/components/atoms/Tag/Tag.js +1 -1
- package/es/components/atoms/index.d.ts +3 -0
- package/es/components/atoms/index.js +2 -0
- package/es/components/icons/FeedbackOutlinedIcon.d.ts +3 -0
- package/es/components/icons/FeedbackOutlinedIcon.js +7 -0
- package/es/components/icons/LazyIcon/LazyIcon.d.ts +5 -0
- package/es/components/icons/LazyIcon/LazyIcon.js +5 -0
- package/es/components/icons/NavigateBeforeIcon.d.ts +3 -0
- package/es/components/icons/NavigateBeforeIcon.js +7 -0
- package/es/components/icons/NavigateNextIcon.d.ts +3 -0
- package/es/components/icons/NavigateNextIcon.js +7 -0
- package/es/components/icons/PenSparkIcon.d.ts +3 -0
- package/es/components/icons/PenSparkIcon.js +7 -0
- package/es/components/icons/StatusSuccessIcon.d.ts +3 -0
- package/es/components/icons/StatusSuccessIcon.js +7 -0
- package/es/components/icons/SummarizeIconIcon.d.ts +3 -0
- package/es/components/icons/SummarizeIconIcon.js +7 -0
- package/es/components/icons/index.d.ts +5 -0
- package/es/components/icons/index.js +5 -0
- package/es/components/index.scss +1 -0
- package/es/components/molecules/AddDynamicContent/AddDynamicContent.d.ts +1 -2
- package/es/components/molecules/CalendarSelection/constants.d.ts +1 -1
- package/es/components/molecules/CalendarSelection/constants.js +1 -1
- package/es/components/molecules/CaptureScreen/CaptureScreen.d.ts +8 -2
- package/es/components/molecules/CaptureScreen/CaptureScreen.js +2 -2
- package/es/components/molecules/DrawerDetail/DrawerDetail.js +19 -7
- package/es/components/molecules/DrawerDetail/types.d.ts +5 -0
- package/es/components/molecules/EditingListV2/components/Loadable.d.ts +1 -1
- package/es/components/molecules/EditorScript/EditorScript.d.ts +1 -2
- package/es/components/molecules/EditorScript/EditorScript.js +5 -1
- package/es/components/molecules/FontSizeInput/index.scss +15 -0
- package/es/components/molecules/Select/styled.js +1 -1
- package/es/components/molecules/SelectAccount/type.d.ts +1 -1
- package/es/components/molecules/TagifyInput/utils.style.js +1 -0
- package/es/components/molecules/TemplateSaveAs/hooks/useTemplateSave.d.ts +1 -1
- package/es/components/organism/AccountProfile/components/AccountSetting/AccountSetting.js +2 -1
- package/es/components/organism/AccountProfile/components/AccountSetting/components/LanguageSelector/styles.d.ts +1 -1
- package/es/components/organism/AccountProfile/components/AccountSetting/components/LanguageSelector/styles.js +1 -1
- package/es/components/organism/ActivityTimeline/__mocks__/event_tracking.json +1290 -0
- package/es/components/organism/ActivityTimeline/__mocks__/timeline.json +3059 -0
- package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.js +5 -4
- package/es/components/organism/Login/components/LoginWithEmail/styled.js +1 -1
- package/es/components/organism/Login/components/SetupGGAuthenticator/styled.js +1 -1
- package/es/components/organism/Login/components/SignIn/styled.js +1 -1
- package/es/components/organism/Login/components/WidgetLayout/styled.js +1 -1
- package/es/components/organism/Login/styled.d.ts +3 -3
- package/es/components/organism/Login/styled.js +11 -11
- package/es/components/organism/ModifyColumnModal/styled.d.ts +2 -2
- package/es/components/organism/PreviewTemplateModal/components/ThumbnailSlider/styled.d.ts +1 -2
- package/es/components/organism/PreviewTemplateModal/components/ThumbnailSlider/styled.js +3 -1
- package/es/components/organism/SQLGeneration/SQLGeneration.d.ts +3 -0
- package/es/components/organism/SQLGeneration/SQLGeneration.js +26 -0
- package/es/components/organism/SQLGeneration/components/CheckboxShowDiff.d.ts +2 -0
- package/es/components/organism/SQLGeneration/components/CheckboxShowDiff.js +16 -0
- package/es/components/organism/SQLGeneration/components/EditTableSourcesDrawer.d.ts +2 -0
- package/es/components/organism/SQLGeneration/components/EditTableSourcesDrawer.js +56 -0
- package/es/components/organism/SQLGeneration/components/ErrorDisplay.d.ts +21 -0
- package/es/components/organism/SQLGeneration/components/ErrorDisplay.js +69 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationActions.d.ts +4 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationActions.js +23 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationCodeBlock.d.ts +2 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationCodeBlock.js +22 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationEditPrompt.d.ts +2 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationEditPrompt.js +66 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationHeader.d.ts +2 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationHeader.js +10 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationModal.d.ts +2 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationModal.js +35 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationPagination.d.ts +4 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationPagination.js +13 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationPrompt.d.ts +2 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationPrompt.js +31 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationPromptDisplay.d.ts +2 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationPromptDisplay.js +15 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationQuerySummary.d.ts +2 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationQuerySummary.js +17 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationRefine.d.ts +1 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationRefine.js +55 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationResult.d.ts +5 -0
- package/es/components/organism/SQLGeneration/components/SQLGenerationResult.js +29 -0
- package/es/components/organism/SQLGeneration/components/index.d.ts +9 -0
- package/es/components/organism/SQLGeneration/components/index.js +9 -0
- package/es/components/organism/SQLGeneration/components/styled.d.ts +52 -0
- package/es/components/organism/SQLGeneration/components/styled.js +382 -0
- package/es/components/organism/SQLGeneration/constants.d.ts +48 -0
- package/es/components/organism/SQLGeneration/constants.js +48 -0
- package/es/components/organism/SQLGeneration/hooks/index.d.ts +1 -0
- package/es/components/organism/SQLGeneration/hooks/index.js +1 -0
- package/es/components/organism/SQLGeneration/hooks/useKeyboardNavigation.d.ts +14 -0
- package/es/components/organism/SQLGeneration/hooks/useKeyboardNavigation.js +123 -0
- package/es/components/organism/SQLGeneration/index.d.ts +10 -0
- package/es/components/organism/SQLGeneration/index.js +6 -0
- package/es/components/organism/SQLGeneration/index.scss +1 -0
- package/es/components/organism/SQLGeneration/integrations/AceEditor/index.d.ts +1 -0
- package/es/components/organism/SQLGeneration/integrations/AceEditor/index.js +1 -0
- package/es/components/organism/SQLGeneration/integrations/AceEditor/index.scss +4 -0
- package/es/components/organism/SQLGeneration/integrations/AceEditor/useAceEditor.d.ts +9 -0
- package/es/components/organism/SQLGeneration/integrations/AceEditor/useAceEditor.js +24 -0
- package/es/components/organism/SQLGeneration/integrations/AceEditor/useEnhancePlaceholder.d.ts +10 -0
- package/es/components/organism/SQLGeneration/integrations/AceEditor/useEnhancePlaceholder.js +172 -0
- package/es/components/organism/SQLGeneration/integrations/AceEditor/useInsertQuery.d.ts +8 -0
- package/es/components/organism/SQLGeneration/integrations/AceEditor/useInsertQuery.js +21 -0
- package/es/components/organism/SQLGeneration/integrations/AntsomiAI/index.d.ts +1 -0
- package/es/components/organism/SQLGeneration/integrations/AntsomiAI/index.js +1 -0
- package/es/components/organism/SQLGeneration/integrations/AntsomiAI/useAntsomiAI.d.ts +1 -0
- package/es/components/organism/SQLGeneration/integrations/AntsomiAI/useAntsomiAI.js +35 -0
- package/es/components/organism/SQLGeneration/integrations/AntsomiSqlWS/index.d.ts +1 -0
- package/es/components/organism/SQLGeneration/integrations/AntsomiSqlWS/index.js +1 -0
- package/es/components/organism/SQLGeneration/integrations/AntsomiSqlWS/useAntsomiSqlWS.d.ts +7 -0
- package/es/components/organism/SQLGeneration/integrations/AntsomiSqlWS/useAntsomiSqlWS.js +10 -0
- package/es/components/organism/SQLGeneration/selectors.d.ts +857 -0
- package/es/components/organism/SQLGeneration/selectors.js +61 -0
- package/es/components/organism/SQLGeneration/store/index.d.ts +2 -0
- package/es/components/organism/SQLGeneration/store/index.js +1 -0
- package/es/components/organism/SQLGeneration/store/provider.d.ts +7 -0
- package/es/components/organism/SQLGeneration/store/provider.js +40 -0
- package/es/components/organism/SQLGeneration/store/store.d.ts +383 -0
- package/es/components/organism/SQLGeneration/store/store.js +309 -0
- package/es/components/organism/SQLGeneration/store/types.d.ts +97 -0
- package/es/components/organism/SQLGeneration/store/types.js +1 -0
- package/es/components/organism/SQLGeneration/types.d.ts +29 -0
- package/es/components/organism/SQLGeneration/types.js +1 -0
- package/es/components/organism/index.d.ts +1 -0
- package/es/components/organism/index.js +1 -0
- package/es/components/organism/index.scss +1 -0
- package/es/components/template/TemplateListing/hooks/useTemplateListing.d.ts +3 -4
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.js +1 -0
- package/es/hooks/useFocusManagement.d.ts +14 -0
- package/es/hooks/useFocusManagement.js +124 -0
- package/es/locales/ja/google-sheet.json +2 -2
- package/es/providers/ConfigProvider/ConfigProvider.js +4 -1
- package/es/providers/ConfigProvider/GlobalStyle.js +153 -46
- package/es/queries/AI/index.d.ts +23 -0
- package/es/queries/AI/index.js +4 -0
- package/es/queries/AI/useSqlGeneration.d.ts +25 -0
- package/es/queries/AI/useSqlGeneration.js +13 -0
- package/es/queries/TemplateListing/index.d.ts +2 -2
- package/es/queries/index.d.ts +1 -0
- package/es/queries/index.js +1 -0
- package/es/services/AI/index.d.ts +15 -0
- package/es/services/AI/index.js +15 -0
- package/es/types/auth.d.ts +25 -0
- package/es/types/auth.js +1 -0
- package/es/types/index.d.ts +1 -0
- package/es/types/index.js +1 -0
- package/es/utils/common.d.ts +1 -0
- package/es/utils/common.js +16 -1
- package/es/utils/web.d.ts +16 -3
- package/es/utils/web.js +36 -3
- package/es/utils/zustand.d.ts +10 -0
- package/es/utils/zustand.js +8 -0
- package/package.json +15 -10
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const SQL_GENERATION_CONSTANTS: {
|
|
2
|
+
readonly POPOVER_WIDTH: 600;
|
|
3
|
+
readonly POPOVER_MAX_WIDTH: 800;
|
|
4
|
+
readonly TEXTAREA_MIN_ROWS: 3;
|
|
5
|
+
readonly TEXTAREA_MAX_ROWS: 6;
|
|
6
|
+
readonly MODAL_WIDTH: 800;
|
|
7
|
+
readonly PLACEHOLDER_TEXTS: {
|
|
8
|
+
readonly PROMPT: "Enter a prompt to generate a query";
|
|
9
|
+
readonly SEARCH_TABLES: "Search for tables...";
|
|
10
|
+
readonly REFINE_PROMPT: "Refine";
|
|
11
|
+
readonly NO_RESULT: "No SQL generated yet";
|
|
12
|
+
};
|
|
13
|
+
readonly LOADING_TEXTS: {
|
|
14
|
+
readonly GENERATING: "Generating SQL...";
|
|
15
|
+
};
|
|
16
|
+
readonly RESULT_TEXTS: {
|
|
17
|
+
readonly PROCESSED_DATA: "This query will process {size} when run.";
|
|
18
|
+
};
|
|
19
|
+
readonly BUTTON_TEXTS: {
|
|
20
|
+
readonly GENERATE: "Generate";
|
|
21
|
+
readonly EDIT: "Edit";
|
|
22
|
+
readonly INSERT: "Insert";
|
|
23
|
+
readonly EDIT_TABLE_SOURCES: "Edit Table Sources";
|
|
24
|
+
readonly QUERY_SUMMARY: "Query Summary";
|
|
25
|
+
readonly APPLY: "Apply";
|
|
26
|
+
readonly CLOSE: "Close";
|
|
27
|
+
readonly CANCEL: "Cancel";
|
|
28
|
+
};
|
|
29
|
+
readonly TITLES: {
|
|
30
|
+
readonly MAIN: "Generate SQL with AI";
|
|
31
|
+
readonly EDIT_TABLE_SOURCES: "Edit table sources";
|
|
32
|
+
readonly TABLE_ASSET: "Table asset";
|
|
33
|
+
readonly RATING: {
|
|
34
|
+
readonly THUMBS_UP: "This is helpful";
|
|
35
|
+
readonly THUMBS_DOWN: "This is not helpful";
|
|
36
|
+
readonly MORE_FEEDBACK: "More feedback";
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
readonly MESSAGES: {
|
|
40
|
+
readonly LOADING: "Generating SQL...";
|
|
41
|
+
readonly NO_RESULT: "No SQL generated yet";
|
|
42
|
+
readonly PROCESSING_INFO: "This query will process {size} when run.";
|
|
43
|
+
readonly TABLE_SOURCES_INFO: "Metadata associated with the selected tables will be used to refine your suggestion.";
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export declare const DEFAULT_RESULT_SETTINGS: {
|
|
47
|
+
showDiff: boolean;
|
|
48
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const SQL_GENERATION_CONSTANTS = {
|
|
2
|
+
POPOVER_WIDTH: 600,
|
|
3
|
+
POPOVER_MAX_WIDTH: 800,
|
|
4
|
+
TEXTAREA_MIN_ROWS: 3,
|
|
5
|
+
TEXTAREA_MAX_ROWS: 6,
|
|
6
|
+
MODAL_WIDTH: 800,
|
|
7
|
+
PLACEHOLDER_TEXTS: {
|
|
8
|
+
PROMPT: 'Enter a prompt to generate a query',
|
|
9
|
+
SEARCH_TABLES: 'Search for tables...',
|
|
10
|
+
REFINE_PROMPT: 'Refine',
|
|
11
|
+
NO_RESULT: 'No SQL generated yet',
|
|
12
|
+
},
|
|
13
|
+
LOADING_TEXTS: {
|
|
14
|
+
GENERATING: 'Generating SQL...',
|
|
15
|
+
},
|
|
16
|
+
RESULT_TEXTS: {
|
|
17
|
+
PROCESSED_DATA: 'This query will process {size} when run.',
|
|
18
|
+
},
|
|
19
|
+
BUTTON_TEXTS: {
|
|
20
|
+
GENERATE: 'Generate',
|
|
21
|
+
EDIT: 'Edit',
|
|
22
|
+
INSERT: 'Insert',
|
|
23
|
+
EDIT_TABLE_SOURCES: 'Edit Table Sources',
|
|
24
|
+
QUERY_SUMMARY: 'Query Summary',
|
|
25
|
+
APPLY: 'Apply',
|
|
26
|
+
CLOSE: 'Close',
|
|
27
|
+
CANCEL: 'Cancel',
|
|
28
|
+
},
|
|
29
|
+
TITLES: {
|
|
30
|
+
MAIN: 'Generate SQL with AI',
|
|
31
|
+
EDIT_TABLE_SOURCES: 'Edit table sources',
|
|
32
|
+
TABLE_ASSET: 'Table asset',
|
|
33
|
+
RATING: {
|
|
34
|
+
THUMBS_UP: 'This is helpful',
|
|
35
|
+
THUMBS_DOWN: 'This is not helpful',
|
|
36
|
+
MORE_FEEDBACK: 'More feedback',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
MESSAGES: {
|
|
40
|
+
LOADING: 'Generating SQL...',
|
|
41
|
+
NO_RESULT: 'No SQL generated yet',
|
|
42
|
+
PROCESSING_INFO: 'This query will process {size} when run.',
|
|
43
|
+
TABLE_SOURCES_INFO: 'Metadata associated with the selected tables will be used to refine your suggestion.',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
export const DEFAULT_RESULT_SETTINGS = {
|
|
47
|
+
showDiff: false,
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useKeyboardNavigation, useSQLGenerationKeyboard } from './useKeyboardNavigation';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useKeyboardNavigation, useSQLGenerationKeyboard } from './useKeyboardNavigation';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface KeyboardNavigationOptions {
|
|
2
|
+
onEscape?: () => void;
|
|
3
|
+
onEnter?: () => void;
|
|
4
|
+
onCtrlEnter?: () => void;
|
|
5
|
+
onArrowUp?: () => void;
|
|
6
|
+
onArrowDown?: () => void;
|
|
7
|
+
onArrowLeft?: () => void;
|
|
8
|
+
onArrowRight?: () => void;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const useKeyboardNavigation: (options?: KeyboardNavigationOptions) => {
|
|
12
|
+
handleKeyDown: (event: KeyboardEvent) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const useSQLGenerationKeyboard: () => void;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { useEffect, useCallback } from 'react';
|
|
2
|
+
import { useSQLGenerationStore } from '../store/provider';
|
|
3
|
+
import { selectHasResult, selectIsEditingPrompt, selectIsRefining, selectIsLoading, } from '../selectors';
|
|
4
|
+
export const useKeyboardNavigation = (options = {}) => {
|
|
5
|
+
const { onEscape, onEnter, onCtrlEnter, onArrowUp, onArrowDown, onArrowLeft, onArrowRight, disabled = false, } = options;
|
|
6
|
+
const handleKeyDown = useCallback((event) => {
|
|
7
|
+
if (disabled)
|
|
8
|
+
return;
|
|
9
|
+
const { key, ctrlKey, metaKey, altKey, shiftKey } = event;
|
|
10
|
+
const isModifierPressed = ctrlKey || metaKey || altKey || shiftKey;
|
|
11
|
+
// Prevent handling if user is typing in an input/textarea
|
|
12
|
+
const target = event.target;
|
|
13
|
+
const isInputElement = ['INPUT', 'TEXTAREA'].includes(target.tagName) || target.contentEditable === 'true';
|
|
14
|
+
switch (key) {
|
|
15
|
+
case 'Escape':
|
|
16
|
+
if (onEscape) {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
onEscape();
|
|
19
|
+
}
|
|
20
|
+
break;
|
|
21
|
+
case 'Enter':
|
|
22
|
+
if ((ctrlKey || metaKey) && onCtrlEnter) {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
onCtrlEnter();
|
|
25
|
+
}
|
|
26
|
+
else if (!isModifierPressed && !isInputElement && onEnter) {
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
onEnter();
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
case 'ArrowUp':
|
|
32
|
+
if (!isInputElement && onArrowUp) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
onArrowUp();
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
case 'ArrowDown':
|
|
38
|
+
if (!isInputElement && onArrowDown) {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
onArrowDown();
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
case 'ArrowLeft':
|
|
44
|
+
if (!isInputElement && onArrowLeft) {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
onArrowLeft();
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
case 'ArrowRight':
|
|
50
|
+
if (!isInputElement && onArrowRight) {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
onArrowRight();
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}, [disabled, onEscape, onEnter, onCtrlEnter, onArrowUp, onArrowDown, onArrowLeft, onArrowRight]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (disabled)
|
|
61
|
+
return;
|
|
62
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
63
|
+
return () => {
|
|
64
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
65
|
+
};
|
|
66
|
+
}, [handleKeyDown, disabled]);
|
|
67
|
+
return { handleKeyDown };
|
|
68
|
+
};
|
|
69
|
+
// Hook for SQL Generation specific keyboard shortcuts
|
|
70
|
+
export const useSQLGenerationKeyboard = () => {
|
|
71
|
+
const hasResults = useSQLGenerationStore(selectHasResult);
|
|
72
|
+
const isEditingPrompt = useSQLGenerationStore(selectIsEditingPrompt);
|
|
73
|
+
const isRefining = useSQLGenerationStore(selectIsRefining);
|
|
74
|
+
const isLoading = useSQLGenerationStore(selectIsLoading);
|
|
75
|
+
const setIsOpen = useSQLGenerationStore(s => s.setIsOpen);
|
|
76
|
+
const setIsEditingPrompt = useSQLGenerationStore(s => s.setIsEditingPrompt);
|
|
77
|
+
const generateSQL = useSQLGenerationStore(s => s.generateSQL);
|
|
78
|
+
const refineSQL = useSQLGenerationStore(s => s.refineSQL);
|
|
79
|
+
const setCurrentResultKey = useSQLGenerationStore(s => s.setCurrentResultKey);
|
|
80
|
+
const resultAllKeys = useSQLGenerationStore(s => s.results.allKeys);
|
|
81
|
+
const currentResultKey = useSQLGenerationStore(s => s.currentResultKey);
|
|
82
|
+
const handleEscape = useCallback(() => {
|
|
83
|
+
if (isEditingPrompt) {
|
|
84
|
+
setIsEditingPrompt(false);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
setIsOpen(false);
|
|
88
|
+
}
|
|
89
|
+
}, [isEditingPrompt, setIsEditingPrompt, setIsOpen]);
|
|
90
|
+
const handleCtrlEnter = useCallback(() => {
|
|
91
|
+
if (isLoading)
|
|
92
|
+
return;
|
|
93
|
+
if (isRefining) {
|
|
94
|
+
refineSQL();
|
|
95
|
+
}
|
|
96
|
+
else if (!hasResults) {
|
|
97
|
+
generateSQL();
|
|
98
|
+
}
|
|
99
|
+
}, [isLoading, isRefining, hasResults, refineSQL, generateSQL]);
|
|
100
|
+
const handleArrowLeft = useCallback(() => {
|
|
101
|
+
if (hasResults && resultAllKeys.length > 1) {
|
|
102
|
+
const currentIndex = resultAllKeys.indexOf(currentResultKey || '');
|
|
103
|
+
if (currentIndex > 0) {
|
|
104
|
+
setCurrentResultKey(resultAllKeys[currentIndex - 1]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, [hasResults, resultAllKeys, currentResultKey, setCurrentResultKey]);
|
|
108
|
+
const handleArrowRight = useCallback(() => {
|
|
109
|
+
if (hasResults && resultAllKeys.length > 1) {
|
|
110
|
+
const currentIndex = resultAllKeys.indexOf(currentResultKey || '');
|
|
111
|
+
if (currentIndex < resultAllKeys.length - 1) {
|
|
112
|
+
setCurrentResultKey(resultAllKeys[currentIndex + 1]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}, [hasResults, resultAllKeys, currentResultKey, setCurrentResultKey]);
|
|
116
|
+
useKeyboardNavigation({
|
|
117
|
+
onEscape: handleEscape,
|
|
118
|
+
onCtrlEnter: handleCtrlEnter,
|
|
119
|
+
onArrowLeft: handleArrowLeft,
|
|
120
|
+
onArrowRight: handleArrowRight,
|
|
121
|
+
disabled: false,
|
|
122
|
+
});
|
|
123
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { SQLGeneration } from './SQLGeneration';
|
|
2
|
+
export type { SQLGenerationProps, SQLGenerationResult, TableSource } from './types';
|
|
3
|
+
export { SQLGenerationProvider, useSQLGenerationStore, type SQLGenerationProviderProps, } from './store';
|
|
4
|
+
export declare const SQLGenerationIntegrations: {
|
|
5
|
+
readonly useAntsomiSqlWS: (params?: {
|
|
6
|
+
triggerTitle: string;
|
|
7
|
+
} | undefined) => {
|
|
8
|
+
setAceEditor: (editor: import("react-ace/lib/types").IAceEditor) => void;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@use './integrations/AceEditor';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useEnhancePlaceholder } from './useEnhancePlaceholder';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useEnhancePlaceholder } from './useEnhancePlaceholder';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IAceEditor } from 'react-ace/lib/types';
|
|
2
|
+
export type Params = {
|
|
3
|
+
triggerTitle?: string;
|
|
4
|
+
maxRetries?: number;
|
|
5
|
+
baseDelay?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const useAceEditor: (params?: Params) => {
|
|
8
|
+
setAceEditor: (editor: IAceEditor) => void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useEnhancePlaceholder } from './useEnhancePlaceholder';
|
|
3
|
+
import { useInsertQuery } from './useInsertQuery';
|
|
4
|
+
import { useSQLGenerationStore } from '../../store';
|
|
5
|
+
export const useAceEditor = (params) => {
|
|
6
|
+
const setIsOpen = useSQLGenerationStore(s => s.setIsOpen);
|
|
7
|
+
const resetStore = useSQLGenerationStore(s => s.reset);
|
|
8
|
+
const { setAceEditor: setAceEditorForPlaceholder } = useEnhancePlaceholder({
|
|
9
|
+
triggerTitle: params?.triggerTitle,
|
|
10
|
+
maxRetries: params?.maxRetries,
|
|
11
|
+
baseDelay: params?.baseDelay,
|
|
12
|
+
});
|
|
13
|
+
const { setAceEditor: setAceEditorForInsertQuery } = useInsertQuery({
|
|
14
|
+
onInsertQueryDone: () => {
|
|
15
|
+
setIsOpen(false);
|
|
16
|
+
resetStore();
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const setAceEditor = useCallback((editor) => {
|
|
20
|
+
setAceEditorForPlaceholder(editor);
|
|
21
|
+
setAceEditorForInsertQuery(editor);
|
|
22
|
+
}, [setAceEditorForPlaceholder, setAceEditorForInsertQuery]);
|
|
23
|
+
return { setAceEditor };
|
|
24
|
+
};
|
package/es/components/organism/SQLGeneration/integrations/AceEditor/useEnhancePlaceholder.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IAceEditor } from 'react-ace/lib/types';
|
|
2
|
+
type Params = {
|
|
3
|
+
triggerTitle?: string;
|
|
4
|
+
maxRetries?: number;
|
|
5
|
+
baseDelay?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const useEnhancePlaceholder: (params?: Params) => {
|
|
8
|
+
setAceEditor: (editor: IAceEditor) => void;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { useCallback, useRef, useEffect } from 'react';
|
|
2
|
+
import { useUnmount } from '@antscorp/antsomi-ui/es/hooks';
|
|
3
|
+
import { useSQLGenerationStore } from '../../store';
|
|
4
|
+
export const useEnhancePlaceholder = (params) => {
|
|
5
|
+
const { triggerTitle = 'generate SQL with AI', maxRetries = 5, baseDelay = 100 } = params || {};
|
|
6
|
+
const timeoutRef = useRef();
|
|
7
|
+
const mutationObserverRef = useRef(null);
|
|
8
|
+
const editorRef = useRef(null);
|
|
9
|
+
const placeholderRef = useRef(null);
|
|
10
|
+
const triggerRef = useRef(null);
|
|
11
|
+
const retryCountRef = useRef(0);
|
|
12
|
+
const isDestroyedRef = useRef(false);
|
|
13
|
+
const setModalSqlGenerationOpen = useSQLGenerationStore(state => state.setIsOpen);
|
|
14
|
+
const syncPlaceholderEl = useCallback((editor) => {
|
|
15
|
+
if (isDestroyedRef.current)
|
|
16
|
+
return false;
|
|
17
|
+
const selectedEl = editor.renderer.container.querySelector('.ace_placeholder');
|
|
18
|
+
if (selectedEl && selectedEl instanceof HTMLDivElement) {
|
|
19
|
+
placeholderRef.current = selectedEl;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}, []);
|
|
24
|
+
const waitForPlaceholder = useCallback((editor, retryCount = 0) => new Promise(resolve => {
|
|
25
|
+
if (isDestroyedRef.current) {
|
|
26
|
+
resolve(null);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Try to find placeholder immediately
|
|
30
|
+
if (syncPlaceholderEl(editor)) {
|
|
31
|
+
resolve(placeholderRef.current);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// If max retries reached, resolve with null
|
|
35
|
+
if (retryCount >= maxRetries) {
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
37
|
+
console.warn(`AceEditor placeholder not found after ${maxRetries} retries`);
|
|
38
|
+
resolve(null);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// Use exponential backoff: baseDelay * 2^retryCount
|
|
42
|
+
const delay = baseDelay * 2 ** retryCount;
|
|
43
|
+
timeoutRef.current = setTimeout(() => {
|
|
44
|
+
if (isDestroyedRef.current) {
|
|
45
|
+
resolve(null);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
waitForPlaceholder(editor, retryCount + 1).then(resolve);
|
|
49
|
+
}, delay);
|
|
50
|
+
}), [syncPlaceholderEl, maxRetries, baseDelay]);
|
|
51
|
+
const updatePlaceholderVisibility = useCallback(async (forceWait = false) => {
|
|
52
|
+
const editor = editorRef.current;
|
|
53
|
+
if (!editor || isDestroyedRef.current)
|
|
54
|
+
return;
|
|
55
|
+
// If placeholder not found and we need to wait for it
|
|
56
|
+
if (!placeholderRef.current || forceWait) {
|
|
57
|
+
clearTimeout(timeoutRef.current);
|
|
58
|
+
const placeholder = await waitForPlaceholder(editor, 0);
|
|
59
|
+
if (!placeholder || isDestroyedRef.current)
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!placeholderRef.current)
|
|
63
|
+
return;
|
|
64
|
+
const content = editor.session.getValue();
|
|
65
|
+
const isEmpty = content.length === 0;
|
|
66
|
+
const appendTriggerEl = (placeholderEl) => {
|
|
67
|
+
// Avoid duplicate triggers
|
|
68
|
+
if (triggerRef.current && placeholderEl.contains(triggerRef.current)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
let triggerEl;
|
|
72
|
+
if (triggerRef.current) {
|
|
73
|
+
triggerEl = triggerRef.current;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
triggerEl = document.createElement('span');
|
|
77
|
+
triggerRef.current = triggerEl;
|
|
78
|
+
}
|
|
79
|
+
triggerEl.classList.add('ace-sqlgen-placeholder');
|
|
80
|
+
triggerEl.innerHTML = ` or <u class='trigger-title'>${triggerTitle}</u>`;
|
|
81
|
+
triggerEl.addEventListener('click', () => {
|
|
82
|
+
setModalSqlGenerationOpen(true);
|
|
83
|
+
});
|
|
84
|
+
placeholderEl.appendChild(triggerEl);
|
|
85
|
+
};
|
|
86
|
+
if (isEmpty && placeholderRef.current) {
|
|
87
|
+
appendTriggerEl(placeholderRef.current);
|
|
88
|
+
}
|
|
89
|
+
if (!isEmpty && triggerRef.current) {
|
|
90
|
+
triggerRef.current.remove();
|
|
91
|
+
triggerRef.current = null;
|
|
92
|
+
}
|
|
93
|
+
}, [setModalSqlGenerationOpen, triggerTitle, waitForPlaceholder]);
|
|
94
|
+
// Setup MutationObserver to watch for DOM changes
|
|
95
|
+
const setupMutationObserver = useCallback((editor) => {
|
|
96
|
+
if (mutationObserverRef.current) {
|
|
97
|
+
mutationObserverRef.current.disconnect();
|
|
98
|
+
}
|
|
99
|
+
mutationObserverRef.current = new MutationObserver(mutations => {
|
|
100
|
+
if (isDestroyedRef.current)
|
|
101
|
+
return;
|
|
102
|
+
let shouldUpdate = false;
|
|
103
|
+
mutations.forEach(mutation => {
|
|
104
|
+
// Check if placeholder-related nodes were added/removed
|
|
105
|
+
if (mutation.type === 'childList') {
|
|
106
|
+
const addedNodes = Array.from(mutation.addedNodes);
|
|
107
|
+
const removedNodes = Array.from(mutation.removedNodes);
|
|
108
|
+
const hasPlaceholderChanges = [...addedNodes, ...removedNodes].some(node => node instanceof Element &&
|
|
109
|
+
(node.classList?.contains('ace_placeholder') ||
|
|
110
|
+
node.querySelector?.('.ace_placeholder')));
|
|
111
|
+
if (hasPlaceholderChanges) {
|
|
112
|
+
shouldUpdate = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
if (shouldUpdate) {
|
|
117
|
+
// Small delay to ensure DOM is stable
|
|
118
|
+
setTimeout(() => {
|
|
119
|
+
if (!isDestroyedRef.current) {
|
|
120
|
+
updatePlaceholderVisibility(true);
|
|
121
|
+
}
|
|
122
|
+
}, 50);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
// Observe the editor container for changes
|
|
126
|
+
mutationObserverRef.current.observe(editor.renderer.container, {
|
|
127
|
+
childList: true,
|
|
128
|
+
subtree: true,
|
|
129
|
+
});
|
|
130
|
+
}, [updatePlaceholderVisibility]);
|
|
131
|
+
const setAceEditorRef = useCallback((editor) => {
|
|
132
|
+
if (isDestroyedRef.current)
|
|
133
|
+
return;
|
|
134
|
+
editorRef.current = editor;
|
|
135
|
+
retryCountRef.current = 0;
|
|
136
|
+
// Setup mutation observer to watch for DOM changes
|
|
137
|
+
setupMutationObserver(editor);
|
|
138
|
+
// Initial placeholder setup
|
|
139
|
+
updatePlaceholderVisibility(true);
|
|
140
|
+
const eventCb = () => {
|
|
141
|
+
if (!isDestroyedRef.current) {
|
|
142
|
+
updatePlaceholderVisibility();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
editor.on('change', eventCb);
|
|
146
|
+
editor.on('blur', eventCb);
|
|
147
|
+
editor.on('focus', eventCb);
|
|
148
|
+
}, [updatePlaceholderVisibility, setupMutationObserver]);
|
|
149
|
+
// Cleanup function
|
|
150
|
+
const cleanup = useCallback(() => {
|
|
151
|
+
isDestroyedRef.current = true;
|
|
152
|
+
clearTimeout(timeoutRef.current);
|
|
153
|
+
if (mutationObserverRef.current) {
|
|
154
|
+
mutationObserverRef.current.disconnect();
|
|
155
|
+
mutationObserverRef.current = null;
|
|
156
|
+
}
|
|
157
|
+
if (triggerRef.current) {
|
|
158
|
+
triggerRef.current.remove();
|
|
159
|
+
triggerRef.current = null;
|
|
160
|
+
}
|
|
161
|
+
placeholderRef.current = null;
|
|
162
|
+
editorRef.current = null;
|
|
163
|
+
}, []);
|
|
164
|
+
useUnmount(cleanup);
|
|
165
|
+
// Also cleanup on component re-render if needed
|
|
166
|
+
useEffect(() => () => {
|
|
167
|
+
if (isDestroyedRef.current) {
|
|
168
|
+
cleanup();
|
|
169
|
+
}
|
|
170
|
+
}, [cleanup]);
|
|
171
|
+
return { setAceEditor: setAceEditorRef };
|
|
172
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCallback, useRef } from 'react';
|
|
2
|
+
import { useSQLGenerationStore } from '../../store';
|
|
3
|
+
export const useInsertQuery = (params) => {
|
|
4
|
+
const { onInsertQueryDone } = params || {};
|
|
5
|
+
const editorRef = useRef(null);
|
|
6
|
+
const setState = useSQLGenerationStore(s => s.setState);
|
|
7
|
+
const setAceEditorRef = useCallback((editor) => {
|
|
8
|
+
editorRef.current = editor;
|
|
9
|
+
setState({
|
|
10
|
+
onInsertSQL: sql => {
|
|
11
|
+
const content = editor.session.getValue();
|
|
12
|
+
const isEmpty = content.length === 0;
|
|
13
|
+
if (isEmpty) {
|
|
14
|
+
editor.insert(sql);
|
|
15
|
+
onInsertQueryDone?.();
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}, [setState, onInsertQueryDone]);
|
|
20
|
+
return { setAceEditor: setAceEditorRef };
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useAntsomiAI } from './useAntsomiAI';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useAntsomiAI } from './useAntsomiAI';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useAntsomiAI: () => void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useAppConfigContext } from '@antscorp/antsomi-ui/es/providers';
|
|
2
|
+
import { useSQLGenerationStore } from '../../store';
|
|
3
|
+
import { AntsomiAIQueries } from '@antscorp/antsomi-ui/es/queries/AI';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
export const useAntsomiAI = () => {
|
|
6
|
+
const setState = useSQLGenerationStore(s => s.setState);
|
|
7
|
+
const { appConfig } = useAppConfigContext();
|
|
8
|
+
const { generateSQLAsync } = AntsomiAIQueries.useSqlGeneration({
|
|
9
|
+
env: appConfig.env || 'production',
|
|
10
|
+
auth: {
|
|
11
|
+
token: appConfig.auth?.token || '',
|
|
12
|
+
userId: +(appConfig.auth?.userId || 0),
|
|
13
|
+
accountId: +(appConfig.auth?.accountId || 0),
|
|
14
|
+
portalId: +(appConfig.auth?.portalId || 0),
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setState({
|
|
19
|
+
onGenerateSQL: async (prompt, context) => {
|
|
20
|
+
const data = await generateSQLAsync({
|
|
21
|
+
prompt,
|
|
22
|
+
selected_tables: context.selectedTables,
|
|
23
|
+
history: {
|
|
24
|
+
pass_turns: context.history.pastTurns,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const generationResult = {
|
|
28
|
+
...data,
|
|
29
|
+
sqlSuggestion: data.sql_suggestion,
|
|
30
|
+
};
|
|
31
|
+
return generationResult;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}, [generateSQLAsync, setState]);
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useAntsomiSqlWS } from './useAntsomiSqlWS';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useAntsomiSqlWS } from './useAntsomiSqlWS';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useAceEditor } from '../AceEditor/useAceEditor';
|
|
2
|
+
import { useAntsomiAI } from '../AntsomiAI';
|
|
3
|
+
export const useAntsomiSqlWS = (params) => {
|
|
4
|
+
const { triggerTitle } = params || {};
|
|
5
|
+
const { setAceEditor } = useAceEditor({
|
|
6
|
+
triggerTitle,
|
|
7
|
+
});
|
|
8
|
+
useAntsomiAI();
|
|
9
|
+
return { setAceEditor };
|
|
10
|
+
};
|