Skip to content

Commit

Permalink
Merge pull request #43 from DigitalNZ/rm/workflow-enhancements-1
Browse files Browse the repository at this point in the history
SJ WORKFLOW ENHANCEMENTS. As an open-source user, I don't want to get caught out by dead ends while creating my pipeline so that I have a smooth productive journey.
  • Loading branch information
richardmatthewsdev authored Oct 18, 2023
2 parents 03f4627 + 50cff32 commit 4a0bded
Show file tree
Hide file tree
Showing 69 changed files with 1,739 additions and 1,236 deletions.
1 change: 1 addition & 0 deletions app/controllers/concerns/extraction_redux_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def ui_parameter_entity(parameter)
saved: true,
saving: false,
deleting: false,
active: false,
displayed: parameter.request == @extraction_definition.requests.first
}
end
Expand Down
34 changes: 19 additions & 15 deletions app/controllers/extraction_definitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ class ExtractionDefinitionsController < ApplicationController

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

def show
@parameters = @extraction_definition.parameters.order(created_at: :desc)
@props = extraction_app_state
end
def show; end

def new
@extraction_definition = ExtractionDefinition.new(kind: params[:kind])
Expand All @@ -30,16 +28,21 @@ def create
redirect_to create_redirect_path, notice: t('.success')
else
flash.alert = t('.failure')
render :new

redirect_to pipeline_path(@pipeline)
end
end

def update
if @extraction_definition.update(extraction_definition_params)
redirect_to update_redirect_path, notice: t('.success')
update_last_edited_by([@extraction_definition])

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

render :show
end
end

Expand Down Expand Up @@ -83,20 +86,21 @@ def clone

private

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
)
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
)
pipeline_harvest_definition_extraction_definition_path(@pipeline, @harvest_definition, @extraction_definition)
end

def successful_clone_path(clone)
Expand Down
52 changes: 43 additions & 9 deletions app/controllers/extraction_jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ def show
end

def create
respond_to do |format|
format.html { html_create }
format.json { json_create }
end
end

def destroy
if @extraction_job.destroy
flash.notice = t('.success')
redirect_to pipeline_pipeline_jobs_path(@pipeline)
else
flash.alert = t('.failure')
redirect_to pipeline_harvest_definition_extraction_definition_extraction_job_path(
@pipeline, @harvest_definition, @extraction_definition, @extraction_job
)
end
end

private

def html_create
@extraction_job = ExtractionJob.new(extraction_definition: @extraction_definition, kind: params[:kind])

if @extraction_job.save
Expand All @@ -29,19 +50,32 @@ def create
@extraction_definition)
end

def destroy
if @extraction_job.destroy
flash.notice = t('.success')
redirect_to pipeline_pipeline_jobs_path(@pipeline)
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)
}
end

def create_or_update_transformation_definition
if @harvest_definition.transformation_definition.present?
@harvest_definition.transformation_definition.update(extraction_job_id: @extraction_job.id)
else
flash.alert = t('.failure')
redirect_to pipeline_harvest_definition_extraction_definition_extraction_job_path(
@pipeline, @harvest_definition, @extraction_definition, @extraction_job
transformation_definition = TransformationDefinition.create(
extraction_job_id: @extraction_job.id,
pipeline_id: @pipeline.id
)

@harvest_definition.update(transformation_definition_id: transformation_definition.id)
end
end

private
@harvest_definition.transformation_definition
end

def find_pipeline
@pipeline = Pipeline.find(params[:pipeline_id])
Expand Down
37 changes: 20 additions & 17 deletions app/controllers/pipelines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,15 @@
class PipelinesController < ApplicationController
include LastEditedBy

before_action :find_pipeline, only: %w[show destroy edit update clone]
before_action :find_pipeline, only: %w[show destroy update clone]
before_action :assign_show_variables, only: %w[show update]

def index
@pipelines = pipelines
@pipeline = Pipeline.new
end

def show
@harvest_definition = @pipeline.harvest || HarvestDefinition.new(pipeline: @pipeline)
@pipeline_job = PipelineJob.new

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

if @harvest_definition&.extraction_definition.present?
@extraction_jobs = @harvest_definition.extraction_definition.extraction_jobs.completed.order(created_at: :desc)
end

@destinations = Destination.all
end

def edit; end
def show; end

def create
@pipeline = Pipeline.new(pipeline_params)
Expand All @@ -39,10 +27,10 @@ def create

def update
if @pipeline.update(pipeline_params)
redirect_to pipeline_path(@pipeline), notice: t('.success')
redirect_to pipeline_path(@pipeline)
else
flash.alert = t('.failure')
render :edit
render :show
end
end

Expand Down Expand Up @@ -73,6 +61,21 @@ def clone

private

def assign_show_variables
@harvest_definition = @pipeline.harvest || HarvestDefinition.new(pipeline: @pipeline)
@pipeline_job = PipelineJob.new

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

if @harvest_definition&.extraction_definition.present?
@extraction_jobs = @harvest_definition.extraction_definition.extraction_jobs.completed.order(created_at: :desc)
end

@completed_harvest_jobs = HarvestJob.where(harvest_definition_id: @harvest_definition.id).completed

@destinations = Destination.all
end

def find_pipeline
@pipeline = Pipeline.find(params[:id])
end
Expand Down
27 changes: 13 additions & 14 deletions app/controllers/transformation_definitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@ class TransformationDefinitionsController < ApplicationController

before_action :find_pipeline
before_action :find_harvest_definition
before_action :find_transformation_definition, only: %w[show edit update destroy clone]
before_action :find_extraction_jobs, only: %w[new create edit update]
before_action :find_transformation_definition, only: %i[show update destroy clone]
before_action :find_extraction_jobs, only: %i[create update]
before_action :assign_show_variables, only: %i[show update]

def show
@fields = @transformation_definition.fields.order(created_at: :desc).map(&:to_h)
@props = transformation_app_state
end

def new
@transformation_definition = TransformationDefinition.new(kind: params[:kind])
end

def edit; end
def show; end

def create
@transformation_definition = TransformationDefinition.new(transformation_definition_params)
Expand All @@ -31,7 +23,7 @@ def create
else
flash.alert = t('.failure')

render :new
redirect_to pipeline_path(@pipeline)
end
end

Expand All @@ -42,7 +34,8 @@ def update
), notice: t('.success')
else
flash.alert = t('.failure')
render 'edit'

render :show
end
end

Expand Down Expand Up @@ -81,6 +74,12 @@ def clone

private

def assign_show_variables
@fields = @transformation_definition.fields.order(created_at: :desc).map(&:to_h)
@props = transformation_app_state
@extraction_jobs = @harvest_definition.extraction_definition.extraction_jobs.completed.order(created_at: :desc)
end

def find_pipeline
@pipeline = Pipeline.find(params[:pipeline_id])
end
Expand Down
4 changes: 3 additions & 1 deletion app/frontend/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ import "/js/TestEnrichmentExtraction";
import "/js/TestTransformationRecordSelector";
import "/js/TestDestination";
import "/js/Tooltips";
import "/js/Toasts";
import "/js/CollapseScroll";
import "/js/formModals";
import "/js/SubmittingSelect";
import "/js/CreateModal";
import "/js/AutoComplete";

import "/js/editor";
import "/js/form-header-submission";
import "/js/pipeline";
import "/js/schedules";
import "/js/inlineEditable";

import "/js/react";
3 changes: 3 additions & 0 deletions app/frontend/entrypoints/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
@import "../stylesheets/bootstrap/card";
@import "../stylesheets/bootstrap/modal";
@import "../stylesheets/bootstrap/accordion";
@import "../stylesheets/bootstrap/alert";
@import "../stylesheets/bootstrap/btn";

// Library overrides
@import "../stylesheets/autocomplete/autocomplete";
Expand All @@ -36,3 +38,4 @@
@import "../stylesheets/blocks/record-view";
@import "../stylesheets/blocks/search";
@import "../stylesheets/blocks/table";
@import "../stylesheets/blocks/inline-editable-element";
14 changes: 0 additions & 14 deletions app/frontend/js/CreateModal.js

This file was deleted.

4 changes: 4 additions & 0 deletions app/frontend/js/Toasts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Toast } from "bootstrap";

const toastElList = document.querySelectorAll(".toast");
const toastList = [...toastElList].map((toastEl) => new Toast(toastEl).show());
32 changes: 23 additions & 9 deletions app/frontend/js/apps/ExtractionApp/components/AddParameter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "~/js/features/ExtractionApp/ParametersSlice";
import { selectAppDetails } from "~/js/features/ExtractionApp/AppDetailsSlice";
import { selectUiAppDetails } from "~/js/features/ExtractionApp/UiAppDetailsSlice";
import Tooltip from "~/js/components/Tooltip";

const AddParameter = ({ kind, buttonText }) => {
const dispatch = useDispatch();
Expand All @@ -28,15 +29,28 @@ const AddParameter = ({ kind, buttonText }) => {
};

return (
<div className="d-grid gap-2">
<button
disabled={emptyParameters}
className="btn btn-outline-primary"
onClick={() => addNewParameter()}
>
{buttonText}
</button>
</div>
<>
{emptyParameters && (
<Tooltip data-bs-title="Please save incomplete parameters before adding another">
<div className="d-grid gap-2">
<button disabled="true" className="btn btn-outline-primary">
{buttonText}
</button>
</div>
</Tooltip>
)}

{!emptyParameters && (
<div className="d-grid gap-2">
<button
className="btn btn-outline-primary"
onClick={() => addNewParameter()}
>
{buttonText}
</button>
</div>
)}
</>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ const HeaderActions = () => {

return createPortal(
<>
<button className="btn btn-success" onClick={handlePreviewClick}>
<button className="btn btn-success me-2" onClick={handlePreviewClick}>
<i className="bi bi-play" aria-hidden="true"></i> Preview
</button>

<PreviewModal
showModal={showModal}
handleClose={handleClose}
Expand Down
4 changes: 2 additions & 2 deletions app/frontend/js/apps/ExtractionApp/components/NavTabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const NavTabs = () => {

const pageOneTabText = () => {
if (appDetails.extractionDefinition.paginated) {
return "Initial Request";
return "First Request";
}

return "Request";
Expand Down Expand Up @@ -95,7 +95,7 @@ const NavTabs = () => {
}}
>
<button className={mainRequestClasses} type="button" role="tab">
Main Request
Following Requests
</button>
</li>
);
Expand Down
Loading

0 comments on commit 4a0bded

Please sign in to comment.