-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Lens][Unified search] Auto expand comboboxes and popovers based on the content #171573
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
8f31868
widen all the things
mbondyra d813f82
moving to unfied search
mbondyra bb964e2
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine d8670fb
fix type
mbondyra 2a7a0b7
move to package
mbondyra f628e1f
remove package from unified search
mbondyra dbbe762
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine 86e4e91
discover changes
mbondyra 642c672
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 4c2bf9a
trigger CI
mbondyra aeb1af5
Merge branch 'widen_eui_selectables_steps' of github.com:mbondyra/kib…
mbondyra a9e440b
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine c31ea17
Merge branch 'main' into widen_eui_selectables_steps
mbondyra a2fd59a
fix test
mbondyra 29694b8
Merge branch 'widen_eui_selectables_steps' of github.com:mbondyra/kib…
mbondyra 4177e2e
fix test
mbondyra 1c90e9c
Merge commit 'edc1b47bbda889dbbebc612f89e90e3505d171ad' into widen_eu…
mbondyra 9005945
removing the flex width changing behavior from unified search
mbondyra 0ed2882
Merge branch 'main' into widen_eui_selectables_steps
mbondyra 3902e4a
Merge commit '17ed0748e8d7671df31291d7b2bce5460c74b0f5' into widen_eu…
mbondyra 6825bb0
Merge branch 'widen_eui_selectables_steps' of github.com:mbondyra/kib…
mbondyra 8642e05
attach to right
mbondyra b880b58
add calculateWidthFromEntries
mbondyra feff1c7
make types smarter
mbondyra f6c3d64
Merge commit 'f555dbef294516517d89e9d41e14b1b2a55425dd' into widen_eu…
mbondyra 13e98f8
Revert "make types smarter"
mbondyra 2f58688
Merge commit 'a8dc2292c6f967b496611829d39c1bd769984577' into widen_eu…
mbondyra 4dbc679
revert css
mbondyra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
9 changes: 9 additions & 0 deletions
9
packages/kbn-calculate-width-from-char-count/.storybook/main.js
This file contains hidden or 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. | ||
| */ | ||
|
|
||
| module.exports = require('@kbn/storybook').defaultConfig; |
This file contains hidden or 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,3 @@ | ||
| # @kbn/calculate-width-from-char-count | ||
|
|
||
| This package contains a function that calculates the approximate width of the component from a text length. |
This file contains hidden or 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 * from './src'; |
13 changes: 13 additions & 0 deletions
13
packages/kbn-calculate-width-from-char-count/jest.config.js
This file contains hidden or 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,13 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| module.exports = { | ||
| preset: '@kbn/test/jest_node', | ||
| rootDir: '../..', | ||
| roots: ['<rootDir>/packages/kbn-calculate-width-from-char-count'], | ||
| }; |
This file contains hidden or 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,5 @@ | ||
| { | ||
| "type": "shared-common", | ||
| "id": "@kbn/calculate-width-from-char-count", | ||
| "owner": "@elastic/kibana-visualizations" | ||
| } |
This file contains hidden or 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,7 @@ | ||
| { | ||
| "name": "@kbn/calculate-width-from-char-count", | ||
| "private": true, | ||
| "version": "1.0.0", | ||
| "license": "SSPL-1.0 OR Elastic License 2.0", | ||
| "sideEffects": false | ||
| } |
21 changes: 21 additions & 0 deletions
21
packages/kbn-calculate-width-from-char-count/src/calculate_width_from_char_count.test.ts
This file contains hidden or 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,21 @@ | ||
| /* | ||
| * 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 { calculateWidthFromCharCount, MAX_WIDTH } from './calculate_width_from_char_count'; | ||
|
|
||
| describe('calculateWidthFromCharCount', () => { | ||
| it('should return minimum width if char count is smaller than minWidth', () => { | ||
| expect(calculateWidthFromCharCount(10, { minWidth: 300 })).toBe(300); | ||
| }); | ||
| it('should return calculated width', () => { | ||
| expect(calculateWidthFromCharCount(30)).toBe(30 * 7 + 116); | ||
| }); | ||
| it('should return maximum width if char count is bigger than maxWidth', () => { | ||
| expect(calculateWidthFromCharCount(1000)).toBe(MAX_WIDTH); | ||
| }); | ||
| }); |
41 changes: 41 additions & 0 deletions
41
packages/kbn-calculate-width-from-char-count/src/calculate_width_from_char_count.ts
This file contains hidden or 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,41 @@ | ||
| /* | ||
| * 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 interface LIMITS { | ||
| paddingsWidth: number; | ||
| minWidth?: number; | ||
| avCharWidth: number; | ||
| maxWidth: number; | ||
| } | ||
|
|
||
| export const MAX_WIDTH = 550; | ||
| const PADDINGS_WIDTH = 116; | ||
| const AVERAGE_CHAR_WIDTH = 7; | ||
|
|
||
| const defaultPanelWidths: LIMITS = { | ||
| maxWidth: MAX_WIDTH, | ||
| avCharWidth: AVERAGE_CHAR_WIDTH, | ||
| paddingsWidth: PADDINGS_WIDTH, | ||
| }; | ||
|
|
||
| export function calculateWidthFromCharCount( | ||
| labelLength: number, | ||
| overridesPanelWidths?: Partial<LIMITS> | ||
| ) { | ||
| const { maxWidth, avCharWidth, paddingsWidth, minWidth } = { | ||
| ...defaultPanelWidths, | ||
| ...overridesPanelWidths, | ||
| }; | ||
| const widthForCharCount = paddingsWidth + labelLength * avCharWidth; | ||
|
|
||
| if (minWidth && widthForCharCount < minWidth) { | ||
| return minWidth; | ||
| } | ||
|
|
||
| return Math.min(widthForCharCount, maxWidth); | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
packages/kbn-calculate-width-from-char-count/src/calculate_width_from_entries.test.ts
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * 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 { calculateWidthFromEntries } from './calculate_width_from_entries'; | ||
| import { MAX_WIDTH } from './calculate_width_from_char_count'; | ||
| import faker from 'faker'; | ||
|
|
||
| const generateLabel = (length: number) => faker.random.alpha({ count: length }); | ||
|
|
||
| const generateObjectWithLabelOfLength = (length: number, propOverrides?: Record<string, any>) => ({ | ||
| label: generateLabel(length), | ||
| ...propOverrides, | ||
| }); | ||
|
|
||
| describe('calculateWidthFromEntries', () => { | ||
| it('calculates width for array of strings', () => { | ||
| const shortLabels = [10, 20].map(generateLabel); | ||
| expect(calculateWidthFromEntries(shortLabels)).toBe(256); | ||
|
|
||
| const mediumLabels = [50, 55, 10, 20].map(generateLabel); | ||
| expect(calculateWidthFromEntries(mediumLabels)).toBe(501); | ||
|
|
||
| const longLabels = [80, 90, 10].map(generateLabel); | ||
| expect(calculateWidthFromEntries(longLabels)).toBe(MAX_WIDTH); | ||
| }); | ||
|
|
||
| it('calculates width for array of objects with keys', () => { | ||
| const shortLabels = [10, 20].map((v) => generateObjectWithLabelOfLength(v)); | ||
| expect(calculateWidthFromEntries(shortLabels, ['label'])).toBe(256); | ||
|
|
||
| const mediumLabels = [50, 55, 10, 20].map((v) => generateObjectWithLabelOfLength(v)); | ||
| expect(calculateWidthFromEntries(mediumLabels, ['label'])).toBe(501); | ||
|
|
||
| const longLabels = [80, 90, 10].map((v) => generateObjectWithLabelOfLength(v)); | ||
| expect(calculateWidthFromEntries(longLabels, ['label'])).toBe(MAX_WIDTH); | ||
| }); | ||
| it('calculates width for array of objects for fallback keys', () => { | ||
| const shortLabels = [10, 20].map((v) => | ||
| generateObjectWithLabelOfLength(v, { label: undefined, name: generateLabel(v) }) | ||
| ); | ||
| expect(calculateWidthFromEntries(shortLabels, ['id', 'label', 'name'])).toBe(256); | ||
|
|
||
| const mediumLabels = [50, 55, 10, 20].map((v) => | ||
| generateObjectWithLabelOfLength(v, { label: undefined, name: generateLabel(v) }) | ||
| ); | ||
| expect(calculateWidthFromEntries(mediumLabels, ['id', 'label', 'name'])).toBe(501); | ||
| }); | ||
| }); |
39 changes: 39 additions & 0 deletions
39
packages/kbn-calculate-width-from-char-count/src/calculate_width_from_entries.ts
This file contains hidden or 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,39 @@ | ||
| /* | ||
| * 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 { LIMITS, calculateWidthFromCharCount } from './calculate_width_from_char_count'; | ||
|
|
||
| type GenericObject<T = Record<string, any>> = T; | ||
|
|
||
| const getMaxLabelLengthForObjects = ( | ||
| entries: GenericObject[], | ||
| labelKeys: Array<keyof GenericObject> | ||
| ) => | ||
| entries.reduce((acc, curr) => { | ||
| const labelKey = labelKeys.find((key) => curr[key]); | ||
| if (!labelKey) { | ||
| return acc; | ||
| } | ||
| const labelLength = curr[labelKey].length; | ||
| return acc > labelLength ? acc : labelLength; | ||
| }, 0); | ||
|
|
||
| const getMaxLabelLengthForStrings = (arr: string[]) => | ||
| arr.reduce((acc, curr) => (acc > curr.length ? acc : curr.length), 0); | ||
|
|
||
| export function calculateWidthFromEntries( | ||
| entries: GenericObject[] | string[], | ||
| labelKeys?: Array<keyof GenericObject>, | ||
| overridesPanelWidths?: Partial<LIMITS> | ||
| ) { | ||
| const maxLabelLength = labelKeys | ||
| ? getMaxLabelLengthForObjects(entries as GenericObject[], labelKeys) | ||
| : getMaxLabelLengthForStrings(entries as string[]); | ||
|
|
||
| return calculateWidthFromCharCount(maxLabelLength, overridesPanelWidths); | ||
| } |
This file contains hidden or 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,11 @@ | ||
| /* | ||
| * 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 { calculateWidthFromCharCount } from './calculate_width_from_char_count'; | ||
|
|
||
| export { calculateWidthFromEntries } from './calculate_width_from_entries'; |
19 changes: 19 additions & 0 deletions
19
packages/kbn-calculate-width-from-char-count/tsconfig.json
This file contains hidden or 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,19 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "outDir": "target/types", | ||
| "types": [ | ||
| "jest", | ||
| "node", | ||
| "react", | ||
| ], | ||
| }, | ||
| "include": [ | ||
| "**/*.ts", | ||
| "**/*.tsx", | ||
| ], | ||
| "kbn_references": [], | ||
| "exclude": [ | ||
| "target/**/*", | ||
| ] | ||
| } |
89 changes: 89 additions & 0 deletions
89
packages/kbn-visualization-ui-components/components/field_picker/field_picker.test.tsx
This file contains hidden or 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,89 @@ | ||
| /* | ||
| * 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 { FieldPicker, FieldPickerProps } from './field_picker'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import faker from 'faker'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { DataType, FieldOptionValue } from './types'; | ||
|
|
||
| const generateFieldWithLabelOfLength = (length: number) => ({ | ||
| label: faker.random.alpha({ count: length }), | ||
| value: { | ||
| type: 'field' as const, | ||
| field: faker.random.alpha({ count: length }), | ||
| dataType: 'date' as DataType, | ||
| operationType: 'count', | ||
| }, | ||
| exists: true, | ||
| compatible: 1, | ||
| }); | ||
|
|
||
| const generateProps = (customField = generateFieldWithLabelOfLength(20)) => | ||
| ({ | ||
| selectedOptions: [ | ||
| { | ||
| label: 'Category', | ||
| value: { | ||
| type: 'field' as const, | ||
| field: 'category.keyword', | ||
| dataType: 'keyword' as DataType, | ||
| operationType: 'count', | ||
| }, | ||
| }, | ||
| ], | ||
| options: [ | ||
| { | ||
| label: 'nested options', | ||
| exists: true, | ||
| compatible: 1, | ||
| value: generateFieldWithLabelOfLength(20), | ||
| options: [ | ||
| generateFieldWithLabelOfLength(20), | ||
| customField, | ||
| generateFieldWithLabelOfLength(20), | ||
| ], | ||
| }, | ||
| ], | ||
| onChoose: jest.fn(), | ||
| fieldIsInvalid: false, | ||
| } as unknown as FieldPickerProps<FieldOptionValue>); | ||
|
|
||
| describe('field picker', () => { | ||
| const renderFieldPicker = (customField = generateFieldWithLabelOfLength(20)) => { | ||
| const props = generateProps(customField); | ||
| const rtlRender = render(<FieldPicker {...props} />); | ||
| return { | ||
| openCombobox: () => userEvent.click(screen.getByLabelText(/open list of options/i)), | ||
| ...rtlRender, | ||
| }; | ||
| }; | ||
|
|
||
| it('should render minimum width dropdown list if all labels are short', async () => { | ||
| const { openCombobox } = renderFieldPicker(); | ||
| openCombobox(); | ||
| const popover = screen.getByRole('dialog'); | ||
| expect(popover).toHaveStyle('inline-size: 256px'); | ||
| }); | ||
|
|
||
| it('should render calculated width dropdown list if the longest label is longer than min width', async () => { | ||
| const { openCombobox } = renderFieldPicker(generateFieldWithLabelOfLength(50)); | ||
| openCombobox(); | ||
|
|
||
| const popover = screen.getByRole('dialog'); | ||
| expect(popover).toHaveStyle('inline-size: 466px'); | ||
| }); | ||
|
|
||
| it('should render maximum width dropdown list if the longest label is longer than max width', async () => { | ||
| const { openCombobox } = renderFieldPicker(generateFieldWithLabelOfLength(80)); | ||
| openCombobox(); | ||
| const popover = screen.getByRole('dialog'); | ||
| expect(popover).toHaveStyle('inline-size: 550px'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.