You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/08/04 17:13:43 UTC
[superset] 10/16: fix(sqllab): Add docText for long keyword (#24847)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 21ded992ad4d76ce3ebeeb4c61f024134744c293
Author: JUST.in DO IT <ju...@airbnb.com>
AuthorDate: Wed Aug 2 09:02:57 2023 -0700
fix(sqllab): Add docText for long keyword (#24847)
(cherry picked from commit 1a9c559a8f6c1e0cf59ac1d102ac42fba3458f8c)
---
.../AceEditorWrapper/useKeywords.test.ts | 46 ++++++++++++++++++++++
.../components/AceEditorWrapper/useKeywords.ts | 9 +++++
.../src/components/AsyncAceEditor/index.tsx | 2 +
3 files changed, 57 insertions(+)
diff --git a/superset-frontend/src/SqlLab/components/AceEditorWrapper/useKeywords.test.ts b/superset-frontend/src/SqlLab/components/AceEditorWrapper/useKeywords.test.ts
index 6a7c79b85b..12bd95b402 100644
--- a/superset-frontend/src/SqlLab/components/AceEditorWrapper/useKeywords.test.ts
+++ b/superset-frontend/src/SqlLab/components/AceEditorWrapper/useKeywords.test.ts
@@ -267,3 +267,49 @@ test('returns column keywords among selected tables', async () => {
),
);
});
+
+test('returns long keywords with docText', async () => {
+ const expectLongKeywordDbId = 2;
+ const longKeyword = 'veryveryveryveryverylongtablename';
+ const dbFunctionNamesApiRoute = `glob:*/api/v1/database/${expectLongKeywordDbId}/function_names/`;
+ fetchMock.get(dbFunctionNamesApiRoute, { function_names: [] });
+
+ act(() => {
+ store.dispatch(
+ schemaApiUtil.upsertQueryData(
+ 'schemas',
+ {
+ dbId: expectLongKeywordDbId,
+ forceRefresh: false,
+ },
+ ['short', longKeyword].map(value => ({
+ value,
+ label: value,
+ title: value,
+ })),
+ ),
+ );
+ });
+ const { result, waitFor } = renderHook(
+ () =>
+ useKeywords({
+ queryEditorId: 'testqueryid',
+ dbId: expectLongKeywordDbId,
+ }),
+ {
+ wrapper: createWrapper({
+ useRedux: true,
+ store,
+ }),
+ },
+ );
+ await waitFor(() =>
+ expect(result.current).toContainEqual(
+ expect.objectContaining({
+ name: longKeyword,
+ value: longKeyword,
+ docText: longKeyword,
+ }),
+ ),
+ );
+});
diff --git a/superset-frontend/src/SqlLab/components/AceEditorWrapper/useKeywords.ts b/superset-frontend/src/SqlLab/components/AceEditorWrapper/useKeywords.ts
index e7582158f4..b42edc5822 100644
--- a/superset-frontend/src/SqlLab/components/AceEditorWrapper/useKeywords.ts
+++ b/superset-frontend/src/SqlLab/components/AceEditorWrapper/useKeywords.ts
@@ -50,6 +50,11 @@ const EMPTY_LIST = [] as typeof sqlKeywords;
const { useQueryState: useSchemasQueryState } = schemaEndpoints.schemas;
const { useQueryState: useTablesQueryState } = tableEndpoints.tables;
+const getHelperText = (value: string) =>
+ value.length > 30 && {
+ docText: value,
+ };
+
export function useKeywords(
{ queryEditorId, dbId, schema }: Params,
skip = false,
@@ -149,6 +154,7 @@ export function useKeywords(
completer: {
insertMatch,
},
+ ...getHelperText(s.value),
})),
[schemaOptions, insertMatch],
);
@@ -163,6 +169,7 @@ export function useKeywords(
completer: {
insertMatch,
},
+ ...getHelperText(value),
})),
[tableData?.options, insertMatch],
);
@@ -174,6 +181,7 @@ export function useKeywords(
value: col,
score: COLUMN_AUTOCOMPLETE_SCORE,
meta: 'column',
+ ...getHelperText(col),
})),
[allColumns],
);
@@ -188,6 +196,7 @@ export function useKeywords(
completer: {
insertMatch,
},
+ ...getHelperText(func),
})),
[functionNames, insertMatch],
);
diff --git a/superset-frontend/src/components/AsyncAceEditor/index.tsx b/superset-frontend/src/components/AsyncAceEditor/index.tsx
index e4fa51f56b..2e499e150b 100644
--- a/superset-frontend/src/components/AsyncAceEditor/index.tsx
+++ b/superset-frontend/src/components/AsyncAceEditor/index.tsx
@@ -35,6 +35,8 @@ export interface AceCompleterKeywordData {
value: string;
score: number;
meta: string;
+ docText?: string;
+ docHTML?: string;
}
export type TextMode = OrigTextMode & { $id: string };