mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-08 22:12:29 +08:00
Compare commits
25 Commits
fix/update
...
fix/query-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e52397732 | ||
|
|
20ff4f3687 | ||
|
|
73ce3039ce | ||
|
|
c27a038fc5 | ||
|
|
c3c4efc6ec | ||
|
|
61296bc855 | ||
|
|
78da0076cf | ||
|
|
279b38fec3 | ||
|
|
0e348fcca4 | ||
|
|
7d79fae84d | ||
|
|
f642e0325d | ||
|
|
43a408f1c9 | ||
|
|
b97b5cf6e2 | ||
|
|
6c269a99cf | ||
|
|
24841f2dd9 | ||
|
|
c2e60c1e52 | ||
|
|
7a87d43bdc | ||
|
|
5fa1c90674 | ||
|
|
c79225ef27 | ||
|
|
0bd8fdea1f | ||
|
|
18dbd043ae | ||
|
|
a7535dec2b | ||
|
|
dbd4b7f763 | ||
|
|
68eacbbcf7 | ||
|
|
a4a0ac25cf |
@@ -24,6 +24,14 @@ const sameEditorPosition = (left: any, right: any): boolean => (
|
|||||||
&& Number(left?.column) === Number(right?.column)
|
&& Number(left?.column) === Number(right?.column)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isSelectionEmpty = (selection: any): boolean => (
|
||||||
|
!selection
|
||||||
|
|| (
|
||||||
|
Number(selection.startLineNumber) === Number(selection.endLineNumber)
|
||||||
|
&& Number(selection.startColumn) === Number(selection.endColumn)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
const stripSqlIdentifierQuotes = (value: string): string => {
|
const stripSqlIdentifierQuotes = (value: string): string => {
|
||||||
const text = String(value || '').trim();
|
const text = String(value || '').trim();
|
||||||
if (!text) return '';
|
if (!text) return '';
|
||||||
@@ -126,10 +134,11 @@ const installOceanBaseOracleNavigationFallback = (editor: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const parts = splitSqlIdentifierPath(identifier.text);
|
const parts = splitSqlIdentifierPath(identifier.text);
|
||||||
if (parts.length !== 2) {
|
if (parts.length < 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [schemaName, tableName] = parts;
|
const schemaName = parts[parts.length - 2];
|
||||||
|
const tableName = parts[parts.length - 1];
|
||||||
if (!schemaName || !tableName) {
|
if (!schemaName || !tableName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -193,6 +202,72 @@ const patchQueryEditorAiInlineRightArrowFallback = (editor: any, monaco: any) =>
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const installPrintableInputFallback = (editor: any, monaco: any) => {
|
||||||
|
const editorDomNode = editor?.getDomNode?.();
|
||||||
|
if (!editorDomNode || editor.__gonaviPrintableInputFallbackInstalled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const input = editorDomNode.querySelector?.('textarea.inputarea, .inputarea textarea, textarea') as HTMLTextAreaElement | null;
|
||||||
|
if (!(input instanceof HTMLTextAreaElement)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object.defineProperty(editor, '__gonaviPrintableInputFallbackInstalled', {
|
||||||
|
value: true,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const isReadOnly = (): boolean => {
|
||||||
|
try {
|
||||||
|
const optionId = monaco?.editor?.EditorOption?.readOnly;
|
||||||
|
return optionId !== undefined ? editor.getOption?.(optionId) === true : false;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleBeforeInput = (event: InputEvent) => {
|
||||||
|
const text = String(event.data || '');
|
||||||
|
if (
|
||||||
|
event.defaultPrevented
|
||||||
|
|| event.isComposing
|
||||||
|
|| event.inputType !== 'insertText'
|
||||||
|
|| !text
|
||||||
|
|| text.length > 8
|
||||||
|
|| isReadOnly()
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectionBefore = editor.getSelection?.();
|
||||||
|
if (!isSelectionEmpty(selectionBefore)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const beforeValue = String(editor.getValue?.() ?? '');
|
||||||
|
const beforePosition = editor.getPosition?.();
|
||||||
|
|
||||||
|
window.setTimeout(() => {
|
||||||
|
const domNode = editor.getDomNode?.();
|
||||||
|
if (!(domNode instanceof HTMLElement) || !domNode.isConnected || isReadOnly()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (document.activeElement && !domNode.contains(document.activeElement)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const afterValue = String(editor.getValue?.() ?? '');
|
||||||
|
const afterPosition = editor.getPosition?.();
|
||||||
|
if (afterValue !== beforeValue || !sameEditorPosition(beforePosition, afterPosition)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editor.trigger?.('gonavi-printable-input-fallback', 'type', { text });
|
||||||
|
}, 16);
|
||||||
|
};
|
||||||
|
|
||||||
|
input.addEventListener('beforeinput', handleBeforeInput);
|
||||||
|
editor.onDidDispose?.(() => {
|
||||||
|
input.removeEventListener('beforeinput', handleBeforeInput);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const registerGonaviMonacoThemes: BeforeMount = (monaco) => {
|
export const registerGonaviMonacoThemes: BeforeMount = (monaco) => {
|
||||||
if (transparentThemesRegistered) {
|
if (transparentThemesRegistered) {
|
||||||
return;
|
return;
|
||||||
@@ -290,6 +365,7 @@ const MonacoEditor: React.FC<MonacoEditorProps> = ({
|
|||||||
const handleMount: OnMount = useCallback((editor, monaco) => {
|
const handleMount: OnMount = useCallback((editor, monaco) => {
|
||||||
installOceanBaseOracleNavigationFallback(editor);
|
installOceanBaseOracleNavigationFallback(editor);
|
||||||
patchQueryEditorAiInlineRightArrowFallback(editor, monaco);
|
patchQueryEditorAiInlineRightArrowFallback(editor, monaco);
|
||||||
|
installPrintableInputFallback(editor, monaco);
|
||||||
onMount?.(editor, monaco);
|
onMount?.(editor, monaco);
|
||||||
}, [onMount]);
|
}, [onMount]);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const legacyLiterals = [
|
|||||||
'选择连接',
|
'选择连接',
|
||||||
'选择数据库',
|
'选择数据库',
|
||||||
'最大返回行数',
|
'最大返回行数',
|
||||||
|
'最大行数:100',
|
||||||
'最大行数:500',
|
'最大行数:500',
|
||||||
'最大行数:1000',
|
'最大行数:1000',
|
||||||
'最大行数:5000',
|
'最大行数:5000',
|
||||||
@@ -64,6 +65,7 @@ describe('QueryEditorToolbar i18n', () => {
|
|||||||
expect(source).toContain("import { useOptionalI18n } from '../i18n/provider';");
|
expect(source).toContain("import { useOptionalI18n } from '../i18n/provider';");
|
||||||
expect(source).toContain('const i18n = useOptionalI18n();');
|
expect(source).toContain('const i18n = useOptionalI18n();');
|
||||||
expect(source).toContain('const t = i18n?.t ?? defaultTranslate;');
|
expect(source).toContain('const t = i18n?.t ?? defaultTranslate;');
|
||||||
|
expect(source).toContain("{ label: '100', value: 100 }");
|
||||||
|
|
||||||
for (const key of requiredKeys) {
|
for (const key of requiredKeys) {
|
||||||
expect(source).toContain(key);
|
expect(source).toContain(key);
|
||||||
|
|||||||
@@ -291,6 +291,7 @@ const QueryEditorToolbar: React.FC<QueryEditorToolbarProps> = ({
|
|||||||
value={maxRows}
|
value={maxRows}
|
||||||
onChange={(val) => onMaxRowsChange(Number(val))}
|
onChange={(val) => onMaxRowsChange(Number(val))}
|
||||||
options={[
|
options={[
|
||||||
|
{ label: '100', value: 100 },
|
||||||
{ label: t("query_editor.max_rows.option_500"), value: 500 },
|
{ label: t("query_editor.max_rows.option_500"), value: 500 },
|
||||||
{ label: t("query_editor.max_rows.option_1000"), value: 1000 },
|
{ label: t("query_editor.max_rows.option_1000"), value: 1000 },
|
||||||
{ label: t("query_editor.max_rows.option_5000"), value: 5000 },
|
{ label: t("query_editor.max_rows.option_5000"), value: 5000 },
|
||||||
|
|||||||
@@ -26,6 +26,25 @@ describe('queryResultPagination', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('treats query-editor injected LIMIT as a capped page rather than an uncounted total', () => {
|
||||||
|
const page = createInitialQueryResultPagination({
|
||||||
|
executedSql: 'SELECT id, name FROM users LIMIT 500',
|
||||||
|
exportSql: 'SELECT id, name FROM users',
|
||||||
|
dbType: 'mysql',
|
||||||
|
returnedRowCount: 500,
|
||||||
|
fallbackPageSize: 500,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(page).toMatchObject({
|
||||||
|
current: 1,
|
||||||
|
pageSize: 500,
|
||||||
|
total: 500,
|
||||||
|
totalKnown: true,
|
||||||
|
baseSql: 'SELECT id, name FROM users',
|
||||||
|
exportAllSql: 'SELECT id, name FROM users',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('builds the next page SQL with one lookahead row', () => {
|
it('builds the next page SQL with one lookahead row', () => {
|
||||||
expect(buildQueryResultPageSql({
|
expect(buildQueryResultPageSql({
|
||||||
baseSql: 'SELECT id FROM users',
|
baseSql: 'SELECT id FROM users',
|
||||||
|
|||||||
@@ -22,6 +22,14 @@ const normalizePositiveInteger = (value: unknown): number => {
|
|||||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const normalizeSqlForComparison = (sql: string): string => (
|
||||||
|
String(sql || '')
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.replace(/;+\s*$/g, '')
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
);
|
||||||
|
|
||||||
const parseTopLevelLimit = (sql: string): LimitInfo | null => {
|
const parseTopLevelLimit = (sql: string): LimitInfo | null => {
|
||||||
const { main } = splitSqlTail(sql);
|
const { main } = splitSqlTail(sql);
|
||||||
const limitPos = findTopLevelKeyword(main, 'limit');
|
const limitPos = findTopLevelKeyword(main, 'limit');
|
||||||
@@ -60,6 +68,14 @@ const stripExplicitLimitForExport = (sql: string): string => {
|
|||||||
return splitSqlTail(sql).main.trim();
|
return splitSqlTail(sql).main.trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const wasLimitAppliedByQueryEditorCap = (executedSql: string, exportSql: string): boolean => {
|
||||||
|
const executed = String(executedSql || '').trim();
|
||||||
|
const exportable = String(exportSql || '').trim();
|
||||||
|
if (!executed || !exportable) return false;
|
||||||
|
if (normalizeSqlForComparison(executed) === normalizeSqlForComparison(exportable)) return false;
|
||||||
|
return normalizeSqlForComparison(stripExplicitLimitForExport(executed)) === normalizeSqlForComparison(stripExplicitLimitForExport(exportable));
|
||||||
|
};
|
||||||
|
|
||||||
const resolveWrappedBaseSql = (dbType: string, baseSql: string): string => {
|
const resolveWrappedBaseSql = (dbType: string, baseSql: string): string => {
|
||||||
const normalizedType = String(dbType || '').trim().toLowerCase();
|
const normalizedType = String(dbType || '').trim().toLowerCase();
|
||||||
const base = baseSql.trim();
|
const base = baseSql.trim();
|
||||||
@@ -146,11 +162,14 @@ export const createInitialQueryResultPagination = (params: {
|
|||||||
const exportAllSql = exportSql && getLeadingKeyword(exportSql) === 'select'
|
const exportAllSql = exportSql && getLeadingKeyword(exportSql) === 'select'
|
||||||
? stripExplicitLimitForExport(exportSql)
|
? stripExplicitLimitForExport(exportSql)
|
||||||
: stripExplicitLimitForExport(executedSql);
|
: stripExplicitLimitForExport(executedSql);
|
||||||
const totalState = resolveQueryResultPaginationTotal({
|
const autoLimitCap = current === 1 && wasLimitAppliedByQueryEditorCap(executedSql, exportSql);
|
||||||
current,
|
const totalState = autoLimitCap
|
||||||
pageSize,
|
? { total: returnedRowCount, totalKnown: true }
|
||||||
rowCount: returnedRowCount,
|
: resolveQueryResultPaginationTotal({
|
||||||
});
|
current,
|
||||||
|
pageSize,
|
||||||
|
rowCount: returnedRowCount,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
current,
|
current,
|
||||||
|
|||||||
@@ -93,9 +93,9 @@ func resolveWindowsUpdateFinalTargetPath(currentTarget string, sourcePath string
|
|||||||
func isVersionedWindowsUpdatePackageName(name string) bool {
|
func isVersionedWindowsUpdatePackageName(name string) bool {
|
||||||
trimmed := strings.TrimSpace(name)
|
trimmed := strings.TrimSpace(name)
|
||||||
lower := strings.ToLower(trimmed)
|
lower := strings.ToLower(trimmed)
|
||||||
return strings.HasPrefix(trimmed, "GoNavi-")
|
return strings.HasPrefix(trimmed, "GoNavi-") &&
|
||||||
&& strings.Contains(trimmed, "-Windows-")
|
strings.Contains(trimmed, "-Windows-") &&
|
||||||
&& strings.HasSuffix(lower, ".exe")
|
strings.HasSuffix(lower, ".exe")
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareWindowsStagedUpdateAsset(sourcePath string, stagedDir string) (string, error) {
|
func prepareWindowsStagedUpdateAsset(sourcePath string, stagedDir string) (string, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user