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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboards: Fix so that empty folders can be deleted from the manage dashboards/folders page #42527

Merged
merged 3 commits into from Dec 1, 2021

Conversation

ashharrison90
Copy link
Contributor

@ashharrison90 ashharrison90 commented Nov 30, 2021

What this PR does / why we need it:

  • there is no way to currently delete an empty folder. this is because canDelete is currently based on canMove, and canMove is only true if a dashboard is selected.
  • change the logic so canDelete is enabled if anything is selected. this allows us to select empty folders, and also allows us to delete folders before they've been expanded.
  • add a new unit test to make sure we can delete empty folders

Which issue(s) this PR fixes:

Fixes #42486

Special notes for your reviewer:

  • we should probably hold off on merging this until the release is complete 馃槺

@ashharrison90 ashharrison90 added this to the 8.3.1 milestone Nov 30, 2021
@ashharrison90 ashharrison90 requested a review from a team as a code owner November 30, 2021 13:56
@ashharrison90 ashharrison90 self-assigned this Nov 30, 2021
@ashharrison90 ashharrison90 requested review from joshhunt and kaydelaney and removed request for a team November 30, 2021 13:56
Copy link
Contributor

@Clarity-89 Clarity-89 left a comment

Choose a reason for hiding this comment

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

Nice catch, works as expected 馃帀 Could we also update the text copy for delete warning as it doesn't seem to account for singular folder case properly?
Screenshot 2021-12-01 at 10 46 20

Copy link
Contributor

@hugohaggmark hugohaggmark left a comment

Choose a reason for hiding this comment

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

Looks good but I haven't had the chance to test it out (yet)


const canDelete = useMemo(() => {
const somethingChecked = results.some((result) => result.checked || result.items.some((item) => item.checked));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I wonder if it would be worth to flatten everything and check for checked because using .some in another .some isn't super readable. I know I've been part of adding to this complexity in the past 馃檲 I guess as long we have good tests for these cases its not super important. 馃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hugohaggmark yeah agreed it's not super readable, but also didn't wanna flatten as that means we definitely have to go through the entire array. when using list view that means looping an array containing every dashboard that exists in your instance 馃槵 whereas with the .some it shortcircuits that loop as soon as it finds one.

have moved the logic into a separate mini function instead. wdyt? 馃

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right! Looks better as a separate function.

@ashharrison90
Copy link
Contributor Author

ashharrison90 commented Dec 1, 2021

Nice catch, works as expected 馃帀 Could we also update the text copy for delete warning as it doesn't seem to account for singular folder case properly? Screenshot 2021-12-01 at 10 46 20

@Clarity-89 i don't think this is easily possible as there's currently no real way to distinguish between an empty folder (items: []), and a folder that just hasn't been expanded yet to fetch the inner dashboards (items: []). we could maybe make a call to the backend on deletion of a single folder to check if it's really empty or not, but my gut feeling is to err on the side of the more generic error message for simplicity. wdyt? 馃

@Clarity-89
Copy link
Contributor

Nice catch, works as expected 馃帀 Could we also update the text copy for delete warning as it doesn't seem to account for singular folder case properly? Screenshot 2021-12-01 at 10 46 20

@Clarity-89 i don't think this is easily possible as there's currently no real way to distinguish between an empty folder (items: []), and a folder that just hasn't been expanded yet to fetch the inner dashboards (items: []). we could maybe make a call to the backend on deletion of a single folder to check if it's really empty or not, but i'm erring on the side of the more generic error message for simplicity. wdyt? 馃

Just to clarify, if only one folder is selected, the message should say Do you want to delete the selected folder and all its dashboards and alerts? instead of Do you want to delete the selected folder and all their dashboards and alerts?. The logic to detect if multiple dashboards are selected is already there, it just needs to be applied to this string.

@ashharrison90
Copy link
Contributor Author

ashharrison90 commented Dec 1, 2021

@Clarity-89 ahhhhh gotcha, that we can probably do. 馃憤 i thought you were referring to the dashboards and alerts bit 馃う

@ashharrison90 ashharrison90 merged commit a365dcc into main Dec 1, 2021
@ashharrison90 ashharrison90 deleted the ash/42486 branch December 1, 2021 14:53
grafanabot pushed a commit that referenced this pull request Dec 1, 2021
* Manage dashboards: Can now delete empty folders

* Split hasChecked out into a separate function

* Update modal text

(cherry picked from commit a365dcc)
ashharrison90 added a commit that referenced this pull request Dec 1, 2021
* Manage dashboards: Can now delete empty folders

* Split hasChecked out into a separate function

* Update modal text

(cherry picked from commit a365dcc)

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
@marefr marefr changed the title Manage dashboards: Can now delete empty folders Dashboards: Fix so that empty folders can be deleted from the manage dashboards/folders page Dec 10, 2021
simPod added a commit to simPod/grafana that referenced this pull request Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to delete empty folders on Grafana dashboards
3 participants