-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[STRY0011998] Linelist Export: UI (#664)
* chore: Working on setting up dropdown * chore: Working dropdown for old data export * start adding linelist ui * Change sortable_list component to render single list for future flexibility * Add add all and remove all buttons to modal * add disabled submit, samples into collapse * Add disable to linelist export button, add linelist export btn to group samples * refactor sortable list component to use has_many, fix export description dialog to more universal * fix current broken tests * start adding data export ui tests * add test previews for sortable_lists component * add fr translations, cleanup * more cleanup * change styling of list elements in sortable lists * more styling changes to list component * fix styling for component preview * change format param to linelist_format in anticipation of other future format params * fix rubucop warning * Add enable and disable states for add and remove all buttons in dialog, fix sortable scrolling * fix rebase * cleanup * remove hover from list_component, remove forceFallback from controller * attempt to fix flaky test * fix other flaky tests * try using only tbody as selector for flaky tests * change selector in groups group links as well * fix tests in data-exports-tests * remove unnecessary unless conditional and fix disabled statement --------- Co-authored-by: Chris Huynh <[email protected]>
- Loading branch information
1 parent
b601bbb
commit 6d52583
Showing
33 changed files
with
1,005 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/components/viral/sortable_list/list_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div class="<%= @system_arguments[:container_classes] %>"> | ||
<%= title %> | ||
<ul | ||
id="<%= id %>" | ||
data-controller="sortable-list" | ||
data-sortable-list-group-name-value="<%= group %>" | ||
class="<%= @system_arguments[:list_classes] %>" | ||
> | ||
<% list_items.each do |list_item| %> | ||
<li | ||
id="<%= list_item %>" | ||
class=" | ||
block | ||
w-full | ||
px-4 | ||
py-2 | ||
border-b | ||
border-slate-200 | ||
cursor-move | ||
dark:border-slate-600"><%= list_item %></li> | ||
<% end %> | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Viral | ||
module SortableList | ||
# This component creates the individual lists for the sortable_lists_component. | ||
class ListComponent < Viral::Component | ||
attr_reader :id, :group, :title, :list_items | ||
|
||
# If creating multiple lists to utilize the same list values, assign them the same group | ||
def initialize(id: nil, group: nil, title: nil, list_items: [], **system_arguments) | ||
@id = id | ||
@group = group | ||
@title = title | ||
@list_items = list_items | ||
@system_arguments = system_arguments | ||
@system_arguments[:list_classes] = | ||
class_names(system_arguments[:list_classes], | ||
'border border-slate-300 rounded-md block | ||
dark:bg-slate-800 dark:border-slate-600 max-h-[225px] min-h-[225px]') | ||
@system_arguments[:container_classes] = | ||
class_names(system_arguments[:container_classes], 'text-slate-900 dark:text-white') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div> | ||
<div class="flex justify-between block text-sm font-medium text-slate-900 dark:text-white"> | ||
<%= title %> | ||
</div> | ||
<div class="text-sm font-medium text-base leading-relaxed text-slate-500 dark:text-slate-400"> | ||
<%= description %> | ||
</div> | ||
</div> | ||
<div class="flex"> | ||
<% lists.each do |list| %> | ||
<%= list %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Viral | ||
# This component creates the sortable_lists. | ||
class SortableListsComponent < Viral::Component | ||
attr_reader :title, :description | ||
|
||
renders_many :lists, Viral::SortableList::ListComponent | ||
|
||
def initialize(title: nil, description: nil) | ||
@title = title | ||
@description = description | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/javascript/controllers/data_exports/metadata_selection_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
import { createHiddenInput } from "utilities/form"; | ||
|
||
export default class extends Controller { | ||
|
||
static targets = ["field", "submitBtn", "addAll", "removeAll"]; | ||
|
||
static values = { | ||
selectedList: { | ||
type: String, | ||
}, | ||
availableList: { | ||
type: String, | ||
} | ||
}; | ||
|
||
#disabledClasses = ["pointer-events-none", "cursor-not-allowed", "text-slate-300", "dark:text-slate-700"]; | ||
#enabledClasses = ["underline", "hover:no-underline"] | ||
|
||
connect() { | ||
this.availableList = document.getElementById(this.availableListValue) | ||
this.selectedList = document.getElementById(this.selectedListValue) | ||
this.fullListItems = this.availableList.querySelectorAll("li") | ||
this.selectedList.addEventListener("mouseover", () => { this.#checkButtonStates() }) | ||
this.availableList.addEventListener("mouseover", () => { this.#checkButtonStates() }) | ||
} | ||
|
||
addAll() { | ||
for (const item of this.fullListItems) { | ||
this.selectedList.append(item) | ||
} | ||
this.#checkButtonStates() | ||
} | ||
|
||
removeAll() { | ||
for (const item of this.fullListItems) { | ||
this.availableList.append(item) | ||
} | ||
this.#checkButtonStates() | ||
} | ||
|
||
#checkButtonStates() { | ||
const selected_metadata = this.selectedList.querySelectorAll("li") | ||
const available_metadata = this.availableList.querySelectorAll("li") | ||
if (selected_metadata.length == 0) { | ||
this.#setSubmitButtonDisableState(true) | ||
this.#setAddOrRemoveButtonDisableState(this.removeAllTarget, true) | ||
this.#setAddOrRemoveButtonDisableState(this.addAllTarget, false) | ||
} else if (available_metadata.length == 0) { | ||
this.#setSubmitButtonDisableState(false) | ||
this.#setAddOrRemoveButtonDisableState(this.removeAllTarget, false) | ||
this.#setAddOrRemoveButtonDisableState(this.addAllTarget, true) | ||
} else { | ||
this.#setSubmitButtonDisableState(false) | ||
this.#setAddOrRemoveButtonDisableState(this.removeAllTarget, false) | ||
this.#setAddOrRemoveButtonDisableState(this.addAllTarget, false) | ||
} | ||
} | ||
|
||
#setSubmitButtonDisableState(disableState) { | ||
this.submitBtnTarget.disabled = !(!disableState && this.selectedList.querySelectorAll("li").length > 0); | ||
} | ||
|
||
#setAddOrRemoveButtonDisableState(button, disableState) { | ||
if (disableState && !button.classList.contains("pointer-events-none")) { | ||
button.classList.remove(...this.#enabledClasses) | ||
button.classList.add(...this.#disabledClasses) | ||
button.setAttribute("aria-disabled", "true") | ||
} else if (!disableState && button.classList.contains("pointer-events-none")) { | ||
button.classList.remove(...this.#disabledClasses) | ||
button.classList.add(...this.#enabledClasses) | ||
button.removeAttribute("aria-disabled") | ||
} | ||
} | ||
|
||
constructMetadataParams() { | ||
const metadata_fields = this.selectedList.querySelectorAll("li") | ||
|
||
for (const metadata_field of metadata_fields) { | ||
this.fieldTarget.appendChild( | ||
createHiddenInput( | ||
`data_export[export_parameters][metadata_fields][]`, | ||
metadata_field.innerText | ||
) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import { Sortable } from "sortablejs"; | ||
|
||
export default class extends Controller { | ||
static values = { | ||
groupName: String, | ||
scrollSensitivity: { | ||
type: Number, | ||
default: 50, | ||
}, | ||
scrollSpeed: { | ||
type: Number, | ||
default: 8, | ||
} | ||
} | ||
connect() { | ||
this.sortable = new Sortable(this.element, { | ||
scroll: true, | ||
scrollSensitivity: this.scrollSensitivityValue, // The number of px from div edge where scroll begins | ||
scrollSpeed: this.scrollSpeedValue, | ||
bubbleScroll: true, | ||
group: this.groupNameValue, | ||
animation: 100 | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.