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

Add Upload Button to Ingestions #1403

Merged
merged 5 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/andi/assets/css/ingestions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

.ingestion-metadata-form {
margin-bottom: 1rem;
margin-top: 1rem;
}

.selected-results-from-search.selected-dataset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule AndiWeb.Helpers.MetadataFormHelpers do
end

def get_source_format_options(_), do: Options.source_format()
def get_source_format_options(), do: Options.source_format()

def get_language(nil), do: "english"
def get_language(lang), do: lang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ defmodule AndiWeb.IngestionLiveView.DataDictionaryForm do
"expanded" -> "MINIMIZE"
end

loader_visibility =
case assigns.loading_schema do
true -> "loading"
false -> "hidden"
end

~L"""
<div id="data-dictionary-form" class="form-component">
<div class="component-header" phx-click="toggle-component-visibility" phx-value-component="data_dictionary_form">
Expand All @@ -73,10 +79,27 @@ defmodule AndiWeb.IngestionLiveView.DataDictionaryForm do

<div class="component-edit-section--<%= @visibility %>">

<%= ErrorHelpers.error_tag(f, :schema, bind_to_input: false, class: "full-width") %>

<div class="data-dictionary-form-edit-section form-grid">

<div class="upload-section">
<%= if @sourceFormat in ["text/csv", "application/json"] and @is_curator do %>
<div class="data-dictionary-form__file-upload">
<div class="file-input-button--<%= loader_visibility %>">
<div class="file-input-button">
<%= label(f, :schema_sample, "Upload data sample", class: "label") %>
<%= file_input(f, :schema_sample, phx_hook: "readFile", accept: "text/csv, application/json") %>
<%= ErrorHelpers.error_tag(f, :schema_sample, bind_to_input: false) %>
</div>
</div>

<button type="button" id="reader-cancel" class="file-upload-cancel-button file-upload-cancel-button--<%= loader_visibility %> btn">Cancel</button>
<div class="loader data-dictionary-form__loader data-dictionary-form__loader--<%= loader_visibility %>"></div>
</div>
<% end %>

<%= ErrorHelpers.error_tag(f, :schema, bind_to_input: false, class: "full-width") %>
</div>

<div class="data-dictionary-form__tree-section">
<div class="data-dictionary-form__tree-header data-dictionary-form-tree-header">
<div class="label">Enter/Edit Fields</div>
Expand Down Expand Up @@ -105,6 +128,7 @@ defmodule AndiWeb.IngestionLiveView.DataDictionaryForm do

<%= live_component(@socket, AndiWeb.DataDictionary.RemoveFieldEditor, id: :data_dictionary_remove_field_editor, selected_field: @current_data_dictionary_item, visible: @remove_data_dictionary_field_visible) %>

<%= live_component(@socket, AndiWeb.DataDictionary.OverwriteSchemaModal, id: :overwrite_schema_modal, visibility: @overwrite_schema_visibility) %>
</div>
"""
end
Expand Down Expand Up @@ -496,9 +520,4 @@ defmodule AndiWeb.IngestionLiveView.DataDictionaryForm do
_ -> {:noreply, assign(socket, changeset: new_changeset, loading_schema: false)}
end
end

defp send_data_dictionary_status(changeset, socket) do
send(socket.parent_pid, {:update_data_dictionary_status, changeset.valid?})
changeset
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,30 @@ defmodule AndiWeb.IngestionLiveView.EditIngestionLiveView do
~L"""
<%= header_render(@socket, @is_curator) %>
<div class="edit-page" id="ingestions-edit-page">
<div class="edit-ingestion-title">
<h2 class="component-title-text">Define Data Ingestion</h2>
</div>

<div>
<%= live_render(@socket, AndiWeb.IngestionLiveView.MetadataForm, id: :ingestion_metadata_form_editor, session: %{"ingestion" => @ingestion}) %>
</div>

<div>
<div class="extract-steps-form-component">
<%= live_render(@socket, AndiWeb.IngestionLiveView.ExtractSteps.ExtractStepForm, id: :extract_step_form_editor, session: %{"ingestion" => @ingestion, "order" => "1"}) %>
<%= f = form_for @changeset, "" %>
<%= hidden_input(f, :sourceFormat) %>
<div class="edit-ingestion-title">
<h2 class="component-title-text">Define Data Ingestion</h2>
</div>

<div class="data-dictionary-form-component">
<%= live_render(@socket, AndiWeb.IngestionLiveView.DataDictionaryForm, id: :data_dictionary_form_editor, session: %{"ingestion" => @ingestion, "is_curator" => @is_curator, "order" => "2"}) %>
<div>
<%= live_render(@socket, AndiWeb.IngestionLiveView.MetadataForm, id: :ingestion_metadata_form_editor, session: %{"ingestion" => @ingestion}) %>
</div>

<div class="finalize-form-component ">
<%= live_render(@socket, AndiWeb.IngestionLiveView.FinalizeForm, id: :finalize_form_editor, session: %{"ingestion" => @ingestion, "order" => "4"}) %>
<div>
<div class="extract-steps-form-component">
<%= live_render(@socket, AndiWeb.IngestionLiveView.ExtractSteps.ExtractStepForm, id: :extract_step_form_editor, session: %{"ingestion" => @ingestion, "order" => "1"}) %>
</div>

<div class="data-dictionary-form-component">
<%= live_render(@socket, AndiWeb.IngestionLiveView.DataDictionaryForm, id: :data_dictionary_form_editor, session: %{"ingestion" => @ingestion, "is_curator" => @is_curator, "order" => "2"}) %>
</div>

<div class="finalize-form-component ">
<%= live_render(@socket, AndiWeb.IngestionLiveView.FinalizeForm, id: :finalize_form_editor, session: %{"ingestion" => @ingestion, "order" => "4"}) %>
</div>
</div>
</div>
</form>

<div class="edit-page__btn-group">
<div class="btn-group__standard">
Expand Down
17 changes: 15 additions & 2 deletions apps/andi/lib/andi_web/live/ingestion_live_view/metadata_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ defmodule AndiWeb.IngestionLiveView.MetadataForm do
def mount(_, %{"ingestion" => ingestion}, socket) do
changeset = IngestionMetadataFormSchema.changeset_from_andi_ingestion(ingestion)
AndiWeb.Endpoint.subscribe("form-save")
AndiWeb.Endpoint.subscribe("source-format")

{:ok,
assign(socket,
changeset: changeset,
select_dataset_modal_visibility: "hidden",
search_results: [],
search_text: "",
selected_dataset: ingestion.targetDataset
selected_dataset: ingestion.targetDataset,
ingestion_id: ingestion.id
)}
end

Expand All @@ -34,7 +36,7 @@ defmodule AndiWeb.IngestionLiveView.MetadataForm do
</div>
<div class="ingestion-metadata-form ingestion-metadata-form__format">
<%= label(f, :sourceFormat, "Source Format", class: "label label--required") %>
<%= select(f, :sourceFormat, MetadataFormHelpers.get_source_format_options(input_value(f, :sourceFormat)), [class: "select ingestion-form-fields"]) %>
<%= select(f, :sourceFormat, MetadataFormHelpers.get_source_format_options(), [class: "select ingestion-form-fields"]) %>
<%= ErrorHelpers.error_tag(f, :sourceFormat, bind_to_input: false) %>
</div>
<div class="ingestion-metadata-form ingestion-metadata-form__target-dataset">
Expand Down Expand Up @@ -78,6 +80,17 @@ defmodule AndiWeb.IngestionLiveView.MetadataForm do
{:noreply, assign(socket, selected_dataset: nil)}
end

def handle_event("validate", %{"form_data" => form_data, "_target" => ["form_data", "sourceFormat"]}, socket) do
AndiWeb.Endpoint.broadcast_from(self(), "source-format", "format-update", %{
new_format: form_data["sourceFormat"],
ingestion_id: socket.assigns.ingestion_id
})

form_data
|> IngestionMetadataFormSchema.changeset_from_form_data()
|> complete_validation(socket)
end

def handle_event("validate", %{"form_data" => form_data}, socket) do
form_data
|> IngestionMetadataFormSchema.changeset_from_form_data()
Expand Down
2 changes: 1 addition & 1 deletion apps/andi/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Andi.MixProject do
def project do
[
app: :andi,
version: "2.2.8",
version: "2.2.9",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down
Loading