-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Folders: Migrate getFolder API to app platform #107617
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
Open
aocenas
wants to merge
40
commits into
main
Choose a base branch
from
aocenas/folders/migrate-api-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+589
−105
Open
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
4ea5a35
Add /children endpoint
aocenas fe84c8c
Update folder client
aocenas a9c2f4c
Add comment
aocenas d867638
Add feature toggle
aocenas 187e977
Add new version of useFoldersQuery
aocenas db5b914
Merge branch 'main' into aocenas/folders/migrate-api
Clarity-89 c70aaff
Error handling
Clarity-89 8e8ad40
Format
Clarity-89 2a00788
Rename feature toggle
aocenas c7f3908
Remove options and move root folder constant
aocenas eed14cd
Merge remote-tracking branch 'origin/aocenas/folders/migrate-api' int…
aocenas 34bc654
Fix feature toggle merge
aocenas 48af59b
Merge branch 'main' into aocenas/folders/migrate-api
aocenas d1d959d
Add feature toggle again
aocenas 421958b
Rename useFoldersQuery files
aocenas d529ed1
Update API spec
aocenas ea906e8
Fix test
aocenas 634cd2a
Add test
aocenas b86b98d
Migrate delete folder button
aocenas 845bbe6
useGetFolderQueryFacade
aocenas a873b99
Merge branch 'main' into aocenas/folders/migrate-api-2
aocenas e7b4f3e
Use getFolder facade hook
aocenas 06f0baa
Recreate legacy getFolder from the APIs
aocenas 802fa46
Merge branch 'main' into aocenas/folders/migrate-api-2
aocenas 7b30613
Fix imports
aocenas bd65f06
Add comment
aocenas 2f5b2c9
Merge branch 'main' into aocenas/folders/migrate-api-2
Clarity-89 c8423b4
Rename function
aocenas dc229e0
Simulate virtual folders in the API client
aocenas 320f469
Translations
aocenas 7c6dbdd
Merge branch 'main' into aocenas/folders/migrate-api-2
aocenas 9ba694d
Update test
aocenas 18b12c7
Move the hook out of the index file
aocenas 8fdb275
Fix undefined in test
aocenas 24e5b2b
Better status combining
aocenas 152612b
Merge branch 'main' into aocenas/folders/migrate-api-2
aocenas c8b3dd7
Use real access api for virtual folders
aocenas 641c091
Add basic test for the hook
aocenas d715ddb
Remove commented import
aocenas d1b2fb9
Merge branch 'main' into aocenas/folders/migrate-api-2
aocenas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
apps/folder/pkg/apis/folder/v1beta1/zz_generated.openapi.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package folders | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
folders "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apiserver/pkg/registry/rest" | ||
) | ||
|
||
// getFolderParents gets a list of info objects for each parent of a Folder | ||
// TODO: There are some other implementations that seem to do similar thing like pkg/services/folder/service.go#GetParents. | ||
// | ||
// Not sure if they should be merged somehow or not. | ||
func getFolderParents(ctx context.Context, folderGetter rest.Getter, folder *folders.Folder) *folders.FolderInfoList { | ||
info := &folders.FolderInfoList{ | ||
Items: []folders.FolderInfo{}, | ||
} | ||
for folder != nil { | ||
parent := getParent(folder) | ||
descr := "" | ||
if folder.Spec.Description != nil { | ||
descr = *folder.Spec.Description | ||
} | ||
info.Items = append(info.Items, folders.FolderInfo{ | ||
Name: folder.Name, | ||
Title: folder.Spec.Title, | ||
Description: descr, | ||
Parent: parent, | ||
}) | ||
if parent == "" { | ||
break | ||
} | ||
|
||
obj, err := folderGetter.Get(ctx, parent, &metav1.GetOptions{}) | ||
if err != nil { | ||
info.Items = append(info.Items, folders.FolderInfo{ | ||
Name: parent, | ||
Detached: true, | ||
Description: err.Error(), | ||
}) | ||
break | ||
} | ||
|
||
parentFolder, ok := obj.(*folders.Folder) | ||
if !ok { | ||
info.Items = append(info.Items, folders.FolderInfo{ | ||
Name: parent, | ||
Detached: true, | ||
Description: fmt.Sprintf("expected folder, found: %T", obj), | ||
}) | ||
break | ||
} | ||
folder = parentFolder | ||
} | ||
return info | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reasoning behind adding this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is returned in the old API. The main point of this step in the migration is to use the new API but providing the same data as old one, before going on and refactoring the front end to use the more granular APIs better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 where are they returned in the HTTP api? I see this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're included on the individual details' endpoint, if you pass in
accesscontrol=true
query param, e.g./api/folders/edx2eifh2qx34e?accesscontrol=true