-
Notifications
You must be signed in to change notification settings - Fork 91
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
ETQ administrateur, je peux deplacer un champ via un select #9861
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4073804
feat(administrateurs/types_de_champ_controller#move_and_morph): add a…
11de4bd
feat(types_de_champ_editor.ts): wires move_and_morph with type de cha…
dce06f2
feat(type_de_champ_editor): add SelectChampTemplatePosition which fee…
b4d32e6
feat(ChampComponent): add procedure_revision_type_de_champ.position t…
857a1fc
fix(select_champ_position): rewire for more robust and easier impleme…
e7eee7b
spec(move_and_morph): add some spec and lint with rubocop/haml/eslint
69346ad
tech(review): implement some pair review suggestions
68e9d35
tech(clean): drop drag and drop champs in editor, ux not ok
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
7 changes: 5 additions & 2 deletions
7
app/components/types_de_champ_editor/block_component/block_component.html.haml
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
%ul.types-de-champ-block{ id: block_id, data: sortable_options } | ||
- c = TypesDeChampEditor::SelectChampTemplatePositionComponent.new(block: @block, coordinates: @coordinates) | ||
%ul.types-de-champ-block{ id: block_id, data: { controller: 'select-champ-position-template', 'select-champ-position-template-template-id-value': c.block_id } } | ||
- @coordinates.each do |coordinate| | ||
= render TypesDeChampEditor::ChampComponent.new(coordinate: coordinate, upper_coordinates: coordinate.upper_coordinates) | ||
= render TypesDeChampEditor::ChampComponent.new(coordinate:, upper_coordinates: coordinate.upper_coordinates) | ||
%li.hidden= render c | ||
|
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
14 changes: 14 additions & 0 deletions
14
app/components/types_de_champ_editor/select_champ_position_component.rb
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,14 @@ | ||
class TypesDeChampEditor::SelectChampPositionComponent < ApplicationComponent | ||
def initialize(revision:, coordinate:) | ||
@revision = revision | ||
@coordinate = coordinate | ||
end | ||
|
||
def options | ||
[["Selectionner une option", @coordinate.stable_id]] | ||
end | ||
|
||
def describedby_id | ||
dom_id(@coordinate, :move_and_morph) | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
...de_champ_editor/select_champ_position_component/select_champ_position_component.html.haml
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,3 @@ | ||
= form_with(url: move_and_morph_admin_procedure_type_de_champ_path(@coordinate.revision.procedure, @coordinate.type_de_champ.stable_id), class: 'fr-ml-3w flex', method: :patch, data: { turbo: true }) do |f| | ||
= label_tag :target_stable_id, "Déplacer ce champ à la place de ", for: describedby_id, class: 'flex align-center flex-no-shrink fr-mr-3w' | ||
= select_tag :target_stable_id, options_for_select(options), id: describedby_id, class: 'fr-select', aria: { discribedby: describedby_id }, data: { 'select-champ-position-template-target': 'select', selected: @coordinate.stable_id } |
10 changes: 10 additions & 0 deletions
10
app/components/types_de_champ_editor/select_champ_template_position_component.rb
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,10 @@ | ||
class TypesDeChampEditor::SelectChampTemplatePositionComponent < ApplicationComponent | ||
def initialize(block:, coordinates:) | ||
@block = block | ||
@coordinates = coordinates | ||
end | ||
|
||
def block_id | ||
dom_id(@block, :types_de_champ_editor_select_champ_template) | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
...lect_champ_template_position_component/select_champ_template_position_component.html.haml
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,4 @@ | ||
%div{ id: block_id, data: { 'select-champ-position-template-target': 'template', turbo_force: :server } } | ||
%select | ||
- @coordinates.each do |coordinate| | ||
%option{ value: coordinate.stable_id }= "#{coordinate.position} #{coordinate.libelle}" |
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
71 changes: 71 additions & 0 deletions
71
app/javascript/controllers/select_champ_position_template_controller.ts
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,71 @@ | ||
import { ApplicationController } from './application_controller'; | ||
|
||
export class SelectChampPositionTemplateController extends ApplicationController { | ||
static targets = ['select', 'template']; | ||
static values = { | ||
templateId: String | ||
}; | ||
// this element is updated via turbostream as the source of truth for all select | ||
declare readonly templateIdValue: string; | ||
declare readonly selectTargets: HTMLSelectElement[]; | ||
|
||
selectTargetConnected(selectElement: HTMLSelectElement) { | ||
selectElement.addEventListener('focus', this); | ||
selectElement.addEventListener('change', this); | ||
} | ||
|
||
selectTargetDisconnected(selectElement: HTMLSelectElement) { | ||
selectElement.removeEventListener('focus', this); | ||
selectElement.removeEventListener('change', this); | ||
} | ||
|
||
handleEvent(event: Event) { | ||
switch (event.type) { | ||
case 'focus': | ||
this.onFocus(event); | ||
break; | ||
case 'change': | ||
this.onChange(event); | ||
break; | ||
} | ||
} | ||
|
||
private onFocus(event: Event): void { | ||
mfo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const focusedSelect = event.target as HTMLSelectElement; | ||
const focusedSelectStableId = this.getStableIdForSelect(focusedSelect); | ||
const template = this.element.querySelector<HTMLElement>( | ||
`#${this.templateIdValue}` | ||
); | ||
|
||
if (template) { | ||
const fragment = template.cloneNode(true) as HTMLSelectElement; | ||
|
||
const options = Array.from(fragment.querySelectorAll('option')) | ||
.map((option) => { | ||
if (option.value == focusedSelectStableId) { | ||
option.setAttribute('selected', 'selected'); | ||
option.setAttribute('disabled', 'disabled'); | ||
} | ||
|
||
return option.outerHTML; | ||
}) | ||
.join(''); | ||
focusedSelect.innerHTML = options; | ||
} | ||
} | ||
|
||
private onChange(event: Event): void { | ||
const changedSelectTarget = event.target as HTMLSelectElement; | ||
const stableIdDidChange = | ||
changedSelectTarget.value != | ||
this.getStableIdForSelect(changedSelectTarget); | ||
if (stableIdDidChange) { | ||
changedSelectTarget.form?.requestSubmit(); | ||
} | ||
event.stopImmediatePropagation(); | ||
} | ||
|
||
private getStableIdForSelect(select: HTMLSelectElement): string | null { | ||
return select.getAttribute('data-selected'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
2 changes: 2 additions & 0 deletions
2
app/views/administrateurs/types_de_champ/move_and_morph.turbo_stream.haml
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,2 @@ | ||
= render partial: 'insert' | ||
|
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Est-ce qu'on garde ce wording ou on met plutot "Déplacer ce champ après" car la on dirait qu'on le remplace et ça amène un peu de confusion je trouve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah oui ça m'avait échappé dans le refacto, je suis d'accord
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deplacé apres ne marche pas dans le sens bas vers le haut. c'est bien deplacer ce champ à la place de (a l'inverse du feedback que j'ai donné a lesim). si vous trouvez un autre wording ca serait top. mais de haut en bas, le 1er champ arrive apres le dernier champ. a l'inverse le dernier champ vient remplacer le 1er champ