-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
compactMode: add collapsible functionality + reog job card layout #687
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4457f00
compactMode: add collapsible functionality + reog job card layout
ivnnv e742967
update highlight component + improved collapsible
ivnnv e3ad62f
fix arrowup icon
ivnnv ede9ae1
revert attempt condition
ivnnv d41fc01
implement global setting
ivnnv caecbba
modify highlt prop name + allow live job collapse setting update
ivnnv b42bc80
Merge branch 'master' into compactMode
felixmosh 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 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 |
---|---|---|
@@ -1,58 +1,46 @@ | ||
import cn from 'clsx'; | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { asyncHighlight } from '../../utils/highlight/highlight'; | ||
import s from './Highlight.module.css'; | ||
import { Button } from '../Button/Button'; | ||
import { CopyIcon } from '../Icons/Copy'; | ||
|
||
interface HighlightProps { | ||
language: 'json' | 'stacktrace'; | ||
children: string | null; | ||
text: string; | ||
} | ||
|
||
export class Highlight extends React.Component<HighlightProps> { | ||
private codeRef = React.createRef<HTMLPreElement>(); | ||
|
||
public shouldComponentUpdate(nextProps: Readonly<HighlightProps>) { | ||
return ( | ||
nextProps.language !== this.props.language || | ||
(Array.isArray(this.props.children) | ||
? this.props.children.some( | ||
(item: any) => !([] as any).concat(nextProps.children).includes(item) | ||
) | ||
: nextProps.children !== this.props.children) | ||
); | ||
} | ||
|
||
public componentDidMount() { | ||
return this.highlightCode(); | ||
} | ||
|
||
public componentDidUpdate() { | ||
return this.highlightCode(); | ||
} | ||
|
||
public render() { | ||
const { language } = this.props; | ||
return ( | ||
<div className={s.codeContainerWrapper}> | ||
<pre ref={this.codeRef}> | ||
<code className={cn('hljs', language)} /> | ||
</pre> | ||
<Button | ||
onClick={() => navigator.clipboard.writeText(this.props.children ?? '')} | ||
className={s.copyBtn} | ||
> | ||
<CopyIcon /> | ||
</Button> | ||
</div> | ||
); | ||
} | ||
|
||
private async highlightCode() { | ||
const node = this.codeRef.current?.querySelector('code'); | ||
if (node) { | ||
node.innerHTML = await asyncHighlight(this.props.children as string, this.props.language); | ||
} | ||
} | ||
} | ||
export const Highlight: React.FC<HighlightProps> = ({ language, text }) => { | ||
const [code, setCode] = useState<string>(''); | ||
|
||
const textToCode = async () => { | ||
setCode(await asyncHighlight(text as string, language)); | ||
}; | ||
|
||
useEffect(() => { | ||
textToCode(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
textToCode(); | ||
}, [language, text]); | ||
|
||
const handleCopyClick = () => { | ||
navigator.clipboard.writeText(text ?? ''); | ||
}; | ||
|
||
return ( | ||
<div className={s.codeContainerWrapper}> | ||
<pre> | ||
<code className={cn('hljs', language)} dangerouslySetInnerHTML={{ __html: code }} /> | ||
</pre> | ||
|
||
<Button | ||
onClick={handleCopyClick} | ||
className={s.copyBtn} | ||
> | ||
<CopyIcon /> | ||
</Button> | ||
</div> | ||
); | ||
}; |
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,5 @@ | ||
import React from 'react'; | ||
|
||
export const ArrowUpIcon = () => ( | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M241 130.5l194.3 194.3c9.4 9.4 9.4 24.6 0 33.9l-22.7 22.7c-9.4 9.4-24.5 9.4-33.9 0L224 227.5 69.3 381.5c-9.4 9.3-24.5 9.3-33.9 0l-22.7-22.7c-9.4-9.4-9.4-24.6 0-33.9L207 130.5C216.4 121.2 231.6 121.2 241 130.5z"/></svg> | ||
); |
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
2 changes: 1 addition & 1 deletion
2
packages/ui/src/components/JobCard/Timeline/Timeline.module.css
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls move this refactor to a separate PR 🙏🏽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure! lets process this first 👍🏽