Skip to content

mgr/dashboard: Dashboard info cards refactoring - #22902

Merged
LenzGr merged 1 commit into
ceph:masterfrom
alfonsomthd:24778-dashboard-info-cards-refactor
Jul 18, 2018
Merged

LenzGr merged 1 commit into
ceph:masterfrom
alfonsomthd:24778-dashboard-info-cards-refactor

Conversation

@alfonsomthd

@alfonsomthd alfonsomthd commented Jul 6, 2018 •

Copy link
Copy Markdown
Contributor

ceph-dashboard-master
ceph-dashboard-refactored

Refactor:
Create common Card component for info shown in landing page:

  • Overall health status
  • MON/OSD/MDS/MGR status (up, down, active, etc)

This will bring a common template and will be easier for maintain and refactor landing page in the future.

Fixes: https://tracker.ceph.com/issues/24778

@LenzGr LenzGr changed the title 24778 dashboard info cards refactor mgr/dashboard: Dashboard info cards refactoring Jul 6, 2018
@@ -0,0 +1,27 @@
<div class="col-md-6">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having <div class="col-md-6"> inside the component template is very limiting. I recommend that this shoudl be declared outsite, by the one that uses the component:

<div class="col-md-6">
  <cd-info-card ...
...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'll implement it.

@epuertat epuertat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great first step towards a more flexible landing page, Alfonso!

Please, have a look at the approach mentioned below. Tried to provide examples on how the component could be instantiated and fully initialized from the HTML template, instead of relying on TS initialization. This should save all the initialization boilerplate and a few other bits of code, and we could besides add new widgets without touching any TS code.

</div>
<cd-info-card
*ngIf="monitorsCard"
[infoCard]="monitorsCard">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about making the info card parametrizable and exposing those params from the template:

<cd-info-card
  [title]="Monitors"
  [link]="/monitor"
  [iconClass]="fa-database"
  [info]='contentData.mon_status | monSummary'
></cd-info-card>

</cd-info-card>

<cd-info-card
*ngIf="osdCard"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<cd-info-card
  [title]="OSDs"
  [link]='/osd'
  [iconClass]='fa-hdff'
  [info]='contentData.mon_status | osdSummary'
></cd-info-card>

</div>
</div>
<cd-info-card
*ngIf="mdsCard"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<cd-info-card
  [title]="Metadata Servers"
  [iconClass]='fa-folder'
  [info]='contentData.mon_status | mdsSummary'
></cd-info-card>

</cd-info-card>

<cd-info-card
*ngIf="mgrCard"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<cd-info-card
  [title]="Managers"
  [iconClass]='fa-cog'
  [info]='contentData.mon_status | mgrSummary'
></cd-info-card>

</div>
</div>
<cd-info-card
*ngIf="healthStatusCard"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This first card is the trickiest one. One approach could be by-passing the HTML within the tags to the cd-info-card template (via tags):

<cd-info-card
  [title]="Health"
  [info]="contentData.health.status | healthColor"
>
  <ul>
    <li *ngFor="let check of contentData.health.checks">	
      <span [ngStyle]="check.severity | healthColor">{{ check.type }}</span>: {{ check.summary.message }}	
    </li>	
  </ul>
</cd-info-card>

@tspmelo

tspmelo commented Jul 6, 2018

Copy link
Copy Markdown
Contributor

I agree with @epuertat and would even go 1 step further and remove the info input.
This would allow us to use the component for more generic content, like the pool card and the charts card.

<cd-info-card  [title]="Health">
  <ng-container i18n>Overall status: </ng-container>
  <span [ngStyle]="contentData.health.status | healthColor">{{ contentData.health.status }}</span>
  <ul>
    <li *ngFor="let check of contentData.health.checks">	
      <span [ngStyle]="check.severity | healthColor">{{ check.type }}</span>: {{ check.summary.message }}	
    </li>	
  </ul>
</cd-info-card>
<cd-info-card [title]="Pools">
  <table class="table table-condensed">
    ...
  </table>
</cd-info-card>
<cd-info-card [title]="Usage">
  <table class="ceph-chartbox">
    ...
  </table>
</cd-info-card>

@@ -17,6 +17,8 @@ import { OsdSummaryPipe } from './osd-summary.pipe';
import { PgStatusStylePipe } from './pg-status-style.pipe';
import { PgStatusPipe } from './pg-status.pipe';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line.

</fieldset>
</div>
</div>
<cd-info-card

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually keep the first attribute in the same line of the element and align the following attributes in the column of the 1st attribute.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.
But (only asking), is it not better for readability to have standard indentation (2-4 spaces) than indentation/alignment depending on tag length?

</div>
</div>
<cd-info-card
*ngIf="healthStatusCard"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be simplified if you moved this verification inside CdInfoCard, that way you just need to declared it once.


import { InfoCard } from '../info-card/info-card';
import { InfoCardAdditionalInfo } from '../info-card/info-card-additional-info';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line.
We should have only 3 groups of imports (groups are separated by a blank line), 1 for @angular imports, another for external plugins and the last for our imports.

@@ -4,6 +4,15 @@ import * as _ from 'lodash';

import { DashboardService } from '../../../shared/api/dashboard.service';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line.

@alfonsomthd

Copy link
Copy Markdown
Contributor Author

Hi @epuertat @tspmelo,
I take into account your recommendations and I'll implement them, but about this @tspmelo suggestion:
"to use the component for more generic content, like the pool card and the charts card."
My original idea was to have dedicated components for pool/chart as I understand
that they require dedicated templates. My question is:
Do we want a one-for-all kind of card?

@epuertat

epuertat commented Jul 9, 2018 •

Copy link
Copy Markdown
Member

@tspmelo My suggestion to @alfonsomthd was simply to open the component tag arguments, so cards could be stateless and fully characterized by their @Inputs, not requiring any further embedded Typescript code.

However, the idea to allow the interface to pass 'free-form' HTML tags/templating was just to cope with the current design, not to enforce that, as in my opinion it's better to move visual hinting (colors, formatting, etc.) to the widget's logic, being that the single responsibility for a widget (information representation).

What about something like the following design (if anyone wants to modify it, please let me know and I'll share an editable link):
widget interface design

@epuertat epuertat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking into account my suggestions! Please, just ensure to check my minor comments and proceed as you consider, but you can count on my ok.

</div>
</div>
</div>
<cd-info-card title="MONITORS"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor comment, but uppercase here would be just a style, so title could be 'Monitors' or even 'monitors', and then capitalize it in the component template:

{{ title | uppercase }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in favor of forcing the uppercase. In fact, there are design proposals to move to "Monitors".

</div>
</div>
<cd-info-card title="MONITORS"
class="col-md-6"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If col-md-6 seems to be the default one, why not overriding it, or setting it as default:

@Input() class: string = 'col-md-6';

@alfonsomthd alfonsomthd Jul 9, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll implement it.
By setting it at selector level I was trying to avoid an additional enclosing < div > (needed to respect the current look and feel).
It would also be good to define if the project style guide contains "Convention over configuration" (e.g. providing sensible default values as much as possible)
in order for all contributors to follow the same coding style.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love that 'convention over configuration'! Not sure if there's a style guide for Ceph (only could find this). This might be an interesting topic to discuss!

@@ -0,0 +1,18 @@
<div [class]="class">
<div class="well">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a class (eg. class = "info-card") and put all scss inside it. Example

.info-card{
  .center-block{...
  ...
}

@tspmelo

tspmelo commented Jul 11, 2018

Copy link
Copy Markdown
Contributor

as in my opinion it's better to move visual hinting (colors, formatting, etc.) to the widget's logic, being that the single responsibility for a widget (information representation).

You can still achieve that if you pass free form html.
You just need to use ::ng-deep in the style rules and it will apply to all the html that is transcluded in the component.

@epuertat I like your proposed design.
But would suggest keep using CdInfoCard as a component and use it in all the specific InfoCard components.

Should we implement that in this PR or wait for the redesign of the health page with all the new cards?
During the redesign we would have a better overview of the needs for all the info card types and would need less refactors...

@alfonsomthd If we don't implement @epuertat suggestion, I would suggest to also wrap the Usage and Pools card with the new cd-info-card component, for better consistence.

selector: 'cd-info-card',
templateUrl: './info-card.component.html',
styleUrls: ['./info-card.component.scss'],
encapsulation: ViewEncapsulation.None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use this encapsulation.
This will result in the css from this component to be applied to the whole document.

@alfonsomthd

Copy link
Copy Markdown
Contributor Author

@tspmelo @epuertat IMHO the decision about implementing dedicated cardComponents for Charts (Usage) or Tables (Pools) can be taken after this PR and start a new issue/PR in order to not refactor code pieces that, after the decision, should be refactored again...

@tspmelo

tspmelo commented Jul 11, 2018

Copy link
Copy Markdown
Contributor

@alfonsomthd We don't need to create new components in order to use the CdInfoCard on the Usage and Pools. Please use it, the same way you are doing for the Health Card.
That way we have all the cards equal.

@tspmelo

tspmelo commented Jul 12, 2018

Copy link
Copy Markdown
Contributor

@alfonsomthd Please add a title to the commit with a brief summary.
And keep all lines to a max of 80 columns.

@alfonsomthd

alfonsomthd commented Jul 12, 2018 •

Copy link
Copy Markdown
Contributor Author

@tspmelo commit message updated.

@tspmelo @epuertat Should we create a commit-msg hook example in the repo with this "80-column-max length for commit message line " rule and maybe others that I'm not aware of?

…g page:

Info encapsulated in cd-info-card selector:
- Overall health status, MON/OSD/MDS/MGR status

Fixes: https://tracker.ceph.com/issues/24778

Signed-off-by: Alfonso Martínez <[email protected]>
@LenzGr
LenzGr merged commit 2c783eb into ceph:master Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants