-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: Fixes healthy node listing resize on large portrait screens #4564
Merged
Merged
Changes from all commits
Commits
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 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 |
---|---|---|
@@ -1,6 +1,32 @@ | ||
import { computed, get } from '@ember/object'; | ||
import Component from 'ember-collection/components/ember-collection'; | ||
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({ | ||
export default Component.extend(WithResizing, { | ||
tagName: 'div', | ||
attributeBindings: ['style'], | ||
height: 500, | ||
style: style('getStyle'), | ||
classNames: ['list-collection'], | ||
getStyle: computed('height', function() { | ||
return { | ||
height: get(this, 'height'), | ||
}; | ||
}), | ||
resize: function(e) { | ||
const $self = this.element; | ||
const $appContent = [...$$('main > div')][0]; | ||
if ($appContent) { | ||
const rect = $self.getBoundingClientRect(); | ||
const $footer = [...$$('footer[role="contentinfo"]')][0]; | ||
const space = rect.top + $footer.clientHeight; | ||
const height = e.detail.height - space; | ||
this.set('height', Math.max(0, height)); | ||
this.updateItems(); | ||
this.updateScrollPosition(); | ||
} | ||
}, | ||
}); |
This file contains 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 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 Mixin from '@ember/object/mixin'; | ||
import { get } from '@ember/object'; | ||
import { assert } from '@ember/debug'; | ||
export default Mixin.create({ | ||
resize: function(e) { | ||
assert('with-resizing.resize needs to be overridden', false); | ||
}, | ||
win: window, | ||
init: function() { | ||
this._super(...arguments); | ||
this.handler = e => { | ||
const win = e.target; | ||
this.resize({ | ||
detail: { width: win.innerWidth, height: win.innerHeight }, | ||
}); | ||
}; | ||
}, | ||
didInsertElement: function() { | ||
this._super(...arguments); | ||
get(this, 'win').addEventListener('resize', this.handler); | ||
this.didAppear(); | ||
}, | ||
didAppear: function() { | ||
this.handler({ target: get(this, 'win') }); | ||
}, | ||
willDestroyElement: function() { | ||
get(this, 'win').removeEventListener('resize', this.handler); | ||
this._super(...arguments); | ||
}, | ||
}); | ||
This file contains 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 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,26 @@ | ||
import { module } from 'qunit'; | ||
import test from 'ember-sinon-qunit/test-support/test'; | ||
import { setupTest } from 'ember-qunit'; | ||
import EmberObject from '@ember/object'; | ||
import Mixin from 'consul-ui/mixins/with-resizing'; | ||
module('Integration | Mixin | with-resizing', function(hooks) { | ||
setupTest(hooks); | ||
test('window.addEventListener, resize and window.removeEventListener are called once each through the entire lifecycle', function(assert) { | ||
const win = { | ||
innerWidth: 0, | ||
innerHeight: 0, | ||
addEventListener: this.stub(), | ||
removeEventListener: this.stub(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat. I need to look into |
||
}; | ||
const subject = EmberObject.extend(Mixin, { | ||
win: win, | ||
}).create(); | ||
const resize = this.stub(subject, 'resize'); | ||
subject.didInsertElement(); | ||
subject.willDestroyElement(); | ||
assert.ok(win.addEventListener.calledOnce); | ||
assert.ok(resize.calledOnce); | ||
assert.ok(resize.calledWith({ detail: { width: 0, height: 0 } })); | ||
assert.ok(win.removeEventListener.calledOnce); | ||
}); | ||
}); |
This file contains 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,12 @@ | ||
import EmberObject from '@ember/object'; | ||
import WithResizingMixin from 'consul-ui/mixins/with-resizing'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Mixin | with resizing'); | ||
|
||
// Replace this with your real tests. | ||
test('it works', function(assert) { | ||
let WithResizingObject = EmberObject.extend(WithResizingMixin); | ||
let subject = WithResizingObject.create(); | ||
assert.ok(subject); | ||
}); |
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.
Nice mixin. One suggestion I have is to put emphasis on resize in some manner to make it obvious that that is the interesting part for a consumer of this mixin. This could be as simple as moving
resize
to the first thing in the file so it's hard to overlook, or something more aggressive like this, which throws an error if a component/controller/whatever is mixing in the mixin without overriding the expected method.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.
Done