Skip to content

Commit

Permalink
Add proposal state label in diff renderer (decidim#13396)
Browse files Browse the repository at this point in the history
* Add proposal state label in diff renderer

* Apply review recommendations
  • Loading branch information
alecslupu committed Oct 11, 2024
1 parent 03c9b18 commit 00a15be
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ def attribute_types
address: :string,
latitude: :string,
longitude: :string,
decidim_proposals_proposal_state_id: :string
decidim_proposals_proposal_state_id: :state
}
end

# Parses the values before parsing the changeset.
def parse_changeset(attribute, values, type, diff)
return parse_scope_changeset(attribute, values, type, diff) if type == :scope
return parse_state_changeset(attribute, values, type, diff) if type == :state

values = parse_values(attribute, values)
old_value = values[0]
Expand All @@ -37,6 +38,22 @@ def parse_changeset(attribute, values, type, diff)
)
end

def parse_state_changeset(attribute, values, type, diff)
return unless diff

old_scope = Decidim::Proposals::ProposalState.find_by(id: values[0])
new_scope = Decidim::Proposals::ProposalState.find_by(id: values[1])

diff.update(
attribute => {
type:,
label: I18n.t(attribute, scope: i18n_scope),
old_value: old_scope ? translated_attribute(old_scope.title) : "",
new_value: new_scope ? translated_attribute(new_scope.title) : ""
}
)
end

# Handles which values to use when diffing emendations and
# normalizes line endings of the :body attribute values.
# Returns and Array of two Strings.
Expand Down
1 change: 1 addition & 0 deletions decidim-proposals/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ en:
automatic_hashtags: Hashtags automatically added
body: Body
category_id: Category
decidim_proposals_proposal_state_id: State
decidim_scope_id: Scope
has_address: Has address
scope_id: Scope
Expand Down
26 changes: 26 additions & 0 deletions decidim-proposals/spec/system/proposals_versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,31 @@
end
end
end

it "show the correct state" do
form_params = {
internal_state: "evaluating",
answer: { en: "Foo" },
cost: 2000,
cost_report: { en: "Cost report" },
execution_period: { en: "Execution period" }
}
form = Decidim::Proposals::Admin::ProposalAnswerForm.from_params(form_params).with_context(
current_user: proposal.authors.first,
current_component: proposal.component,
current_organization: proposal.component.organization
)
Decidim::Proposals::Admin::AnswerProposal.call(form, proposal)

visit current_path
click_on("Version 3 of 3")

within "#diff-for-state" do
expect(page).to have_content("State")
within ".diff > ul > .ins" do
expect(page).to have_content("Evaluating")
end
end
end
end
end

0 comments on commit 00a15be

Please sign in to comment.