- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8.5k
[Enterprise Search] Migrate util and components from ent-search #76051
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
      
      
            scottybollinger
  merged 10 commits into
  elastic:master
from
scottybollinger:es-migrate-utils-components
  
      
      
   
  Aug 27, 2020 
      
    
  
     Merged
                    Changes from 2 commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      bcf8eb9
              
                Migrate useDidUpdateEffect hook
              
              
                scottybollinger 0184ae7
              
                Migrate TruncateContent component
              
              
                scottybollinger d51dec7
              
                Migrate TableHeader component
              
              
                scottybollinger dc6fc2c
              
                Remove unused deps
              
              
                scottybollinger a95dc48
              
                Fix test name
              
              
                scottybollinger 7d96b7c
              
                Remove custom type in favor of DependencyList
              
              
                scottybollinger 296d9ac
              
                Add stylesheet for truncated content
              
              
                scottybollinger eacb246
              
                Actually import stylesheet
              
              
                scottybollinger 86c7de9
              
                Replace legacy mixin
              
              
                scottybollinger fdb338f
              
                Merge branch 'master' into es-migrate-utils-components
              
              
                elasticmachine 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
        
          
          
            8 changes: 8 additions & 0 deletions
          
          8 
        
  x-pack/plugins/enterprise_search/public/applications/shared/truncate/index.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,8 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|  | ||
| export { truncate, truncateBeginning } from './truncate'; | ||
| export { TruncatedContent } from './truncated_content'; | 
        
          
          
            47 changes: 47 additions & 0 deletions
          
          47 
        
  x-pack/plugins/enterprise_search/public/applications/shared/truncate/truncate.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,47 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|  | ||
| import React from 'react'; | ||
| import { shallow } from 'enzyme'; | ||
|  | ||
| import { truncate, truncateBeginning, TruncatedContent } from './'; | ||
|  | ||
| const content = 'foobarbaz'; | ||
|  | ||
| describe('TableHeader', () => { | ||
| it('renders with no truncation', () => { | ||
| const wrapper = shallow(<TruncatedContent length={4} content="foo" />); | ||
|  | ||
| expect(wrapper.find('span.truncated-content')).toHaveLength(0); | ||
| expect(wrapper.text()).toEqual('foo'); | ||
| }); | ||
|  | ||
| it('renders with truncation at the end', () => { | ||
| const wrapper = shallow(<TruncatedContent tooltipType="title" length={4} content={content} />); | ||
| const element = wrapper.find('span.truncated-content'); | ||
|  | ||
| expect(element).toHaveLength(1); | ||
| expect(element.prop('title')).toEqual(content); | ||
| expect(wrapper.text()).toEqual('foob…'); | ||
| expect(wrapper.find('span.truncated-content__tooltip')).toHaveLength(0); | ||
| }); | ||
|  | ||
| it('renders with truncation at the beginning', () => { | ||
| const wrapper = shallow( | ||
| <TruncatedContent tooltipType="title" beginning length={4} content={content} /> | ||
| ); | ||
|  | ||
| expect(wrapper.find('span.truncated-content')).toHaveLength(1); | ||
| expect(wrapper.text()).toEqual('…rbaz'); | ||
| }); | ||
|  | ||
| it('renders with inline tooltip', () => { | ||
| const wrapper = shallow(<TruncatedContent beginning length={4} content={content} />); | ||
|  | ||
| expect(wrapper.find('span.truncated-content').prop('title')).toEqual(''); | ||
| expect(wrapper.find('span.truncated-content__tooltip')).toHaveLength(1); | ||
| }); | ||
| }); | 
        
          
          
            13 changes: 13 additions & 0 deletions
          
          13 
        
  x-pack/plugins/enterprise_search/public/applications/shared/truncate/truncate.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,13 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|  | ||
| export function truncate(text: string, length: number) { | ||
| return `${text.substring(0, length)}…`; | ||
| } | ||
|  | ||
| export function truncateBeginning(text: string, length: number) { | ||
| return `…${text.substring(text.length - length)}`; | ||
| } | 
        
          
          
            33 changes: 33 additions & 0 deletions
          
          33 
        
  x-pack/plugins/enterprise_search/public/applications/shared/truncate/truncated_content.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,33 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|  | ||
| import React from 'react'; | ||
|  | ||
| import { truncate, truncateBeginning } from './'; | ||
|  | ||
| interface ITruncatedContentProps { | ||
| content: string; | ||
| length: number; | ||
| beginning?: boolean; | ||
| tooltipType?: 'inline' | 'title'; | ||
| } | ||
|  | ||
| export const TruncatedContent: React.FC<ITruncatedContentProps> = ({ | ||
| content, | ||
| length, | ||
| beginning = false, | ||
| tooltipType = 'inline', | ||
| }) => { | ||
| if (content.length <= length) return <>{content}</>; | ||
|  | ||
| const inline = tooltipType === 'inline'; | ||
| return ( | ||
| <span className="truncated-content" title={!inline ? content : ''}> | ||
| {beginning ? truncateBeginning(content, length) : truncate(content, length)} | ||
| {inline && <span className="truncated-content__tooltip">{content}</span>} | ||
| </span> | ||
| ); | ||
| }; | ||
        
          
          
            7 changes: 7 additions & 0 deletions
          
          7 
        
  x-pack/plugins/enterprise_search/public/applications/shared/use_did_update_effect/index.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,7 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|  | ||
| export { useDidUpdateEffect } from './use_did_update_effect'; | 
        
          
          
            33 changes: 33 additions & 0 deletions
          
          33 
        
  ...se_search/public/applications/shared/use_did_update_effect/use_did_update_effect.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,33 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|  | ||
| import React, { useState } from 'react'; | ||
| import { mount } from 'enzyme'; | ||
|  | ||
| import { EuiLink } from '@elastic/eui'; | ||
|  | ||
| import { useDidUpdateEffect } from './use_did_update_effect'; | ||
|  | ||
| const fn = jest.fn(); | ||
|  | ||
| const TestHook = ({ value }: { value: number }) => { | ||
| const [inputValue, setValue] = useState(value); | ||
| useDidUpdateEffect(fn, [inputValue]); | ||
| return <EuiLink onClick={() => setValue(2)} />; | ||
| }; | ||
|  | ||
| const wrapper = mount(<TestHook value={1} />); | ||
|  | ||
| describe('useDidUpdateEffect', () => { | ||
|         
                  yakhinvadim marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| it('should not fire function when value unchanged', () => { | ||
| expect(fn).not.toHaveBeenCalled(); | ||
| }); | ||
|  | ||
| it('should fire function when value changed', () => { | ||
| wrapper.find(EuiLink).simulate('click'); | ||
| expect(fn).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
        
          
          
            25 changes: 25 additions & 0 deletions
          
          25 
        
  ...erprise_search/public/applications/shared/use_did_update_effect/use_did_update_effect.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,25 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|  | ||
| /* | ||
| * Sometimes we don't want to fire the initial useEffect call. | ||
| * This custom Hook only fires after the intial render has completed. | ||
| */ | ||
| import { useEffect, useRef } from 'react'; | ||
|  | ||
| type TInput = string | number | object | Function | boolean | null | undefined; | ||
|         
                  yakhinvadim marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| export const useDidUpdateEffect = (fn: Function, inputs: TInput[]) => { | ||
| const didMountRef = useRef(false); | ||
|  | ||
| useEffect(() => { | ||
| if (didMountRef.current) { | ||
| fn(); | ||
| } else { | ||
| didMountRef.current = true; | ||
| } | ||
| }, inputs); | ||
| }; | ||
  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.