-
Notifications
You must be signed in to change notification settings - Fork 11
feat: code viewer component #1511
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
10 commits
Select commit
Hold shift + click to select a range
d3ba2fb
feat: code viewer component and download file component
itssharmasandeep c51aa00
fix: add searched class
itssharmasandeep 892edcc
fix: lint and test cases
itssharmasandeep fd62c4a
Merge remote-tracking branch 'origin/main' into code-viewer
itssharmasandeep f7dcc92
fix: removinfg snippet viewer and additional changes
itssharmasandeep ebcb49b
fix: fix
itssharmasandeep 9f21e6c
fix: tests
itssharmasandeep 24f0f11
fix: addressing review comments
itssharmasandeep 176fde6
fix: addressing review comments
itssharmasandeep d415f97
Merge branch 'main' into code-viewer
itssharmasandeep 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
6 changes: 6 additions & 0 deletions
6
projects/components/src/download-file/download-file-metadata.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,6 @@ | ||
import { Observable } from 'rxjs'; | ||
|
||
export interface DownloadFileMetadata { | ||
dataSource: Observable<string>; // This should be a stringified data for any file | ||
fileName: string; | ||
} |
2 changes: 1 addition & 1 deletion
2
...ownload-json/download-json.component.scss → ...ownload-file/download-file.component.scss
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
@import 'color-palette'; | ||
|
||
.download-json { | ||
.download-file { | ||
width: 40px; | ||
height: 40px; | ||
display: flex; | ||
|
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
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
87 changes: 87 additions & 0 deletions
87
projects/components/src/viewer/code-viewer/code-viewer.component.scss
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,87 @@ | ||
@import 'mixins'; | ||
|
||
@mixin line-base { | ||
display: flex; | ||
align-items: center; | ||
width: 100%; | ||
height: 20px; | ||
|
||
&.line-highlight { | ||
background-color: $blue-2; | ||
} | ||
} | ||
|
||
.code-viewer { | ||
@include fill-container; | ||
display: grid; | ||
grid-template-rows: 54px auto; | ||
|
||
.header { | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
padding: 0 12px; | ||
border-bottom: 1px solid $gray-2; | ||
|
||
.title { | ||
@include overline; | ||
} | ||
|
||
.header-content { | ||
min-width: 0; | ||
flex: 1 1 auto; | ||
display: flex; | ||
justify-content: flex-end; | ||
|
||
.search-box { | ||
width: 140px; | ||
background-color: white; | ||
} | ||
} | ||
} | ||
|
||
.content { | ||
@include code; | ||
height: 100%; | ||
overflow-y: auto; | ||
display: grid; | ||
grid-template-columns: 40px auto; | ||
position: relative; | ||
|
||
.line-numbers { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
|
||
.line-number { | ||
@include line-base; | ||
padding-left: 8px; | ||
} | ||
} | ||
|
||
.code-lines { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
overflow-x: auto; | ||
|
||
.code-line { | ||
@include line-base; | ||
white-space: break-spaces; | ||
|
||
::ng-deep { | ||
mark { | ||
background-color: $yellow-4; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.copy-to-clipboard { | ||
position: absolute; | ||
color: $gray-9; | ||
right: 0; | ||
top: 0; | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
projects/components/src/viewer/code-viewer/code-viewer.component.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,73 @@ | ||
import { FormattingModule } from '@hypertrace/common'; | ||
import { createComponentFactory } from '@ngneat/spectator/jest'; | ||
import { MockComponent } from 'ng-mocks'; | ||
import { CopyToClipboardComponent } from '../../copy-to-clipboard/copy-to-clipboard.component'; | ||
import { DownloadFileComponent } from '../../download-file/download-file.component'; | ||
import { SearchBoxComponent } from '../../search-box/search-box.component'; | ||
import { CodeViewerComponent } from './code-viewer.component'; | ||
|
||
describe('Code Viewer Component', () => { | ||
const createComponent = createComponentFactory({ | ||
component: CodeViewerComponent, | ||
declarations: [ | ||
MockComponent(SearchBoxComponent), | ||
MockComponent(DownloadFileComponent), | ||
MockComponent(CopyToClipboardComponent) | ||
], | ||
imports: [FormattingModule], | ||
shallow: true | ||
}); | ||
const code = `{\n "key": "value" \n }`; | ||
const downloadFileName = 'code.json'; | ||
|
||
test('should render everything correctly', () => { | ||
const spectator = createComponent({ | ||
props: { | ||
code: '' | ||
} | ||
}); | ||
expect(spectator.query('.code-viewer')).not.toExist(); | ||
|
||
// Set code | ||
spectator.setInput({ | ||
code: code | ||
}); | ||
|
||
expect(spectator.query('.code-viewer')).toExist(); | ||
expect(spectator.query(SearchBoxComponent)).toExist(); | ||
expect(spectator.query(DownloadFileComponent)).not.toExist(); | ||
expect(spectator.query(CopyToClipboardComponent)).not.toExist(); | ||
expect(spectator.query('.title')).toHaveText('Code Viewer'); | ||
expect(spectator.queryAll('.line-number').length).toBe(3); | ||
expect(spectator.queryAll('.code-line').length).toBe(3); | ||
expect(spectator.queryAll('.line-number.line-highlight').length).toBe(0); | ||
expect(spectator.queryAll('.code-line.line-highlight').length).toBe(0); | ||
|
||
// Highlight text | ||
spectator.setInput({ | ||
highlightText: 'key' | ||
}); | ||
|
||
expect(spectator.queryAll('.code-line.line-highlight').length).toBe(1); | ||
expect(spectator.queryAll('.code-line.line-highlight').length).toBe(1); | ||
|
||
// Download | ||
spectator.setInput({ | ||
downloadFileName: downloadFileName | ||
}); | ||
|
||
expect(spectator.query(DownloadFileComponent)).toExist(); | ||
expect(spectator.query(DownloadFileComponent)?.metadata?.fileName).toBe(downloadFileName); | ||
|
||
// Copy to clipboard | ||
spectator.setInput({ | ||
enableCopy: true | ||
}); | ||
|
||
expect(spectator.query(CopyToClipboardComponent)).toExist(); | ||
|
||
// Search | ||
spectator.triggerEventHandler(SearchBoxComponent, 'valueChange', 'e'); | ||
expect(spectator.queryAll('mark').length).toBe(2); | ||
}); | ||
}); |
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.
why this change? How would this change the original json download?
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.
Since we have yaml as well to download, I moved to plain text, I does not affect original download