Skip to content

Commit 2c8faf2

Browse files
committed
mgr/dashboard: generalized code-block component
Fixes: https://tracker.ceph.com/issues/63608 Signed-off-by: Nizamudeen A <[email protected]>
1 parent f2cc24b commit 2c8faf2

File tree

7 files changed

+85
-12
lines changed

7 files changed

+85
-12
lines changed

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-form/cephfs-form.component.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,8 @@
2323
*ngIf="editing && disableRename">
2424
<p>The File System can only be renamed if it is shutdown and `refuse_client_session` is set to true.
2525
Follow the steps below in the command line and refresh the page:</p>
26-
<pre class="d-flex">{{ fsFailCmd }}
27-
<cd-copy-2-clipboard-button [source]="fsFailCmd"
28-
[byId]="false"
29-
[showIconOnly]="true"></cd-copy-2-clipboard-button>
30-
</pre>
31-
<pre class="d-flex">{{ fsSetCmd }}
32-
<cd-copy-2-clipboard-button [source]="fsSetCmd"
33-
[byId]="false"
34-
[showIconOnly]="true"></cd-copy-2-clipboard-button>
35-
</pre>
26+
<cd-code-block [codes]="[fsFailCmd]"></cd-code-block>
27+
<cd-code-block [codes]="[fsSetCmd]"></cd-code-block>
3628
</cd-alert-panel>
3729

3830
<div class="card-body">
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<ng-container *ngIf="codes.length > 1; else singleCodeBlock">
2+
<pre id="bigCodeBlock">
3+
<span *ngFor="let code of codes"
4+
class="d-flex p-2 align-items-center justify-content-between text-dark">
5+
<span>{{code}}</span>
6+
<cd-copy-2-clipboard-button
7+
[source]="code"
8+
[byId]="false"></cd-copy-2-clipboard-button>
9+
</span>
10+
</pre>
11+
</ng-container>
12+
13+
<ng-template #singleCodeBlock>
14+
<pre class="d-flex p-2 align-items-center justify-content-between text-dark"
15+
id="singleCodeBlock">
16+
<span>{{codes}}</span>
17+
<cd-copy-2-clipboard-button
18+
[source]="codes"
19+
[byId]="false"></cd-copy-2-clipboard-button>
20+
</pre>
21+
</ng-template>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@use './src/styles/vendor/variables' as vv;
2+
3+
pre {
4+
background-color: vv.$code-block-bg;
5+
border-radius: 0.5rem;
6+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { CodeBlockComponent } from './code-block.component';
4+
import { configureTestBed } from '~/testing/unit-test-helper';
5+
6+
describe('CodeBlockComponent', () => {
7+
let component: CodeBlockComponent;
8+
let fixture: ComponentFixture<CodeBlockComponent>;
9+
10+
configureTestBed({
11+
declarations: [CodeBlockComponent]
12+
});
13+
14+
beforeEach(() => {
15+
fixture = TestBed.createComponent(CodeBlockComponent);
16+
component = fixture.componentInstance;
17+
component.codes = [];
18+
fixture.detectChanges();
19+
});
20+
21+
it('should create', () => {
22+
expect(component).toBeTruthy();
23+
});
24+
25+
it('should show single codeblock if there are only one code', () => {
26+
component.codes = ['code'];
27+
fixture.detectChanges();
28+
expect(fixture.nativeElement.querySelector('#singleCodeBlock')).not.toBeNull();
29+
expect(fixture.nativeElement.querySelector('#bigCodeBlock')).toBeNull();
30+
});
31+
32+
it('should show single codeblock if there are only one code', () => {
33+
component.codes = ['code1', 'code2'];
34+
fixture.detectChanges();
35+
expect(fixture.nativeElement.querySelector('#bigCodeBlock')).not.toBeNull();
36+
expect(fixture.nativeElement.querySelector('#singleCodeBlock')).toBeNull();
37+
});
38+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Component, Input } from '@angular/core';
2+
3+
@Component({
4+
selector: 'cd-code-block',
5+
templateUrl: './code-block.component.html',
6+
styleUrls: ['./code-block.component.scss']
7+
})
8+
export class CodeBlockComponent {
9+
@Input()
10+
codes: string[];
11+
}

src/pybind/mgr/dashboard/frontend/src/app/shared/components/components.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { UsageBarComponent } from './usage-bar/usage-bar.component';
5151
import { WizardComponent } from './wizard/wizard.component';
5252
import { CardComponent } from './card/card.component';
5353
import { CardRowComponent } from './card-row/card-row.component';
54+
import { CodeBlockComponent } from './code-block/code-block.component';
5455

5556
@NgModule({
5657
imports: [
@@ -105,7 +106,8 @@ import { CardRowComponent } from './card-row/card-row.component';
105106
CdLabelComponent,
106107
ColorClassFromTextPipe,
107108
CardComponent,
108-
CardRowComponent
109+
CardRowComponent,
110+
CodeBlockComponent
109111
],
110112
providers: [],
111113
exports: [
@@ -137,7 +139,8 @@ import { CardRowComponent } from './card-row/card-row.component';
137139
CustomLoginBannerComponent,
138140
CdLabelComponent,
139141
CardComponent,
140-
CardRowComponent
142+
CardRowComponent,
143+
CodeBlockComponent
141144
]
142145
})
143146
export class ComponentsModule {}

src/pybind/mgr/dashboard/frontend/src/styles/defaults/_bootstrap-defaults.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ $chart-color-translucent-blue: #0096dc80 !default;
9696
$chart-color-border: #00000020 !default;
9797
$chart-color-translucent-yellow: #ef923472 !default;
9898

99+
$code-block-bg: #f7f7f9 !default;
100+
99101
// Typography
100102

101103
$font-family-sans-serif: 'Helvetica Neue', Helvetica, Arial, 'Noto Sans', sans-serif,

0 commit comments

Comments
 (0)