Skip to content

Commit

Permalink
Merge pull request #45 from DigitalNZ/rm/improve-enrichment-interface
Browse files Browse the repository at this point in the history
IMPROVE ENRICHMENT EXTRACTION INTERFACE: As Dan, I want the Enrichment Extraction interface updated, so that the workflow is intuitive and I can better customise my extraction
  • Loading branch information
richardmatthewsdev authored Oct 24, 2023
2 parents 4a0bded + 19fbbc5 commit bd2c1b0
Show file tree
Hide file tree
Showing 57 changed files with 904 additions and 656 deletions.
8 changes: 7 additions & 1 deletion app/controllers/concerns/extraction_redux_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def extraction_app_details_slice

def ui_extraction_app_details_slice
{
activeRequest: @extraction_definition.requests.first.id,
activeRequest: active_request_id,
sharedDefinitionsTabActive: false
}
end
Expand Down Expand Up @@ -107,4 +107,10 @@ def ui_request_entity(request)
loading: false
}
end

def active_request_id
return @extraction_definition.requests.first.id if @extraction_definition.harvest?

@extraction_definition.requests.last.id
end
end
3 changes: 2 additions & 1 deletion app/controllers/concerns/transformation_redux_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def ui_field_entity(field)
deleting: false,
running: false,
hasRun: false,
displayed: false
displayed: false,
active: false
}
end

Expand Down
46 changes: 7 additions & 39 deletions app/controllers/extraction_definitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@ class ExtractionDefinitionsController < ApplicationController

before_action :find_pipeline
before_action :find_harvest_definition
before_action :find_extraction_definition, only: %i[show update clone destroy edit]
before_action :find_destinations, only: %i[create update new edit]
before_action :find_extraction_definition, only: %i[show update clone destroy]
before_action :find_destinations, only: %i[create update]
before_action :assign_show_variables, only: %i[show update]

def show; end

def new
@extraction_definition = ExtractionDefinition.new(kind: params[:kind])
end

def edit; end

def create
@extraction_definition = ExtractionDefinition.new(extraction_definition_params)

Expand All @@ -25,11 +19,11 @@ def create

2.times { Request.create(extraction_definition: @extraction_definition) }

redirect_to create_redirect_path, notice: t('.success')
redirect_to pipeline_harvest_definition_extraction_definition_path(
@pipeline, @harvest_definition, @extraction_definition
), notice: t('.success')
else
flash.alert = t('.failure')

redirect_to pipeline_path(@pipeline)
redirect_to pipeline_path(@pipeline), alert: t('.failure')
end
end

Expand All @@ -46,21 +40,6 @@ def update
end
end

def test_record_extraction
@extraction_definition = ExtractionDefinition.new(extraction_definition_params)

render json: Extraction::RecordExtraction.new(@extraction_definition, 1).extract
end

def test_enrichment_extraction
@extraction_definition = ExtractionDefinition.new(extraction_definition_params)

api_records = Extraction::RecordExtraction.new(@extraction_definition, 1).extract
records = JSON.parse(api_records.body)['records']

render json: Extraction::EnrichmentExtraction.new(@extraction_definition, records.first, 1).extract
end

def destroy
if @extraction_definition.destroy
redirect_to pipeline_path(@pipeline), notice: t('.success')
Expand Down Expand Up @@ -89,18 +68,7 @@ def clone
def assign_show_variables
@parameters = @extraction_definition.parameters.order(created_at: :desc)
@props = extraction_app_state
end

def create_redirect_path
return pipeline_path(@pipeline) unless @extraction_definition.harvest?

pipeline_harvest_definition_extraction_definition_path(@pipeline, @harvest_definition, @extraction_definition)
end

def update_redirect_path
return pipeline_path(@pipeline) unless @extraction_definition.harvest?

pipeline_harvest_definition_extraction_definition_path(@pipeline, @harvest_definition, @extraction_definition)
@destinations = Destination.all
end

def successful_clone_path(clone)
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/extraction_jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def json_create
@extraction_job = ExtractionJob.create(extraction_definition: @extraction_definition, kind: params[:kind])
ExtractionWorker.perform_async(@extraction_job.id)

return render json: { location: pipeline_path(@pipeline) } unless params[:type] == 'transform'

render json: {
location: pipeline_harvest_definition_transformation_definition_path(@pipeline, @harvest_definition,
create_or_update_transformation_definition)
Expand All @@ -68,7 +66,7 @@ def create_or_update_transformation_definition
else
transformation_definition = TransformationDefinition.create(
extraction_job_id: @extraction_job.id,
pipeline_id: @pipeline.id
pipeline_id: @pipeline.id, kind: @extraction_definition.kind
)

@harvest_definition.update(transformation_definition_id: transformation_definition.id)
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/harvest_definitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def create
else
flash.alert = t('.failure', kind: harvest_kind)

@enrichment_definition = HarvestDefinition.new(pipeline: @pipeline)

render 'pipelines/show'
redirect_to pipeline_path(@pipeline)
end
end

Expand Down
66 changes: 58 additions & 8 deletions app/controllers/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
class RequestsController < ApplicationController
include LastEditedBy

before_action :find_extraction_definition, only: %w[show]

def show
@request = Request.find(params[:id])

if params[:previous_request_id].present?
@previous_request = Request.find(params[:previous_request_id])

@previous_response = Extraction::DocumentExtraction.new(@previous_request).extract
end
return harvest_request if @request.extraction_definition.harvest?

render json: @request.to_h.merge(
preview: Extraction::DocumentExtraction.new(@request, nil, @previous_response).extract
)
enrichment_request
end

def update
Expand All @@ -30,6 +26,60 @@ def update

private

def find_extraction_definition
@extraction_definition = ExtractionDefinition.find(params[:extraction_definition_id])
end

def harvest_request
if params[:previous_request_id].present?
@previous_request = @extraction_definition.requests.find(params[:previous_request_id])

@previous_response = Extraction::DocumentExtraction.new(@previous_request).extract
end

render json: @request.to_h.merge(
preview: Extraction::DocumentExtraction.new(@request, nil, @previous_response).extract
)
end

def enrichment_request
parsed_body = JSON.parse(api_response.body)

if @request.first_request?
render json: first_enrichment_request_response(parsed_body)
else
render json: second_enrichment_request_response
end
end

def page_param
params[:page] || 1
end

def record_param
params[:record] || 1
end

def api_response
Extraction::RecordExtraction.new(@request, page_param).extract
end

def api_record
Extraction::ApiResponse.new(api_response).record(record_param.to_i - 1)
end

def first_enrichment_request_response(parsed_body)
@request.to_h.merge(preview: {
**api_record.to_hash,
**parsed_body['meta'],
total_records: parsed_body['records'].count
})
end

def second_enrichment_request_response
@request.to_h.merge(preview: Extraction::EnrichmentExtraction.new(@request, api_record).extract)
end

def request_params
params.require(:request).permit(:http_method)
end
Expand Down
3 changes: 0 additions & 3 deletions app/frontend/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ console.log(

import * as bootstrap from "bootstrap";
import "/js/ClearField";
import "/js/TestRecordExtraction";
import "/js/TestEnrichmentExtraction";
import "/js/TestTransformationRecordSelector";
import "/js/TestDestination";
import "/js/Tooltips";
import "/js/Toasts";
Expand Down
32 changes: 0 additions & 32 deletions app/frontend/js/TestEnrichmentExtraction.js

This file was deleted.

30 changes: 0 additions & 30 deletions app/frontend/js/TestRecordExtraction.js

This file was deleted.

23 changes: 0 additions & 23 deletions app/frontend/js/TestTransformationRecordSelector.js

This file was deleted.

Loading

0 comments on commit bd2c1b0

Please sign in to comment.