-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Library Panels: Add name endpoint & unique name validation to AddLibraryPanelModal #33987
Conversation
…dLibraryPanelModal
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.
Is the validation for the same name in the same folder?
No, it's global. Should it be per folder? |
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.
Works great, except when you change org 😉 I left some suggestions for consideration.
|
||
// getLibraryElementByName gets a Library Element by name. | ||
func (l *LibraryElementService) getLibraryElementByName(c *models.ReqContext) (LibraryElementDTO, error) { | ||
return l.getLibraryElement(c, map[string]interface{}{"name": c.Params(":name")}) |
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.
The name should be unique within an Org so I think you need org_id as a param here too?
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.
Ah, you're right, will change
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.
Also, I think we need kind
, and folder_id
here too
I agree with Torkel, within the same folder, kind and org the name should be unique or should be exactly the same as the UniqueKey defined here:
|
Hmm, if we just want the name to be unique per folder (per kind, per org), should the name endpoint be able to return multiple library panels if several exist with the same name in different folders? |
I think returning an array with elements should do it! |
}, [debouncedPanelTitle]); | ||
|
||
const invalidInput = | ||
!isValidTitle?.value && isValidTitle.value !== undefined && panelTitle === debouncedPanelTitle && !waiting; |
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.
Settled on the use of waiting
here to avoid a small bit of jank that I couldn't find a way to work around otherwise.
Initially I had wanted to use !isValidTitle.loading
as one of the conditions here, but this resulted in a flash between valid/invalid styles when editing an invalid title to a valid one.
The reason this happens is that, when the user starts typing panelTitle
no longer equals debouncedPanelTitle
, so invalidInput
becomes false, and the valid styling is used.
When the user stops typing, after 350ms debouncedPanelTitle
equals panelTitle
. I had hoped then, that the useAsync
callback would execute and set isValidTitle.loading
to true, thus keeping invalidInput
false, but I suspect because of some event loop weirdness this doesn't happen for a frame or two, and so we get a flash of invalid styling before isValidTitle.loading
settles on being true.
Anyway, if anyone knows a nicer way to do this, let me know.
byName
endpoint & unique name validation to AddLibraryPanelModalname
endpoint & unique name validation to AddLibraryPanelModal
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.
Great work on this and works as expected 🎉
public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx
Outdated
Show resolved
Hide resolved
public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx
Outdated
Show resolved
Hide resolved
name
endpoint & unique name validation to AddLibraryPanelModalname
endpoint & unique name validation to AddLibraryPanelModal
…braryPanelModal (#33987) (#34285) (cherry picked from commit c778d6a) Co-authored-by: kay delaney <[email protected]>
name
endpoint & unique name validation to AddLibraryPanelModal
What this PR does / why we need it:
Adds a
byName
endpoint to the library elements api in service of unique name validation forAddLibraryPanelModal
.