From 2c8faf256df6209994df31c93ebb19a41f038efa Mon Sep 17 00:00:00 2001 From: Nizamudeen A Date: Thu, 30 Nov 2023 14:34:41 +0530 Subject: [PATCH] mgr/dashboard: generalized code-block component Fixes: https://tracker.ceph.com/issues/63608 Signed-off-by: Nizamudeen A --- .../cephfs-form/cephfs-form.component.html | 12 +----- .../code-block/code-block.component.html | 21 ++++++++++ .../code-block/code-block.component.scss | 6 +++ .../code-block/code-block.component.spec.ts | 38 +++++++++++++++++++ .../code-block/code-block.component.ts | 11 ++++++ .../shared/components/components.module.ts | 7 +++- .../styles/defaults/_bootstrap-defaults.scss | 2 + 7 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.html create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.scss create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.spec.ts create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.ts diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-form/cephfs-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-form/cephfs-form.component.html index 18db21f891f5..f8d0fa803204 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-form/cephfs-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-form/cephfs-form.component.html @@ -23,16 +23,8 @@ *ngIf="editing && disableRename">

The File System can only be renamed if it is shutdown and `refuse_client_session` is set to true. Follow the steps below in the command line and refresh the page:

-
{{ fsFailCmd }}
-          
-        
-
{{ fsSetCmd }}
-          
-        
+ +
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.html b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.html new file mode 100644 index 000000000000..7cf78b8d1fbe --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.html @@ -0,0 +1,21 @@ + +
+    
+      {{code}}
+      
+    
+  
+
+ + +
+    {{codes}}
+    
+  
+
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.scss b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.scss new file mode 100644 index 000000000000..f601dfe6609f --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.scss @@ -0,0 +1,6 @@ +@use './src/styles/vendor/variables' as vv; + +pre { + background-color: vv.$code-block-bg; + border-radius: 0.5rem; +} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.spec.ts new file mode 100644 index 000000000000..bc5ad428fd8a --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.spec.ts @@ -0,0 +1,38 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CodeBlockComponent } from './code-block.component'; +import { configureTestBed } from '~/testing/unit-test-helper'; + +describe('CodeBlockComponent', () => { + let component: CodeBlockComponent; + let fixture: ComponentFixture; + + configureTestBed({ + declarations: [CodeBlockComponent] + }); + + beforeEach(() => { + fixture = TestBed.createComponent(CodeBlockComponent); + component = fixture.componentInstance; + component.codes = []; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('should show single codeblock if there are only one code', () => { + component.codes = ['code']; + fixture.detectChanges(); + expect(fixture.nativeElement.querySelector('#singleCodeBlock')).not.toBeNull(); + expect(fixture.nativeElement.querySelector('#bigCodeBlock')).toBeNull(); + }); + + it('should show single codeblock if there are only one code', () => { + component.codes = ['code1', 'code2']; + fixture.detectChanges(); + expect(fixture.nativeElement.querySelector('#bigCodeBlock')).not.toBeNull(); + expect(fixture.nativeElement.querySelector('#singleCodeBlock')).toBeNull(); + }); +}); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.ts new file mode 100644 index 000000000000..91d2d991f378 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/code-block/code-block.component.ts @@ -0,0 +1,11 @@ +import { Component, Input } from '@angular/core'; + +@Component({ + selector: 'cd-code-block', + templateUrl: './code-block.component.html', + styleUrls: ['./code-block.component.scss'] +}) +export class CodeBlockComponent { + @Input() + codes: string[]; +} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/components.module.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/components.module.ts index 17f418d1e148..327d208ef386 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/components.module.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/components.module.ts @@ -51,6 +51,7 @@ import { UsageBarComponent } from './usage-bar/usage-bar.component'; import { WizardComponent } from './wizard/wizard.component'; import { CardComponent } from './card/card.component'; import { CardRowComponent } from './card-row/card-row.component'; +import { CodeBlockComponent } from './code-block/code-block.component'; @NgModule({ imports: [ @@ -105,7 +106,8 @@ import { CardRowComponent } from './card-row/card-row.component'; CdLabelComponent, ColorClassFromTextPipe, CardComponent, - CardRowComponent + CardRowComponent, + CodeBlockComponent ], providers: [], exports: [ @@ -137,7 +139,8 @@ import { CardRowComponent } from './card-row/card-row.component'; CustomLoginBannerComponent, CdLabelComponent, CardComponent, - CardRowComponent + CardRowComponent, + CodeBlockComponent ] }) export class ComponentsModule {} diff --git a/src/pybind/mgr/dashboard/frontend/src/styles/defaults/_bootstrap-defaults.scss b/src/pybind/mgr/dashboard/frontend/src/styles/defaults/_bootstrap-defaults.scss index e9c8a595620a..d69abf12bc8e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/styles/defaults/_bootstrap-defaults.scss +++ b/src/pybind/mgr/dashboard/frontend/src/styles/defaults/_bootstrap-defaults.scss @@ -96,6 +96,8 @@ $chart-color-translucent-blue: #0096dc80 !default; $chart-color-border: #00000020 !default; $chart-color-translucent-yellow: #ef923472 !default; +$code-block-bg: #f7f7f9 !default; + // Typography $font-family-sans-serif: 'Helvetica Neue', Helvetica, Arial, 'Noto Sans', sans-serif, -- 2.47.3