Skip to content

Commit

Permalink
Merge branch 'main' into logoFix
Browse files Browse the repository at this point in the history
  • Loading branch information
TackAdam authored Sep 6, 2024
2 parents 400e289 + e621422 commit ec450fe
Show file tree
Hide file tree
Showing 24 changed files with 310 additions and 131 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7991.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Keep Autocomplete suggestion window open and put user hints below the suggestion window ([#7991](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7991))
20 changes: 12 additions & 8 deletions src/plugins/data/public/antlr/dql/code_completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ const testingIndex = ({
} as unknown) as IndexPattern;

const booleanOperatorSuggestions = [
{ text: 'or', type: 17, detail: 'Keyword' },
{ text: 'and', type: 17, detail: 'Keyword' },
{ text: 'or', type: 11, detail: 'Operator', insertText: 'or ' },
{ text: 'and', type: 11, detail: 'Operator', insertText: 'and ' },
];

const notOperatorSuggestion = { text: 'not', type: 17, detail: 'Keyword' };
const notOperatorSuggestion = { text: 'not', type: 11, detail: 'Operator', insertText: 'not ' };

const fieldNameSuggestions: Array<{
text: string;
Expand Down Expand Up @@ -211,27 +211,31 @@ const carrierValues = [
];

const allCarrierValueSuggestions = [
{ text: 'Logstash Airways', type: 13, detail: 'Value' },
{ text: 'BeatsWest', type: 13, detail: 'Value' },
{ text: 'Logstash Airways', type: 13, detail: 'Value', insertText: 'Logstash Airways ' },
{ text: 'BeatsWest', type: 13, detail: 'Value', insertText: 'BeatsWest ' },
{
text: 'OpenSearch Dashboards Airlines',
type: 13,
detail: 'Value',
insertText: 'OpenSearch Dashboards Airlines ',
},
{ text: 'OpenSearch-Air', type: 13, detail: 'Value' },
{ text: 'OpenSearch-Air', type: 13, detail: 'Value', insertText: 'OpenSearch-Air ' },
];

const carrierWithNotSuggestions = allCarrierValueSuggestions.concat(notOperatorSuggestion);

const logCarrierValueSuggestion = [{ text: 'Logstash Airways', type: 13, detail: 'Value' }];
const logCarrierValueSuggestion = [
{ text: 'Logstash Airways', type: 13, detail: 'Value', insertText: 'Logstash Airways ' },
];

const openCarrierValueSuggestion = [
{
text: 'OpenSearch Dashboards Airlines',
type: 13,
detail: 'Value',
insertText: 'OpenSearch Dashboards Airlines ',
},
{ text: 'OpenSearch-Air', type: 13, detail: 'Value' },
{ text: 'OpenSearch-Air', type: 13, detail: 'Value', insertText: 'OpenSearch-Air ' },
];

const addPositionToValue = (vals: any, start: number, end: number) =>
Expand Down
17 changes: 14 additions & 3 deletions src/plugins/data/public/antlr/dql/code_completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const getSuggestions = async ({

// check to see if field rule is a candidate. if so, suggest field names
if (candidates.rules.has(DQLParser.RULE_field)) {
completions.push(...fetchFieldSuggestions(indexPattern, (f) => `${f}: `));
completions.push(...fetchFieldSuggestions(indexPattern, (f: any) => `${f}: `));
}

interface FoundLastValue {
Expand Down Expand Up @@ -247,12 +247,15 @@ export const getSuggestions = async ({
cursorLine,
cursorColumn + 1
),
insertText: `${val} `,
};
})
);
}
}

const dqlOperators = new Set([DQLParser.AND, DQLParser.OR, DQLParser.NOT]);

// suggest other candidates, mainly keywords
[...candidates.tokens.keys()].forEach((token: number) => {
// ignore identifier, already handled with field rule
Expand All @@ -261,11 +264,19 @@ export const getSuggestions = async ({
}

const tokenSymbolName = parser.vocabulary.getSymbolicName(token)?.toLowerCase();

if (tokenSymbolName) {
let type = monaco.languages.CompletionItemKind.Keyword;
let detail = SuggestionItemDetailsTags.Keyword;
if (dqlOperators.has(token)) {
type = monaco.languages.CompletionItemKind.Operator;
detail = SuggestionItemDetailsTags.Operator;
}
completions.push({
text: tokenSymbolName,
type: monaco.languages.CompletionItemKind.Keyword,
detail: SuggestionItemDetailsTags.Keyword,
type,
detail,
insertText: `${tokenSymbolName} `,
});
}
});
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/antlr/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const enum SuggestionItemDetailsTags {
Keyword = 'Keyword',
AggregateFunction = 'Aggregate Function',
Value = 'Value',
Operator = 'Operator',
}
export const quotesRegex = /^'(.*)'$/;
20 changes: 20 additions & 0 deletions src/plugins/data/public/ui/query_editor/_query_editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,23 @@
border: none;
}
}

.suggest-widget {
position: relative;

&.visible::after {
position: absolute;
height: auto;
bottom: auto;
left: 0;
width: 100%;
background-color: $euiColorLightestShade;
border: $euiBorderThin;
padding: $euiSizeXS;
text-align: left;
color: $euiColorDarkShade;
font-size: $euiFontSizeXS;
content: "Tab to insert, ESC to close window";
display: block;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const DefaultInput: React.FC<DefaultInputProps> = ({
}}
suggestionProvider={{
provideCompletionItems,
triggerCharacters: [' '],
}}
languageConfiguration={{
autoClosingPairs: [
Expand All @@ -65,6 +66,7 @@ export const DefaultInput: React.FC<DefaultInputProps> = ({
{ open: "'", close: "'" },
],
}}
triggerSuggestOnFocus={true}
/>
<div className="defaultEditor__footer">
{footerItems && (
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/ui/query_editor/editors/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const SingleLineInput: React.FC<SingleLineInputProps> = ({
}}
suggestionProvider={{
provideCompletionItems,
triggerCharacters: [' '],
}}
languageConfiguration={{
autoClosingPairs: [
Expand All @@ -108,6 +109,7 @@ export const SingleLineInput: React.FC<SingleLineInputProps> = ({
},
],
}}
triggerSuggestOnFocus={true}
/>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export default class QueryEditorUI extends Component<Props, State> {
insertText: s.insertText ?? s.text,
range: s.replacePosition ?? defaultRange,
detail: s.detail,
command: { id: 'editor.action.triggerSuggest', title: 'Trigger Next Suggestion' },
};
})
: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ describe('CreateButton', () => {
let component: ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>;

beforeEach(() => {
component = shallow(<CreateButton history={history} dataTestSubj={dataTestSubj} />);
component = shallow(
<CreateButton history={history} dataTestSubj={dataTestSubj} featureFlagStatus={true} />
);
});

it('should render normally', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ interface Props {
history: History;
isEmptyState?: boolean;
dataTestSubj: string;
featureFlagStatus: boolean;
}

export const CreateButton = ({ history, isEmptyState, dataTestSubj }: Props) => {
export const CreateButton = ({ history, isEmptyState, dataTestSubj, featureFlagStatus }: Props) => {
return (
<EuiSmallButton
data-test-subj={dataTestSubj}
Expand All @@ -24,7 +25,9 @@ export const CreateButton = ({ history, isEmptyState, dataTestSubj }: Props) =>
>
<FormattedMessage
id="dataSourcesManagement.dataSourceListing.createButton"
defaultMessage="Create data source connection"
defaultMessage={
featureFlagStatus ? 'Create data source connection' : 'Create direct query connection'
}
/>
</EuiSmallButton>
);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ describe('DataSourceHomePanel', () => {
expect(wrapper.find(ManageDirectQueryDataConnectionsTableWithRouter)).toHaveLength(1);
});

test('does not render OpenSearch connections tab when featureFlagStatus is false', () => {
test('does not render any tab when featureFlagStatus is false', () => {
const wrapper = shallowComponent({ ...defaultProps, featureFlagStatus: false });
expect(wrapper.find(EuiTab)).toHaveLength(1);
expect(wrapper.find(EuiTab)).toHaveLength(0);
});

test('calls history.push when CreateButton is clicked', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,9 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
useNewUX,
...props
}) => {
const {
setBreadcrumbs,
notifications,
http,
savedObjects,
uiSettings,
application,
workspaces,
docLinks,
navigation,
} = useOpenSearchDashboards<DataSourceManagementContext>().services;
const { setBreadcrumbs, application, workspaces, docLinks, navigation } = useOpenSearchDashboards<
DataSourceManagementContext
>().services;

const defaultTabId = featureFlagStatus
? 'manageOpensearchDataSources'
Expand All @@ -69,7 +61,7 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
const createDataSourceButton = [
{
id: 'Create data source',
label: 'Create data source connection',
label: featureFlagStatus ? 'Create data source connection' : 'Create direct query connection',
testId: 'createDataSourceButton',
run: () => props.history.push('/create'),
fill: true,
Expand Down Expand Up @@ -110,6 +102,25 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
},
];

const description = {
description: i18n.translate('dataSourcesManagement.dataSourcesTable.description', {
defaultMessage: featureFlagStatus
? 'Create and manage data source connections.'
: 'Manage direct query data source connections.',
}),
links: [
{
href: docLinks.links.opensearchDashboards.dataSource.guide,
controlType: 'link',
target: '_blank',
className: 'external-link-inline-block',
label: i18n.translate('dataSourcesManagement.dataSourcesTable.documentation', {
defaultMessage: 'Learn more',
}),
},
],
} as TopNavControlDescriptionData;

const renderTabs = () => {
return tabs.map((tab) => (
<EuiTab
Expand All @@ -126,10 +137,12 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
<EuiPanel>
{useNewUX && (
<>
<HeaderControl
setMountPoint={application.setAppCenterControls}
controls={connectionTypeButton}
/>
{featureFlagStatus && (
<HeaderControl
setMountPoint={application.setAppCenterControls}
controls={connectionTypeButton}
/>
)}
{canManageDataSource && (
<HeaderControl
setMountPoint={application.setAppRightControls}
Expand All @@ -151,28 +164,7 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
}
),
}
: ({
description: i18n.translate(
'dataSourcesManagement.dataSourcesTable.description',
{
defaultMessage: 'Create and manage data source connections.',
}
),
links: [
{
href: docLinks.links.opensearchDashboards.dataSource.guide,
controlType: 'link',
target: '_blank',
className: 'external-link-inline-block',
label: i18n.translate(
'dataSourcesManagement.dataSourcesTable.documentation',
{
defaultMessage: 'Learn more',
}
),
},
],
} as TopNavControlDescriptionData),
: description,
]}
/>
</>
Expand All @@ -184,28 +176,40 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
<EuiPageHeader>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
<DataSourceHeader history={props.history} />
<DataSourceHeader
history={props.history}
featureFlagStatus={featureFlagStatus}
/>
</EuiFlexItem>
{canManageDataSource ? (
<EuiFlexItem grow={false}>
<CreateButton history={props.history} dataTestSubj="createDataSourceButton" />
<CreateButton
history={props.history}
featureFlagStatus={featureFlagStatus}
dataTestSubj="createDataSourceButton"
/>
</EuiFlexItem>
) : null}
</EuiFlexGroup>
</EuiPageHeader>
</EuiFlexItem>
<EuiFlexItem>
<EuiSpacer size="s" />
<EuiTabs size="s">{renderTabs()}</EuiTabs>
</EuiFlexItem>
{featureFlagStatus && (
<EuiFlexItem>
<EuiSpacer size="s" />
<EuiTabs size="s">{renderTabs()}</EuiTabs>
</EuiFlexItem>
)}
</>
)}
<EuiFlexItem>
{selectedTabId === 'manageOpensearchDataSources' && featureFlagStatus && (
<DataSourceTableWithRouter {...props} />
)}
{selectedTabId === 'manageDirectQueryDataSources' && featureFlagStatus && (
<ManageDirectQueryDataConnectionsTableWithRouter {...props} />
{(!featureFlagStatus || selectedTabId === 'manageDirectQueryDataSources') && (
<ManageDirectQueryDataConnectionsTableWithRouter
featureFlagStatus={featureFlagStatus}
{...props}
/>
)}
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Loading

0 comments on commit ec450fe

Please sign in to comment.