-
-
Notifications
You must be signed in to change notification settings - Fork 18
markdown widget #1433
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
markdown widget #1433
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
frontend/src/app/components/ui-components/record-edit-fields/markdown/markdown.component.css
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 @@ | ||
| .code-editor-box { | ||
| min-height: 200px; | ||
| border: 1px solid #ccc; | ||
| border-radius: 4px; | ||
| overflow: hidden; | ||
| } |
11 changes: 11 additions & 0 deletions
11
...tend/src/app/components/ui-components/record-edit-fields/markdown/markdown.component.html
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,11 @@ | ||
| <span class="mat-body-1">{{ normalizedLabel }} {{ required ? '*' : '' }}</span> | ||
|
|
||
| <div class="code-editor-box" data-hj-suppress> | ||
| <ngs-code-editor | ||
| [theme]="codeEditorTheme" | ||
| [codeModel]="mutableCodeModel" | ||
| [options]="codeEditorOptions" | ||
| [readOnly]="readonly" | ||
| (valueChanged)="onFieldChange.emit($event)"> | ||
| </ngs-code-editor> | ||
| </div> |
30 changes: 30 additions & 0 deletions
30
...d/src/app/components/ui-components/record-edit-fields/markdown/markdown.component.spec.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,30 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { MarkdownEditComponent } from './markdown.component'; | ||
| import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
| import { provideHttpClient } from '@angular/common/http'; | ||
|
|
||
| describe('MarkdownEditComponent', () => { | ||
| let component: MarkdownEditComponent; | ||
| let fixture: ComponentFixture<MarkdownEditComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [MarkdownEditComponent, BrowserAnimationsModule], | ||
| providers: [provideHttpClient()] | ||
| }).compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(MarkdownEditComponent); | ||
| component = fixture.componentInstance; | ||
|
|
||
| component.widgetStructure = { | ||
| widget_params: {} | ||
| } as any; | ||
|
|
||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
| }); |
42 changes: 42 additions & 0 deletions
42
frontend/src/app/components/ui-components/record-edit-fields/markdown/markdown.component.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,42 @@ | ||
| import { Component, Input } from '@angular/core'; | ||
|
|
||
| import { BaseEditFieldComponent } from '../base-row-field/base-row-field.component'; | ||
| import { CodeEditorModule } from '@ngstack/code-editor'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { UiSettingsService } from 'src/app/services/ui-settings.service'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-edit-markdown', | ||
| templateUrl: './markdown.component.html', | ||
| styleUrl: './markdown.component.css', | ||
| imports: [CommonModule, CodeEditorModule], | ||
| }) | ||
| export class MarkdownEditComponent extends BaseEditFieldComponent { | ||
| @Input() value; | ||
|
|
||
| public mutableCodeModel: Object; | ||
| public codeEditorOptions = { | ||
| minimap: { enabled: false }, | ||
| automaticLayout: true, | ||
| scrollBeyondLastLine: false, | ||
| wordWrap: 'on', | ||
| }; | ||
| public codeEditorTheme = 'vs-dark'; | ||
|
|
||
| constructor( | ||
| private _uiSettings: UiSettingsService, | ||
| ) { | ||
| super(); | ||
| } | ||
|
|
||
| ngOnInit(): void { | ||
| super.ngOnInit(); | ||
| this.mutableCodeModel = { | ||
| language: 'markdown', | ||
| uri: `${this.label}.md`, | ||
| value: this.value | ||
| } | ||
|
|
||
| this.codeEditorTheme = this._uiSettings.editorTheme; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
frontend/src/app/components/ui-components/record-view-fields/markdown/markdown.component.css
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,48 @@ | ||
| .markdown-container { | ||
| padding: 16px; | ||
| background: #f9f9f9; | ||
| border-radius: 4px; | ||
| border: 1px solid #e0e0e0; | ||
| min-height: 100px; | ||
| } | ||
|
|
||
| .markdown-container ::ng-deep h1, | ||
| .markdown-container ::ng-deep h2, | ||
| .markdown-container ::ng-deep h3, | ||
| .markdown-container ::ng-deep h4, | ||
| .markdown-container ::ng-deep h5, | ||
| .markdown-container ::ng-deep h6 { | ||
| margin-top: 16px; | ||
| margin-bottom: 8px; | ||
| } | ||
|
|
||
| .markdown-container ::ng-deep p { | ||
| margin-bottom: 8px; | ||
| } | ||
|
|
||
| .markdown-container ::ng-deep ul, | ||
| .markdown-container ::ng-deep ol { | ||
| margin-left: 20px; | ||
| margin-bottom: 8px; | ||
| } | ||
|
|
||
| .markdown-container ::ng-deep code { | ||
| background: #f5f5f5; | ||
| padding: 2px 4px; | ||
| border-radius: 3px; | ||
| font-family: monospace; | ||
| } | ||
|
|
||
| .markdown-container ::ng-deep pre { | ||
| background: #f5f5f5; | ||
| padding: 12px; | ||
| border-radius: 4px; | ||
| overflow-x: auto; | ||
| } | ||
|
|
||
| .markdown-container ::ng-deep blockquote { | ||
| border-left: 4px solid #ddd; | ||
| padding-left: 16px; | ||
| margin-left: 0; | ||
| color: #666; | ||
| } |
3 changes: 3 additions & 0 deletions
3
...tend/src/app/components/ui-components/record-view-fields/markdown/markdown.component.html
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,3 @@ | ||
| <div class="markdown-container"> | ||
| <markdown [data]="renderedMarkdown"></markdown> | ||
| </div> |
30 changes: 30 additions & 0 deletions
30
...d/src/app/components/ui-components/record-view-fields/markdown/markdown.component.spec.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,30 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { MarkdownRecordViewComponent } from './markdown.component'; | ||
| import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
| import { provideMarkdown } from 'ngx-markdown'; | ||
| import { provideHttpClient } from '@angular/common/http'; | ||
|
|
||
| describe('MarkdownRecordViewComponent', () => { | ||
| let component: MarkdownRecordViewComponent; | ||
| let fixture: ComponentFixture<MarkdownRecordViewComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [MarkdownRecordViewComponent, BrowserAnimationsModule], | ||
| providers: [ | ||
| provideHttpClient(), | ||
| provideMarkdown() | ||
| ] | ||
| }).compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(MarkdownRecordViewComponent); | ||
| component = fixture.componentInstance; | ||
| component.value = '# Test Markdown'; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
| }); |
19 changes: 19 additions & 0 deletions
19
frontend/src/app/components/ui-components/record-view-fields/markdown/markdown.component.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,19 @@ | ||
| import { BaseRecordViewFieldComponent } from '../base-record-view-field/base-record-view-field.component'; | ||
| import { Component, Injectable, OnInit } from '@angular/core'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { MarkdownModule } from 'ngx-markdown'; | ||
|
|
||
| @Injectable() | ||
| @Component({ | ||
| selector: 'app-markdown-record-view', | ||
| templateUrl: './markdown.component.html', | ||
| styleUrls: ['../base-record-view-field/base-record-view-field.component.css', './markdown.component.css'], | ||
| imports: [CommonModule, MarkdownModule] | ||
| }) | ||
| export class MarkdownRecordViewComponent extends BaseRecordViewFieldComponent implements OnInit { | ||
| public renderedMarkdown: string = ''; | ||
|
|
||
| ngOnInit(): void { | ||
| this.renderedMarkdown = this.value || ''; | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
...end/src/app/components/ui-components/table-display-fields/markdown/markdown.component.css
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,40 @@ | ||
| .markdown-preview { | ||
| display: inline-block; | ||
| max-width: 300px; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| white-space: nowrap; | ||
| } | ||
|
|
||
| .markdown-preview ::ng-deep p { | ||
| margin: 0; | ||
| display: inline; | ||
| } | ||
|
|
||
| .markdown-preview ::ng-deep h1, | ||
| .markdown-preview ::ng-deep h2, | ||
| .markdown-preview ::ng-deep h3, | ||
| .markdown-preview ::ng-deep h4, | ||
| .markdown-preview ::ng-deep h5, | ||
| .markdown-preview ::ng-deep h6 { | ||
| margin: 0; | ||
| display: inline; | ||
| font-size: inherit; | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| .markdown-preview ::ng-deep ul, | ||
| .markdown-preview ::ng-deep ol { | ||
| display: inline; | ||
| list-style: none; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| .markdown-preview ::ng-deep code { | ||
| background: #f5f5f5; | ||
| padding: 1px 3px; | ||
| border-radius: 2px; | ||
| font-family: monospace; | ||
| font-size: 0.9em; | ||
| } |
13 changes: 13 additions & 0 deletions
13
...nd/src/app/components/ui-components/table-display-fields/markdown/markdown.component.html
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 @@ | ||
| <div class="field-display"> | ||
| <span class="field-value markdown-preview" [matTooltip]="value"> | ||
| {{ displayTitle }} | ||
| </span> | ||
| <button type="button" mat-icon-button | ||
| class="field-copy-button" | ||
| matTooltip="Copy" | ||
| [cdkCopyToClipboard]="value" | ||
| (cdkCopyToClipboardCopied)="onCopyToClipboard.emit('Field value was copied to clipboard.')" | ||
| (click)="$event.stopPropagation()"> | ||
| <mat-icon>content_copy</mat-icon> | ||
| </button> | ||
| </div> |
99 changes: 99 additions & 0 deletions
99
...src/app/components/ui-components/table-display-fields/markdown/markdown.component.spec.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,99 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { MarkdownDisplayComponent } from './markdown.component'; | ||
| import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
| import { provideMarkdown } from 'ngx-markdown'; | ||
| import { provideHttpClient } from '@angular/common/http'; | ||
|
|
||
| describe('MarkdownDisplayComponent', () => { | ||
| let component: MarkdownDisplayComponent; | ||
| let fixture: ComponentFixture<MarkdownDisplayComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [MarkdownDisplayComponent, BrowserAnimationsModule], | ||
| providers: [ | ||
| provideHttpClient(), | ||
| provideMarkdown() | ||
| ] | ||
| }).compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(MarkdownDisplayComponent); | ||
| component = fixture.componentInstance; | ||
| component.value = '# Test Markdown'; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| describe('Title extraction', () => { | ||
| it('should extract H1 heading as title', () => { | ||
| component.value = '# Main Title\n\nSome paragraph text here.'; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('Main Title'); | ||
| }); | ||
|
|
||
| it('should extract H2 heading as title', () => { | ||
| component.value = '## Secondary Title\n\nContent follows.'; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('Secondary Title'); | ||
| }); | ||
|
|
||
| it('should prioritize heading over paragraph', () => { | ||
| component.value = 'Some intro text\n\n# Actual Title\n\nParagraph content.'; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('Actual Title'); | ||
| }); | ||
|
|
||
| it('should use first paragraph if no heading exists', () => { | ||
| component.value = 'This is the first paragraph.\n\nThis is the second paragraph.'; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('This is the first paragraph.'); | ||
| }); | ||
|
|
||
| it('should truncate long titles at 100 characters', () => { | ||
| const longTitle = 'a'.repeat(150); | ||
| component.value = `# ${longTitle}`; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('a'.repeat(100) + '...'); | ||
| }); | ||
|
|
||
| it('should handle markdown with bold and italic formatting', () => { | ||
| component.value = '# **Bold** and *italic* title'; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('**Bold** and *italic* title'); | ||
| }); | ||
|
|
||
| it('should handle empty markdown', () => { | ||
| component.value = ''; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('—'); | ||
| }); | ||
|
|
||
| it('should handle null/undefined markdown', () => { | ||
| component.value = null as any; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('—'); | ||
| }); | ||
|
|
||
| it('should handle markdown with only whitespace', () => { | ||
| component.value = ' \n\n '; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('—'); | ||
| }); | ||
|
|
||
| it('should extract title from markdown with code blocks', () => { | ||
| component.value = '# API Documentation\n\n```javascript\nconst x = 5;\n```'; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('API Documentation'); | ||
| }); | ||
|
|
||
| it('should extract title from markdown with lists', () => { | ||
| component.value = '# Shopping List\n\n- Item 1\n- Item 2'; | ||
| component.ngOnInit(); | ||
| expect(component.displayTitle).toBe('Shopping List'); | ||
| }); | ||
| }); | ||
| }); |
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.
The
renderedMarkdownproperty is unnecessary as it's just a copy ofthis.value. Consider usingvaluedirectly in the template:<markdown [data]="value || ''"></markdown>. This simplifies the code and removes unnecessary state management.