   getWorkflow: (project, workflowID) ->
     # console.log 'Getting workflow', workflowID
     # We could just get the workflow directly, but this way we ensure the workflow belongs to the project.
-    project.get('workflows').then (workflows) ->
-      workflow = (workflow for workflow in workflows when workflow.id is workflowID)[0]
+    project.get('workflows', id: workflowID).then ([workflow]) ->
       unless workflow?
         throw new Error "No workflow #{workflowID} for project #{project.id}"
       workflow

    query: 'loadAppropriateClassification'

  componentDidMount: () ->
    @getCurrentWorkflowID().then (id) =>
      @getWorkflow @props.project, id
        .then (workflow) =>
          @setState
            workflow: workflow

  loadAppropriateClassification: (_, props = @props) ->
    # To load the right classification, we'll need to know which workflow the user expects.
    # console.log 'Loading appropriate classification'
    @promiseToSetState classification: @getCurrentWorkflowID(props).then (workflowID) =>
      # console.log 'Loading classification for workflow', workflowID
      # Create a classification if it doesn't exist for the chosen workflow, then resolve our state with it.
      currentClassifications.forWorkflow[workflowID] ?= @createNewClassification props.project, workflowID
      currentClassifications.forWorkflow[workflowID]

  getCurrentWorkflowID: (props = @props) ->
    getWorkflowID = if props.location.query?.workflow?
      # console.log 'Workflow specified as', props.query.workflow
      # Prefer the workflow specified in the query.
      Promise.resolve props.location.query.workflow
    else
      # If no workflow is specified, pick a random one and record it for later.
      # When we send this classification, we'll clear this value to select a new random workflow.
      currentWorkflowForProject[props.project.id] ?= @getRandomWorkflowID props.project
      currentWorkflowForProject[props.project.id]

  getRandomWorkflowID: (project) ->
    project.get('workflows', active: true).then (workflows) =>
      if workflows.length is 0
        throw new Error "No workflows for project #{project.id}"

        </SignInPrompt>

  loadAnotherSubject: ->
    @getCurrentWorkflow(@props).then (workflow) =>
      # Forget the old classification so a new one will load.
      currentClassifications.forWorkflow[workflow.id] = null
      # Forget the old workflow, unless it was specified, so we'll get a random one next time.
      unless @props.location.query?.workflow?
        currentWorkflowForProject[@props.project.id] = null
