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
refactor prioritize #244
refactor prioritize #244
Conversation
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.
Love the file organization.
Didn't go through the tests too closely...
const active = ( requests, coachId ) => | ||
requests.map( request => Object.assign( {}, request, { active: isActive( request, coachId ) })) | ||
|
||
//TODO throw error if not given 2nd arg coachId |
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.
I'm not a fan of throwing an error - the function should be invoked correctly.
tests/fixtures/requests/index.js
Outdated
goal: { coach_id: coach_id || DEFAULT_COACH_ID } | ||
}) | ||
|
||
const REQUESTS = [ |
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.
Do we still need these? If so, we should generate entries using the request
function, for consistency.
describe( 'active', () => { | ||
describe( 'when no requests are active', () => { | ||
it( 'returns array with no active requests', () => { | ||
const input = [{}].map( item => request( item )) |
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.
I'm regretting the use of a function like this now in order to generate a valid request object... it makes it unclear in the test that we are generating a request. Maybe we could refactor our request function to be a member of an object that makes it clear that we are generating test mocks:
const Factory = {
request
}
Factory.request()
Factory.request({ created_at: `whatever` })
Factory.request({ coach_id: `1234-5678` })
7ebe6e6
to
d2bd79a
Compare
For your review! All tests are passing, but can't run them unless you move |
const active = ( requests, coachId ) => | ||
requests.map( request => Object.assign( {}, request, { active: isActive( request, coachId ) })) | ||
|
||
const isActive = ( request, coachId ) => request.events.some( ({ data }) => data.claimed_by === coachId ) |
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.
Can't active also mean escalated by me at some point?
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.
It is the case that an escalated-by-me request has also been previously claimed-by-me, so isActive
will catch all relevant requests.
|
||
const prioritize = requests => | ||
requests.map( request => | ||
Object.assign( {}, request, { priority: calculatePriority( request ) })) |
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.
Formatting off... I suggest closing the map on a new line, and applying sort
on that line, with proper alignment (sort
is at the same level as requests.map
)
public/javascripts/coach.js
Outdated
const visibleRequests = decoratedSortedRequests.filter( request => request.visible ) | ||
const activeRequests = decoratedSortedRequests.filter( request => request.active ) | ||
.map( request => Object.assign( {}, request, { escalatable: | ||
!request.events.some( ({ data }) => data.escalated_by === userId )} )) |
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.
Isn't this notEscalatedByMe
?
public/javascripts/coach.js
Outdated
@@ -149,6 +126,7 @@ const escalationClick = event => { | |||
const { request_id } = event.target.dataset | |||
|
|||
fetch( '/events', params( 'post', { request_id, name: 'escalate' })) | |||
.then( _ => window.location.reload( true ) ) |
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.
This was intentionally removed - refresh should happen on event publication...
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.
@jrob8577 It's not refreshing without this . . . Do you have any insights on where we could look to see why it's not?
public/javascripts/coach.js
Outdated
@@ -157,6 +135,7 @@ const claimClick = event => { | |||
const { request_id } = event.target.dataset | |||
|
|||
fetch( '/events', params( 'post', { request_id, name: 'claim' })) | |||
.then( _ => window.location.reload( true ) ) |
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.
This was intentionally removed - refresh should happen on event publication...
describe( 'notEscalatedByMe', () => { | ||
|
||
describe( 'when the request was escalated by me', () => { | ||
|
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.
Remove extraneous whitespace between describe
and first it
}) | ||
|
||
describe( 'when the request was escalated by another coach', () => { | ||
|
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.
Remove extraneous whitespace between describe
and first it
}) | ||
|
||
describe( 'when the request has not been escalated', () => { | ||
|
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.
Remove extraneous whitespace between describe
and first it
|
||
|
||
describe( 'calculatePriority', () => { | ||
|
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.
Remove extraneous whitespace between describe
and first describe
|
||
describe( 'comparing one older and one newer request', () => { | ||
|
||
const newerRequest = Factory.request( { |
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.
Move test cases into it
354b80c
to
83a3514
Compare
@@ -33,7 +33,7 @@ const queueTemplate = ({ id, goal, created_at, events, players, claimable, escal | |||
}[ events[ events.length - 1 ].name ] | |||
|
|||
return ` | |||
<div class="panel panel-${type}" data-created-at="${created_at}"> | |||
<div class="panel panel-${type}" data-created_at="${created_at}"> |
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.
This should be created-at
...
public/javascripts/coach.js
Outdated
@@ -126,7 +99,7 @@ load() | |||
const buttons = className => { | |||
const elements = document.querySelectorAll( className ) | |||
|
|||
if( elements !== null ) { | |||
if ( elements !== null ) { |
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.
There should not be a space here.
public/javascripts/coach.js
Outdated
const visibleRequests = decoratedSortedRequests.filter( request => request.visible ) | ||
const activeRequests = decoratedSortedRequests.filter( request => request.active ) | ||
.map( request => Object.assign( {}, request, { escalatable: | ||
!request.events.some( ({ data }) => data.escalated_by === userId )} )) |
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.
Formatting is hard to understand. Close map )
should align with map
goal: { coach_id: coach_id || DEFAULT_COACH_ID } | ||
}) | ||
} | ||
|
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.
remove extra space
const sortedRequests = prioritize(testRequests) | ||
|
||
expect( sortedRequests.map( request => request.events[ request.events.length - 1 ].created_at )) | ||
.to.deep.equal([ priorityOneEvent.events[ priorityOneEvent.events.length - 1 ].created_at, |
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.
Formatting hard to read.
* Complete refactor of how we sort, filter, and decorate requests * Wrote and tested small helper functions that serve active, visible, and prioritize
83a3514
to
0927bf8
Compare
No description provided.