-
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.
Merge pull request #4845 from sahil143/multi-stream-c
Multi-Stream log component
- Loading branch information
Showing
22 changed files
with
1,032 additions
and
269 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); | ||
}); | ||
}); |
101 changes: 101 additions & 0 deletions
101
frontend/packages/console-shared/src/hooks/fullscreen.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,101 @@ | ||
import * as React from 'react'; | ||
|
||
type FullScreenAPI = { | ||
requestFullscreen: string; | ||
exitFullscreen: string; | ||
fullscreenElement: string; | ||
fullscreenEnabled: string; | ||
fullscreenchange: string; | ||
fullscreenerror: string; | ||
}; | ||
|
||
const spec: FullScreenAPI = { | ||
requestFullscreen: 'requestFullscreen', | ||
exitFullscreen: 'exitFullscreen', | ||
fullscreenElement: 'fullscreenElement', | ||
fullscreenEnabled: 'fullscreenEnabled', | ||
fullscreenchange: 'fullscreenchange', | ||
fullscreenerror: 'fullscreenerror', | ||
}; | ||
|
||
const moz: FullScreenAPI = { | ||
requestFullscreen: 'mozRequestFullscreen', | ||
exitFullscreen: 'mozExitFullscreen', | ||
fullscreenElement: 'mozFullscreenElement', | ||
fullscreenEnabled: 'mozFullscreenEnabled', | ||
fullscreenchange: 'mozfullscreenchange', | ||
fullscreenerror: 'mozfullscreenerror', | ||
}; | ||
|
||
const webkit: FullScreenAPI = { | ||
requestFullscreen: 'webkitRequestFullscreen', | ||
exitFullscreen: 'webkitExitFullscreen', | ||
fullscreenElement: 'webkitFullscreenElement', | ||
fullscreenEnabled: 'webkitFullscreenEnabled', | ||
fullscreenchange: 'webkitfullscreenchange', | ||
fullscreenerror: 'webkitfullscreenerror', | ||
}; | ||
|
||
const ms: FullScreenAPI = { | ||
requestFullscreen: 'msRequestFullscreen', | ||
exitFullscreen: 'msExitFullscreen', | ||
fullscreenElement: 'msFullscreenElement', | ||
fullscreenEnabled: 'msFullscreenEnabled', | ||
fullscreenchange: 'msfullscreenchange', | ||
fullscreenerror: 'msfullscreenerror', | ||
}; | ||
|
||
const allPrefixes: FullScreenAPI[] = [spec, moz, webkit, ms]; | ||
|
||
const nativeAPI: FullScreenAPI = | ||
(function(doc) { | ||
return allPrefixes.find((x: FullScreenAPI) => !!doc[x.fullscreenEnabled]); | ||
})(document) ?? spec; | ||
|
||
export const useFullscreen = <T extends HTMLElement>(): [ | ||
boolean, | ||
(node: T) => void, | ||
() => void, | ||
boolean, | ||
] => { | ||
const [isFullscreen, setIsFullscreen] = React.useState<boolean>(false); | ||
const fullscreenRef = React.useRef<boolean>(isFullscreen); | ||
fullscreenRef.current = isFullscreen; | ||
const elementRef = React.useRef<any>(); | ||
|
||
const listener = React.useCallback((event) => { | ||
setIsFullscreen(document[nativeAPI.fullscreenElement] === event.target); | ||
}, []); | ||
|
||
const targetCallbackRef = React.useCallback( | ||
(node: T) => { | ||
if (document[nativeAPI.fullscreenEnabled]) { | ||
if (elementRef.current && elementRef.current !== node) { | ||
elementRef.current.removeEventListener(nativeAPI.fullscreenchange, listener); | ||
elementRef.current.removeEventListener(nativeAPI.fullscreenerror, listener); | ||
} | ||
if (node != null) { | ||
elementRef.current = node; | ||
node.addEventListener(nativeAPI.fullscreenchange, listener); | ||
node.addEventListener(nativeAPI.fullscreenerror, listener); | ||
} | ||
} | ||
}, | ||
[listener], | ||
); | ||
|
||
const fullscreenToggleCallback = React.useCallback(() => { | ||
if (elementRef.current && document[nativeAPI.fullscreenEnabled]) { | ||
fullscreenRef.current | ||
? document[nativeAPI.exitFullscreen]() | ||
: elementRef.current[nativeAPI.requestFullscreen](); | ||
} | ||
}, []); | ||
|
||
return [ | ||
isFullscreen, | ||
targetCallbackRef, | ||
fullscreenToggleCallback, | ||
document[nativeAPI.fullscreenEnabled], | ||
]; | ||
}; |
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,3 +1,5 @@ | ||
export * from './formik-validation-fix'; | ||
export * from './deep-compare-memoize'; | ||
export * from './document-listener'; | ||
export * from './fullscreen'; | ||
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,50 @@ | ||
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 = (): [ScrollDirection, (event) => void] => { | ||
const scrollPosition = React.useRef<number>(null); | ||
const [scrollDirection, setScrollDirection] = React.useState<ScrollDirection>(null); | ||
const handleScroll = React.useCallback( | ||
(event) => { | ||
const { scrollHeight, scrollTop, clientHeight } = event.target; | ||
if (scrollPosition.current !== null) { | ||
const direction = getScrollDirection( | ||
scrollPosition.current, | ||
scrollTop, | ||
scrollHeight, | ||
clientHeight, | ||
); | ||
if (direction && direction !== scrollDirection) setScrollDirection(direction); | ||
} | ||
scrollPosition.current = scrollTop; | ||
}, | ||
[scrollDirection], | ||
); | ||
|
||
return [scrollDirection, handleScroll]; | ||
}; |
2 changes: 2 additions & 0 deletions
2
...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.
Oops, something went wrong.