-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into elasticsearch-integration
- Loading branch information
Showing
242 changed files
with
7,157 additions
and
2,969 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,7 @@ export { | |
nodeBuilder, | ||
nodeTypes, | ||
toElasticsearchQuery, | ||
escapeKuery, | ||
} from './kuery'; | ||
|
||
export { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/kbn-es-query/src/kuery/utils/escape_kuery.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { escapeKuery } from './escape_kuery'; | ||
|
||
describe('escapeKuery', () => { | ||
test('should escape special characters', () => { | ||
const value = `This \\ has (a lot of) <special> characters, don't you *think*? "Yes."`; | ||
const expected = `This \\\\ has \\(a lot of\\) \\<special\\> characters, don't you \\*think\\*? \\"Yes.\\"`; | ||
|
||
expect(escapeKuery(value)).toBe(expected); | ||
}); | ||
|
||
test('should escape keywords', () => { | ||
const value = 'foo and bar or baz not qux'; | ||
const expected = 'foo \\and bar \\or baz \\not qux'; | ||
|
||
expect(escapeKuery(value)).toBe(expected); | ||
}); | ||
|
||
test('should escape keywords next to each other', () => { | ||
const value = 'foo and bar or not baz'; | ||
const expected = 'foo \\and bar \\or \\not baz'; | ||
|
||
expect(escapeKuery(value)).toBe(expected); | ||
}); | ||
|
||
test('should not escape keywords without surrounding spaces', () => { | ||
const value = 'And this has keywords, or does it not?'; | ||
const expected = 'And this has keywords, \\or does it not?'; | ||
|
||
expect(escapeKuery(value)).toBe(expected); | ||
}); | ||
|
||
test('should escape uppercase keywords', () => { | ||
const value = 'foo AND bar'; | ||
const expected = 'foo \\AND bar'; | ||
|
||
expect(escapeKuery(value)).toBe(expected); | ||
}); | ||
|
||
test('should escape both keywords and special characters', () => { | ||
const value = 'Hello, world, and <nice> to meet you!'; | ||
const expected = 'Hello, world, \\and \\<nice\\> to meet you!'; | ||
|
||
expect(escapeKuery(value)).toBe(expected); | ||
}); | ||
|
||
test('should escape newlines and tabs', () => { | ||
const value = 'This\nhas\tnewlines\r\nwith\ttabs'; | ||
const expected = 'This\\nhas\\tnewlines\\r\\nwith\\ttabs'; | ||
|
||
expect(escapeKuery(value)).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { flow } from 'lodash'; | ||
|
||
/** | ||
* Escapes a Kuery node value to ensure that special characters, operators, and whitespace do not result in a parsing error or unintended | ||
* behavior when using the value as an argument for the `buildNode` function. | ||
*/ | ||
export const escapeKuery = flow(escapeSpecialCharacters, escapeAndOr, escapeNot, escapeWhitespace); | ||
|
||
// See the SpecialCharacter rule in kuery.peg | ||
function escapeSpecialCharacters(str: string) { | ||
return str.replace(/[\\():<>"*]/g, '\\$&'); // $& means the whole matched string | ||
} | ||
|
||
// See the Keyword rule in kuery.peg | ||
function escapeAndOr(str: string) { | ||
return str.replace(/(\s+)(and|or)(\s+)/gi, '$1\\$2$3'); | ||
} | ||
|
||
function escapeNot(str: string) { | ||
return str.replace(/not(\s+)/gi, '\\$&'); | ||
} | ||
|
||
// See the Space rule in kuery.peg | ||
function escapeWhitespace(str: string) { | ||
return str.replace(/\t/g, '\\t').replace(/\r/g, '\\r').replace(/\n/g, '\\n'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { escapeKuery } from './escape_kuery'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
.../kbn-shared-ux-components/src/solution_avatar/__snapshots__/solution_avatar.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/kbn-shared-ux-components/src/solution_avatar/assets/texture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
packages/kbn-shared-ux-components/src/solution_avatar/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { KibanaSolutionAvatar } from './solution_avatar'; |
14 changes: 14 additions & 0 deletions
14
packages/kbn-shared-ux-components/src/solution_avatar/solution_avatar.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.kbnSolutionAvatar { | ||
@include euiBottomShadowSmall; | ||
|
||
&--xxl { | ||
@include euiBottomShadowMedium; | ||
@include size(100px); | ||
line-height: 100px; | ||
border-radius: 100px; | ||
display: inline-block; | ||
background: $euiColorEmptyShade url('/assets/texture.svg') no-repeat; | ||
background-size: cover, 125%; | ||
text-align: center; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/kbn-shared-ux-components/src/solution_avatar/solution_avatar.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { KibanaSolutionAvatar, KibanaSolutionAvatarProps } from './solution_avatar'; | ||
|
||
export default { | ||
title: 'Solution Avatar', | ||
description: 'A wrapper around EuiAvatar, specifically to stylize Elastic Solutions', | ||
}; | ||
|
||
type Params = Pick<KibanaSolutionAvatarProps, 'size' | 'name'>; | ||
|
||
export const PureComponent = (params: Params) => { | ||
return <KibanaSolutionAvatar {...params} />; | ||
}; | ||
|
||
PureComponent.argTypes = { | ||
name: { | ||
control: 'text', | ||
defaultValue: 'Kibana', | ||
}, | ||
size: { | ||
control: 'radio', | ||
options: ['s', 'm', 'l', 'xl', 'xxl'], | ||
defaultValue: 'xxl', | ||
}, | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/kbn-shared-ux-components/src/solution_avatar/solution_avatar.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { KibanaSolutionAvatar } from './solution_avatar'; | ||
|
||
describe('KibanaSolutionAvatar', () => { | ||
test('renders', () => { | ||
const component = shallow(<KibanaSolutionAvatar name="Solution" iconType="logoElastic" />); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
packages/kbn-shared-ux-components/src/solution_avatar/solution_avatar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import './solution_avatar.scss'; | ||
|
||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import { DistributiveOmit, EuiAvatar, EuiAvatarProps } from '@elastic/eui'; | ||
|
||
export type KibanaSolutionAvatarProps = DistributiveOmit<EuiAvatarProps, 'size'> & { | ||
/** | ||
* Any EuiAvatar size available, or `xxl` for custom large, brand-focused version | ||
*/ | ||
size?: EuiAvatarProps['size'] | 'xxl'; | ||
}; | ||
|
||
/** | ||
* Applies extra styling to a typical EuiAvatar; | ||
* The `name` value will be appended to 'logo' to configure the `iconType` unless `iconType` is provided. | ||
*/ | ||
export const KibanaSolutionAvatar = ({ className, size, ...rest }: KibanaSolutionAvatarProps) => { | ||
return ( | ||
// @ts-ignore Complains about ExclusiveUnion between `iconSize` and `iconType`, but works fine | ||
<EuiAvatar | ||
className={classNames( | ||
'kbnSolutionAvatar', | ||
{ | ||
[`kbnSolutionAvatar--${size}`]: size, | ||
}, | ||
className | ||
)} | ||
color="plain" | ||
size={size === 'xxl' ? 'xl' : size} | ||
iconSize={size} | ||
iconType={`logo${rest.name}`} | ||
{...rest} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.