Skip to content

Commit

Permalink
a simpler way of upadating the apply edits button visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
biyeun committed Jul 2, 2024
1 parent dcc33e9 commit b6448ee
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 40 deletions.
3 changes: 0 additions & 3 deletions corehq/apps/prototype/static/prototype/js/data_cleaning.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ hqDefine("prototype/js/data_cleaning",[
if (evt.detail.elt.dataset.refreshTable) {
htmx.trigger(evt.detail.elt.dataset.refreshTable, 'refreshTable');
}
if (evt.detail.elt.dataset.refreshEdit) {
htmx.trigger(evt.detail.elt.dataset.refreshEdit, 'refreshEdit');
}
});
document.body.addEventListener('htmx:beforeSend', function (evt) {
if (evt.detail.elt.dataset.selectAll) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{% load django_tables2 %}
{% load hq_shared_tags %}

<div class="editable-column-container"
data-refresh-edit="{% if table.css_id %}#{{ table.css_id }}{% else %}div.table-container{% endif %} .edit-button"
x-data='{ isEditing: false,
cellValue: "{% if edited_value %}{{ edited_value }}{% else %}{{ value }}{% endif %}" }'>
cellValue: "{% if edited_value %}{{ edited_value }}{% else %}{{ value }}{% endif %}" }'
{% if update_edit %}
x-init="$dispatch('updateApplyEditsButton', {{ table.has_edits|BOOL }})"
{% endif %}>
<div class="inline-edit-block"
x-show="!isEditing"
@dblclick="isEditing = true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,20 @@
</div>
{% endif %}

{% include "prototype/data_cleaning/partials/buttons/apply_edits_button.html" %}
<div class="ps-2 ms-2 edit-button"
x-data="{ hasEdits: {{ table.has_edits|BOOL }} }"
x-show="hasEdits && numRecordsSelected > 0"
@update-apply-edits-button.camel.window="hasEdits = $event.detail">
<i class="fa-solid fa-pencil"></i>
{% trans "Edits" %}:
<button class="btn btn-success btn-sm ms-2"
type="button"
hx-post="{{ request.path_info }}{% querystring %}"
hx-action="apply_edits"
hx-target="{% if table.css_id %}#{{ table.css_id }}{% else %}div.table-container{% endif %}">
<i class="fa-solid fa-check"></i> {% trans "Apply Edits to Selected Rows" %}
</button>
</div>

</div>
{{ block.super }}
Expand Down
14 changes: 1 addition & 13 deletions corehq/apps/prototype/views/data_cleaning/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def get_cell_context_data(self, request):

def render_table_cell_response(self, request, *args, **kwargs):
context = self.get_cell_context_data(request)
context['update_edit'] = True
self.template_name = self.get_column().template_name
return self.render_htmx_partial_response(
request, self.get_column().template_name, context
Expand Down Expand Up @@ -228,16 +229,3 @@ def edit_cell_value(self, request, *args, **kwargs):
del all_rows[self.record_id][edited_slug]
data_store.set(all_rows)
return self.render_table_cell_response(request, *args, **kwargs)

@hx_action('post')
def refresh_apply_edits_button(self, request, *args, **kwargs):
context = {}
table = config.RequestConfig(request).configure(
self.table_class(data=[])
)
context[self.get_context_table_name(table)] = table
return self.render_htmx_partial_response(
request,
"prototype/data_cleaning/partials/buttons/apply_edits_button.html",
context
)

0 comments on commit b6448ee

Please sign in to comment.