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

refactor prioritize #244

Merged
merged 1 commit into from
Apr 14, 2017

Conversation

EthanJStark
Copy link
Collaborator

No description provided.

@EthanJStark EthanJStark changed the title 240 refactor prioritize WIP refactor prioritize Apr 14, 2017
Copy link
Contributor

@jrob8577 jrob8577 left a 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
Copy link
Contributor

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.

goal: { coach_id: coach_id || DEFAULT_COACH_ID }
})

const REQUESTS = [
Copy link
Contributor

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 ))
Copy link
Contributor

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` })

@EthanJStark
Copy link
Collaborator Author

For your review!

All tests are passing, but can't run them unless you move frontend to root directory and uncomment require statements.

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 )
Copy link
Contributor

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?

Copy link
Collaborator Author

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 ) }))
Copy link
Contributor

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)

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 )} ))
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this notEscalatedByMe?

@@ -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 ) )
Copy link
Contributor

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...

Copy link
Collaborator Author

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?

@@ -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 ) )
Copy link
Contributor

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', () => {

Copy link
Contributor

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', () => {

Copy link
Contributor

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', () => {

Copy link
Contributor

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', () => {

Copy link
Contributor

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( {
Copy link
Contributor

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

@EthanJStark EthanJStark force-pushed the 240-refactor-prioritize branch 3 times, most recently from 354b80c to 83a3514 Compare April 14, 2017 21:27
@@ -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}">
Copy link
Contributor

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...

@@ -126,7 +99,7 @@ load()
const buttons = className => {
const elements = document.querySelectorAll( className )

if( elements !== null ) {
if ( elements !== null ) {
Copy link
Contributor

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.

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 )} ))
Copy link
Contributor

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 }
})
}

Copy link
Contributor

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,
Copy link
Contributor

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
@EthanJStark EthanJStark changed the title WIP refactor prioritize refactor prioritize Apr 14, 2017
@EthanJStark EthanJStark merged commit cdfc2c7 into GuildCrafts:master Apr 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants