-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit add http request a make reuested changes add vars fix lint errors add unit tests remove comments remove co-fetch code remove co fetch reference make request changes make requested changes make requested changes changes make requested changes rmeove fragment add tests
- Loading branch information
Showing
21 changed files
with
969 additions
and
268 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
frontend/packages/console-shared/src/hooks/__tests__/scroll.spec.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,23 @@ | ||
import { ScrollDirection, getScrollDirection } from '../scroll'; | ||
|
||
describe('getScrollDirection', () => { | ||
it('should return scrolled to bottom', () => { | ||
expect(getScrollDirection(300, 500, 1000, 500)).toEqual(ScrollDirection.scrolledToBottom); | ||
}); | ||
|
||
it('should return scrolled to top', () => { | ||
expect(getScrollDirection(500, 0, 1000, 500)).toEqual(ScrollDirection.scrolledToTop); | ||
}); | ||
|
||
it('should return scrolling down', () => { | ||
expect(getScrollDirection(300, 400, 1000, 500)).toEqual(ScrollDirection.scrollingDown); | ||
}); | ||
|
||
it('should return scrolling up', () => { | ||
expect(getScrollDirection(300, 200, 1000, 500)).toEqual(ScrollDirection.scrollingUp); | ||
}); | ||
|
||
it('should return undefined', () => { | ||
expect(getScrollDirection(300, 300, 1000, 500)).toEqual(undefined); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './formik-validation-fix'; | ||
export * from './deep-compare-memoize'; | ||
export * from './screenfull'; | ||
export * from './scroll'; |
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,31 @@ | ||
import * as React from 'react'; | ||
import * as screenfull from 'screenfull'; | ||
|
||
export const useFullScreen = (node: HTMLElement): [boolean, () => void] => { | ||
const [isFullScreen, setIsFullScreen] = React.useState<boolean>(false); | ||
|
||
const fullScreenToggleCallback = React.useCallback(() => { | ||
if (node && screenfull.enabled) { | ||
screenfull.toggle(node); | ||
} | ||
}, [node]); | ||
|
||
React.useEffect(() => { | ||
if (screenfull.enabled) { | ||
screenfull.on('change', () => { | ||
setIsFullScreen(screenfull.isFullscreen); | ||
}); | ||
screenfull.on('error', () => { | ||
setIsFullScreen(false); | ||
}); | ||
} | ||
return () => { | ||
if (screenfull.enabled) { | ||
screenfull.off('change'); | ||
screenfull.off('error'); | ||
} | ||
}; | ||
}, []); | ||
|
||
return [isFullScreen, fullScreenToggleCallback]; | ||
}; |
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,61 @@ | ||
import * as React from 'react'; | ||
|
||
export enum ScrollDirection { | ||
scrollingUp = 'scrolling-up', | ||
scrollingDown = 'scrolling-down', | ||
scrolledToBottom = 'scrolled-to-bottom', | ||
scrolledToTop = 'scrolled-to-top', | ||
} | ||
|
||
export const getScrollDirection = ( | ||
prevScrollTop: number, | ||
currentScrollTop: number, | ||
scrollHeight: number, | ||
clientHeight: number, | ||
) => { | ||
let direction; | ||
if (scrollHeight - currentScrollTop === clientHeight) { | ||
direction = ScrollDirection.scrolledToBottom; | ||
} else if (currentScrollTop === 0) { | ||
direction = ScrollDirection.scrolledToTop; | ||
} else if (prevScrollTop > currentScrollTop) { | ||
direction = ScrollDirection.scrollingUp; | ||
} else if (prevScrollTop < currentScrollTop) { | ||
direction = ScrollDirection.scrollingDown; | ||
} | ||
return direction; | ||
}; | ||
|
||
export const useScrollDirection = (node: HTMLElement) => { | ||
const scrollPosition = React.useRef(null); | ||
const [scrollDirection, setScrollDirection] = React.useState<ScrollDirection>(null); | ||
const handleScroll = React.useCallback( | ||
(event) => { | ||
const { scrollHeight, scrollTop, clientHeight } = event.target; | ||
if (scrollPosition.current) { | ||
const direction = getScrollDirection( | ||
scrollPosition.current, | ||
scrollTop, | ||
scrollHeight, | ||
clientHeight, | ||
); | ||
if (direction && direction !== scrollDirection) setScrollDirection(direction); | ||
} | ||
scrollPosition.current = scrollTop; | ||
}, | ||
[scrollDirection], | ||
); | ||
|
||
React.useEffect(() => { | ||
const eventHandler = (event) => setTimeout(() => handleScroll(event), 100); | ||
if (node) { | ||
node.addEventListener('scroll', eventHandler); | ||
} | ||
return () => { | ||
node && node.removeEventListener('scroll', eventHandler); | ||
clearTimeout(); | ||
}; | ||
}, [handleScroll, node]); | ||
|
||
return scrollDirection; | ||
}; |
1 change: 1 addition & 0 deletions
1
...nd/packages/dev-console/src/components/pipelineruns/detail-page-tabs/PipelineRunLogs.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
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
48 changes: 0 additions & 48 deletions
48
...d/packages/dev-console/src/components/pipelineruns/detail-page-tabs/PipelineTaskLogs.scss
This file was deleted.
Oops, something went wrong.
199 changes: 0 additions & 199 deletions
199
...nd/packages/dev-console/src/components/pipelineruns/detail-page-tabs/PipelineTaskLogs.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.