Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqllab): Add docText for long keyword #24847

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,49 @@ test('returns column keywords among selected tables', async () => {
),
);
});

test('returns long keywords with docText', async () => {
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
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,
}),
),
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 && {
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
docText: value,
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
};

export function useKeywords(
{ queryEditorId, dbId, schema }: Params,
skip = false,
Expand Down Expand Up @@ -149,6 +154,7 @@ export function useKeywords(
completer: {
insertMatch,
},
...getHelperText(s.value),
})),
[schemaOptions, insertMatch],
);
Expand All @@ -163,6 +169,7 @@ export function useKeywords(
completer: {
insertMatch,
},
...getHelperText(value),
})),
[tableData?.options, insertMatch],
);
Expand All @@ -174,6 +181,7 @@ export function useKeywords(
value: col,
score: COLUMN_AUTOCOMPLETE_SCORE,
meta: 'column',
...getHelperText(col),
})),
[allColumns],
);
Expand All @@ -188,6 +196,7 @@ export function useKeywords(
completer: {
insertMatch,
},
...getHelperText(func),
})),
[functionNames, insertMatch],
);
Expand Down
Loading