Skip to content
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

ui: Improve layout of node cards on large and small screens #4761

Merged
merged 1 commit into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions ui-v2/app/components/list-collection.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { computed, get } from '@ember/object';
import { computed, get, set } from '@ember/object';
import Component from 'ember-collection/components/ember-collection';
import PercentageColumns from 'ember-collection/layouts/percentage-columns';
import style from 'ember-computed-style';
import WithResizing from 'consul-ui/mixins/with-resizing';
import qsaFactory from 'consul-ui/utils/qsa-factory';
const $$ = qsaFactory();

export default Component.extend(WithResizing, {
tagName: 'div',
attributeBindings: ['style'],
height: 500,
cellHeight: 113,
style: style('getStyle'),
classNames: ['list-collection'],
init: function() {
this._super(...arguments);
this.columns = [25, 25, 25, 25];
},
didReceiveAttrs: function() {
this._cellLayout = this['cell-layout'] = new PercentageColumns(
get(this, 'items.length'),
get(this, 'columns'),
get(this, 'cellHeight')
);
},
getStyle: computed('height', function() {
return {
height: get(this, 'height'),
Expand All @@ -28,5 +40,35 @@ export default Component.extend(WithResizing, {
this.updateItems();
this.updateScrollPosition();
}
const width = e.detail.width;
const len = get(this, 'columns.length');
switch (true) {
case width > 1013:
if (len != 4) {
set(this, 'columns', [25, 25, 25, 25]);
}
break;
case width > 744:
if (len != 3) {
set(this, 'columns', [33, 33, 34]);
}
break;
case width > 487:
if (len != 2) {
set(this, 'columns', [50, 50]);
}
break;
case width < 488:
if (len != 1) {
set(this, 'columns', [100]);
}
}
if (len !== get(this, 'columns.length')) {
this._cellLayout = this['cell-layout'] = new PercentageColumns(
get(this, 'items.length'),
get(this, 'columns'),
get(this, 'cellHeight')
);
}
},
});
1 change: 0 additions & 1 deletion ui-v2/app/controllers/dc/services/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import WithHealthFiltering from 'consul-ui/mixins/with-health-filtering';
export default Controller.extend(WithHealthFiltering, {
init: function() {
this._super(...arguments);
this.columns = [25, 25, 25, 25];
},
unhealthy: computed('filtered', function() {
return get(this, 'filtered').filter(function(item) {
Expand Down
22 changes: 17 additions & 5 deletions ui-v2/app/styles/components/list-collection.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@
.unhealthy > div {
margin-bottom: 20px;
}
.healthy > div > ul > li {
padding-right: 23px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal at all, but for your reference, I've tried making all spacing stick to the 12, 24, 36, 48, etc., as suggested by Structure, so I was surprised to see 23, but again, not a big deal, and we can go back and do a spacing audit another time.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey!

Cool yeah for sure. These are only +s because I moved them from further below, the values haven't been changed since my initial trace of the original layouts back from when we did the initial release, which would have been before Structure.

At some point I'll be able to do a re-trace of everything, hopefully might get a chance in the next couple of weeks.

Ta

John

padding-bottom: 20px;
}
%card-grid > ul,
%card-grid > ol {
list-style-type: none;
display: grid;
grid-gap: 20px 2%;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
grid-auto-rows: 12px;
}
.healthy > div > ul > li {
padding-right: 23px;
padding-bottom: 20px;
@media #{$--fixed-grid} {
%card-grid > ul,
%card-grid > ol {
grid-gap: 20px 20px;
grid-template-columns: repeat(4, minmax(220px, 1fr));
}
}
@media #{$--lt-fixed-grid} {
%card-grid > ul,
%card-grid > ol {
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
grid-gap: 20px 2%;
}
}
3 changes: 3 additions & 0 deletions ui-v2/app/styles/variables/custom-query.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ $--lt-wide-form: '(max-width: 420px)';

$--wide-table: '(min-width: 421px)';
$--lt-wide-table: '(max-width: 420px)';

$--fixed-grid: '(min-width: 1260px)';
$--lt-fixed-grid: '(max-width: 1259px)';
2 changes: 1 addition & 1 deletion ui-v2/app/templates/components/healthchecked-resource.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<header class={{if service 'with-service' }}>
<strong>{{address}}</strong>
<strong>{{address}}</strong>
<a href={{href}}>
<span>{{name}}</span>
<em>{{service}}</em>
Expand Down
5 changes: 1 addition & 4 deletions ui-v2/app/templates/dc/nodes/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@
{{#if (gt healthy.length 0) }}
<div class="healthy">
<h2>Healthy Nodes</h2>
{{#list-collection
items=healthy
cell-layout=(percentage-columns-layout healthy.length columns 92) as |item index|
}}
{{#list-collection cellHeight=92 items=healthy as |item index|}}
{{healthchecked-resource
data-test-node=item.Node
href=(href-to 'dc.nodes.show' item.Node)
Expand Down
5 changes: 1 addition & 4 deletions ui-v2/app/templates/dc/services/show.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@
{{#if (gt healthy.length 0) }}
<div data-test-healthy class="healthy">
<h2>Healthy Nodes</h2>
{{#list-collection
items=healthy
cell-layout=(percentage-columns-layout healthy.length columns 113) as |item index|
}}
{{#list-collection cellHeight=113 items=healthy as |item index|}}
{{healthchecked-resource
href=(href-to 'dc.nodes.show' item.Node.Node)
data-test-node=item.Node.Node
Expand Down