diff --git a/pkg/services/libraryelements/api.go b/pkg/services/libraryelements/api.go index 5bb3a03612a..d3113c48526 100644 --- a/pkg/services/libraryelements/api.go +++ b/pkg/services/libraryelements/api.go @@ -63,6 +63,8 @@ func (l *LibraryElementService) createHandler(c *contextmodel.ReqContext) respon if cmd.FolderUID != nil { if *cmd.FolderUID == "" { cmd.FolderID = 0 + generalFolderUID := ac.GeneralFolderUID + cmd.FolderUID = &generalFolderUID } else { folder, err := l.folderService.Get(c.Req.Context(), &folder.GetFolderQuery{OrgID: c.SignedInUser.GetOrgID(), UID: cmd.FolderUID, SignedInUser: c.SignedInUser}) if err != nil || folder == nil { diff --git a/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx b/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx index a982f9e7342..d4b9f8db378 100644 --- a/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx +++ b/public/app/features/library-panels/components/AddLibraryPanelModal/AddLibraryPanelModal.tsx @@ -1,13 +1,14 @@ import React, { useCallback, useEffect, useState } from 'react'; import { useAsync, useDebounce } from 'react-use'; -import { isFetchError } from '@grafana/runtime'; +import { FetchError, isFetchError } from '@grafana/runtime'; import { Button, Field, Input, Modal } from '@grafana/ui'; import { OldFolderPicker } from 'app/core/components/Select/OldFolderPicker'; import { t, Trans } from 'app/core/internationalization'; import { PanelModel } from '../../../dashboard/state'; import { getLibraryPanelByName } from '../../state/api'; +import { LibraryElementDTO } from '../../types'; import { usePanelSave } from '../../utils/usePanelSave'; interface AddLibraryPanelContentsProps { @@ -28,9 +29,11 @@ export const AddLibraryPanelContents = ({ panel, initialFolderUid, onDismiss }: const { saveLibraryPanel } = usePanelSave(); const onCreate = useCallback(() => { panel.libraryPanel = { uid: '', name: panelName }; - saveLibraryPanel(panel, folderUid!).then((res) => { - if (!(res instanceof Error)) { + saveLibraryPanel(panel, folderUid!).then((res: LibraryElementDTO | FetchError) => { + if (!isFetchError(res)) { onDismiss(); + } else { + panel.libraryPanel = undefined; } }); }, [panel, panelName, folderUid, onDismiss, saveLibraryPanel]);