Skip to content
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

[ TASK-1027 ] Conditional label for 'Delete Project and Data' button #5104

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

pauloamorimbr
Copy link
Contributor

@pauloamorimbr pauloamorimbr commented Sep 11, 2024

TASK-1027

Checklist

  1. If you've added code that should be tested, add tests
  2. If you've changed APIs, update (or create!) the documentation
  3. Ensure the tests pass
  4. Make sure that your code lints and that you've followed our coding style
  5. Write a title and, if necessary, a description of your work suitable for publishing in our release notes
  6. Mention any related issues in this repository (as #ISSUE) and in other repositories (as kobotoolbox/other#ISSUE)
  7. Open an issue in the docs if there are UI/UX changes

Description

The "Delete Project" button label now can be either "Delete Project" and "Delete Project and Data" to reflect whether the project has submissions to be deleted along with the project or not.

Notes

This PR adds a conditional label for the 'Delete Project and Data' button, where it will only show 'Delete Project' when there's no submissions to the project.

No data:
image

With data:
image

I opted to isolate the label in a separated variable instead of adding the conditional logic into the button for better readability.
Decided to go back in this decision and leave the condition in the element itself, since there are other conditions for the element rendering.

@pauloamorimbr pauloamorimbr changed the title TASK 1027 - Conditional label for 'Delete Project and Data' button [ TASK-1027 ] Conditional label for 'Delete Project and Data' button Sep 11, 2024
Copy link

@@ -873,6 +873,10 @@ class ProjectSettings extends React.Component {
const isSelfOwned = assetUtils.isSelfOwned(this.state.formAsset);
const descriptionField = envStore.data.getProjectMetadataField('description');

const deleteButtonLabel = this.state.formAsset.deployment__submission_count > 0 ?
Copy link
Contributor

@p2edwards p2edwards Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to check this real quick, since it's possible for deployment__submission_count to be null when viewed by users with row-level submission view permissions (see kpi#4739). But
thanks to the magic of JS, null > 0 is false, so no problem here, it's safe to run. Those users would lack 'manage this form' permission, so it's hard for them to get to this settings page anyway. 👍

Copy link
Contributor Author

@pauloamorimbr pauloamorimbr Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I changed it in 5f22d64 and moved the condition to the element. Since it may not be rendered it does make more sense to leave the conditional label inside it as well. 🙇🏻

Copy link
Contributor

@p2edwards p2edwards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Tested and it works!

@pauloamorimbr pauloamorimbr self-assigned this Sep 11, 2024
@p2edwards p2edwards merged commit 81ef0fd into beta Sep 12, 2024
7 checks passed
@p2edwards p2edwards deleted the task-1027-change-delete-project-button-text branch September 12, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants