Web console: prevent extra trim in auto complete (#8543)

* prevent extra trim in auto complete

* add unit test
This commit is contained in:
Vadim Ogievetsky 2019-09-22 15:18:51 -07:00 committed by Fangjin Yang
parent 94298f7809
commit 2104cee79b
3 changed files with 38 additions and 6 deletions

View File

@ -1,5 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`query input correctly formats helper HTML 1`] = `
"
<div class=\\"function-doc\\">
<div class=\\"function-doc-name\\">
<b>COUNT</b>
</div>
<hr />
<div>
<b>Syntax:</b>
</div>
<div>COUNT(*)</div>
<br />
<div>
<b>Description:</b>
</div>
<div>Counts the number of things</div>
</div>"
`;
exports[`query input matches snapshot 1`] = ` exports[`query input matches snapshot 1`] = `
<div <div
class="query-input" class="query-input"

View File

@ -30,4 +30,14 @@ describe('query input', () => {
const { container } = render(sqlControl); const { container } = render(sqlControl);
expect(container.firstChild).toMatchSnapshot(); expect(container.firstChild).toMatchSnapshot();
}); });
it('correctly formats helper HTML', () => {
expect(
QueryInput.completerToHtml({
caption: 'COUNT',
syntax: 'COUNT(*)',
description: 'Counts the number of things',
}),
).toMatchSnapshot();
});
}); });

View File

@ -106,11 +106,17 @@ export class QueryInput extends React.PureComponent<QueryInputProps, QueryInputS
}, },
getDocTooltip: (item: any) => { getDocTooltip: (item: any) => {
if (item.meta === 'function') { if (item.meta === 'function') {
const functionName = item.caption.slice(0, -2); item.docHTML = QueryInput.completerToHtml(item);
item.docHTML = ` }
},
});
}
static completerToHtml(item: any) {
return `
<div class="function-doc"> <div class="function-doc">
<div class="function-doc-name"> <div class="function-doc-name">
<b>${escape(functionName)}</b> <b>${escape(item.caption)}</b>
</div> </div>
<hr /> <hr />
<div> <div>
@ -124,9 +130,6 @@ export class QueryInput extends React.PureComponent<QueryInputProps, QueryInputS
<div>${escape(item.description)}</div> <div>${escape(item.description)}</div>
</div>`; </div>`;
} }
},
});
}
static getDerivedStateFromProps(props: QueryInputProps, state: QueryInputState) { static getDerivedStateFromProps(props: QueryInputProps, state: QueryInputState) {
const { columnMetadata, currentSchema, currentTable } = props; const { columnMetadata, currentSchema, currentTable } = props;