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
Merged

Conversation

@EthanJStark
Copy link
Collaborator

EthanJStark commented Apr 14, 2017

No description provided.

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

jrob8577 left a comment

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

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

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 = [

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

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

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

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 EthanJStark force-pushed the 240-refactor-prioritize branch from 7ebe6e6 to d2bd79a Apr 14, 2017
@EthanJStark
Copy link
Collaborator Author

EthanJStark commented Apr 14, 2017

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 )

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

Can't active also mean escalated by me at some point?

This comment has been minimized.

Copy link
@EthanJStark

EthanJStark Apr 14, 2017

Author Collaborator

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

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

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

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

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

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

This was intentionally removed - refresh should happen on event publication...

This comment has been minimized.

Copy link
@EthanJStark

EthanJStark Apr 14, 2017

Author Collaborator

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

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

This was intentionally removed - refresh should happen on event publication...

describe( 'notEscalatedByMe', () => {

describe( 'when the request was escalated by me', () => {

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

Remove extraneous whitespace between describe and first it

})

describe( 'when the request was escalated by another coach', () => {

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

Remove extraneous whitespace between describe and first it

})

describe( 'when the request has not been escalated', () => {

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

Remove extraneous whitespace between describe and first it



describe( 'calculatePriority', () => {

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

Remove extraneous whitespace between describe and first describe


describe( 'comparing one older and one newer request', () => {

const newerRequest = Factory.request( {

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

Move test cases into it

@EthanJStark EthanJStark force-pushed the 240-refactor-prioritize branch 3 times, most recently from 354b80c to 83a3514 Apr 14, 2017
@@ -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}">

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

This should be created-at...

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

if( elements !== null ) {
if ( elements !== null ) {

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

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

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

Formatting is hard to understand. Close map ) should align with map

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

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

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,

This comment has been minimized.

Copy link
@jrob8577

jrob8577 Apr 14, 2017

Contributor

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 force-pushed the 240-refactor-prioritize branch from 83a3514 to 0927bf8 Apr 14, 2017
@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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.