fix disable behavior - #285
Conversation
|
Not sure what will happen when testing a new feature. We might also need a mechanism to add a temporary feature that can be later deleted. |
There was a problem hiding this comment.
Pull request overview
This PR changes “Disable” behavior for features from hard-deleting DB rows (which also unlinked historical task entries) to a soft-disable model using the existing Feature.visible flag, so disabled features are hidden until re-enabled.
Changes:
- Update feature toggling to flip
Feature.visibleinstead of deleting rows. - Update the setup/features UI to show active vs hidden (re-enableable) features.
- Reuse an existing feature row on “add new feature” when the name already exists (instead of creating duplicates).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| db/tracker/views.py | Only list visible=True features as “active” and pass hidden custom features to the template. |
| db/tracker/templates/setup_features.html | Render active features with “Disable” and add a hidden-features section with “Enable”. |
| db/tracker/templates/setup_base.html | Update client-side row creation to use “Disable” and include the expected button id. |
| db/tracker/ajax.py | Implement soft-disable/enable behavior and reuse existing feature rows on add. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (resp["status"] == "success") { | ||
| // clear fields | ||
| $("#new_feature_name").val(''); | ||
| $("#new_feature_path").val(''); | ||
|
|
||
| // add new row to table | ||
| tr = $(document.createElement("tr")); | ||
| tr.html("<td>" + resp["data"].id + "</td>" + "<td>" + resp["data"].name + "</td>" + "<td>" + | ||
| "<input type=\"submit\" value=\"Remove\" onclick=\"toggle_feature(\'" + resp["data"].name + "\')\">" + "</td>"); | ||
| "<input type=\"submit\" id=\"feature_" + resp["data"].name + "\" value=\"Disable\" onclick=\"toggle_feature(\'" + resp["data"].name + "\')\">" + "</td>"); | ||
| $('#new-feature-row').after(tr); | ||
| } |
| <td> | ||
| {% if not feature.name in built_in_feature_names %} | ||
| <input type="submit" id="feature_{{feature.name}}" value="Remove" onclick="toggle_feature('{{feature.name}}')"> | ||
| {% else %} | ||
| <input type="submit" id="feature_{{feature.name}}" value="Disable" onclick="toggle_feature('{{feature.name}}')"> | ||
| {% endif %} | ||
| <input type="submit" id="feature_{{feature.name}}" value="Disable" onclick="toggle_feature('{{feature.name}}')"> | ||
| </tr> |
| # check if the feature is already installed | ||
| existing_features = Feature.objects.filter(name=name) | ||
| existing_features = Feature.objects.filter(name=name).order_by('id') | ||
|
|
||
| if len(existing_features) > 0: | ||
| # disable the feature | ||
| Feature.objects.filter(name=name).delete() | ||
| msg = "Disabled feature: %s" % str(name) | ||
| return _respond(dict(msg=msg, status="success")) | ||
| if existing_features.filter(visible=True).exists(): | ||
| # Soft-disable the feature so historical task links remain intact. | ||
| existing_features.filter(visible=True).update(visible=False) | ||
| msg = "Disabled feature: %s" % str(name) | ||
| return _respond(dict(msg=msg, status="success")) | ||
|
|
||
| # Re-enable an existing hidden feature instead of creating a new row. | ||
| existing_features.update(visible=True) | ||
| feat = existing_features[0] | ||
| msg = "Enabled feature: %s" % str(feat.name) | ||
| return _respond(dict(msg=msg, status="success", id=feat.id)) |
ajm2605
left a comment
There was a problem hiding this comment.
This looks pretty cool I don't know how to program html so I have no Idea if it works but happy to test it out
Previously if you disable a feature, it removes it from the database and unlinks task entries that use that feature.
Now it merely hides the feature from showing up anywhere until it is re-enabled.