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B,WAAa,qCAkB1D,SAAStB,EAAUkD,GACjB,MAAO,CACLhB,UAAWiB,EAAAA,GAAI","sources":["webpack://grafana/./public/app/features/folders/FolderLibraryPanelsPage.tsx","webpack://grafana/./public/app/features/library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { connect, ConnectedProps } from 'react-redux';\nimport { useAsync } from 'react-use';\n\nimport Page from '../../core/components/Page/Page';\nimport { GrafanaRouteComponentProps } from '../../core/navigation/types';\nimport { getNavModel } from '../../core/selectors/navModel';\nimport { StoreState } from '../../types';\nimport { LibraryPanelsSearch } from '../library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch';\nimport { OpenLibraryPanelModal } from '../library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal';\nimport { LibraryElementDTO } from '../library-panels/types';\n\nimport { getFolderByUid } from './state/actions';\nimport { getLoadingNav } from './state/navModel';\n\nexport interface OwnProps extends GrafanaRouteComponentProps<{ uid: string }> {}\n\nconst mapStateToProps = (state: StoreState, props: OwnProps) => {\n const uid = props.match.params.uid;\n return {\n navModel: getNavModel(state.navIndex, `folder-library-panels-${uid}`, getLoadingNav(1)),\n folderUid: uid,\n folder: state.folder,\n };\n};\n\nconst mapDispatchToProps = {\n getFolderByUid,\n};\n\nconst connector = connect(mapStateToProps, mapDispatchToProps);\n\nexport type Props = OwnProps & ConnectedProps<typeof connector>;\n\nexport function FolderLibraryPanelsPage({ navModel, getFolderByUid, folderUid, folder }: Props): JSX.Element {\n const { loading } = useAsync(async () => await getFolderByUid(folderUid), [getFolderByUid, folderUid]);\n const [selected, setSelected] = useState<LibraryElementDTO | undefined>(undefined);\n\n return (\n <Page navModel={navModel}>\n <Page.Contents isLoading={loading}>\n <LibraryPanelsSearch\n onClick={setSelected}\n currentFolderId={folder.id}\n showSecondaryActions\n showSort\n showPanelFilter\n />\n {selected ? <OpenLibraryPanelModal onDismiss={() => setSelected(undefined)} libraryPanel={selected} /> : null}\n </Page.Contents>\n </Page>\n );\n}\n\nexport default connector(FolderLibraryPanelsPage);\n","import { css } from '@emotion/css';\nimport { debounce } from 'lodash';\nimport React, { MouseEvent, useCallback, useEffect, useMemo, useState } from 'react';\n\nimport { GrafanaTheme2, SelectableValue, urlUtil } from '@grafana/data';\nimport { locationService } from '@grafana/runtime';\nimport { AsyncSelect, Button, Modal, useStyles2 } from '@grafana/ui';\n\nimport { DashboardSearchHit } from '../../../search/types';\nimport { getConnectedDashboards, getLibraryPanelConnectedDashboards } from '../../state/api';\nimport { LibraryElementDTO } from '../../types';\n\nexport interface OpenLibraryPanelModalProps {\n onDismiss: () => void;\n libraryPanel: LibraryElementDTO;\n}\n\nexport function OpenLibraryPanelModal({ libraryPanel, onDismiss }: OpenLibraryPanelModalProps): JSX.Element {\n const styles = useStyles2(getStyles);\n const [loading, setLoading] = useState(false);\n const [connected, setConnected] = useState(0);\n const [option, setOption] = useState<SelectableValue<DashboardSearchHit> | undefined>(undefined);\n useEffect(() => {\n const getConnected = async () => {\n const connectedDashboards = await getLibraryPanelConnectedDashboards(libraryPanel.uid);\n setConnected(connectedDashboards.length);\n };\n getConnected();\n }, [libraryPanel.uid]);\n const loadOptions = useCallback(\n (searchString: string) => loadOptionsAsync(libraryPanel.uid, searchString, setLoading),\n [libraryPanel.uid]\n );\n const debouncedLoadOptions = useMemo(\n () => debounce(loadOptions, 300, { leading: true, trailing: true }),\n [loadOptions]\n );\n const onViewPanel = (e: MouseEvent<HTMLButtonElement>) => {\n e.preventDefault();\n locationService.push(urlUtil.renderUrl(`/d/${option?.value?.uid}`, {}));\n };\n\n return (\n <Modal title=\"View panel in dashboard\" onDismiss={onDismiss} onClickBackdrop={onDismiss} isOpen>\n <div className={styles.container}>\n {connected === 0 ? (\n <span>Panel is not linked to a dashboard. Add the panel to a dashboard and retry.</span>\n ) : null}\n {connected > 0 ? (\n <>\n <p>\n This panel is being used in{' '}\n <strong>\n {connected} {connected > 1 ? 'dashboards' : 'dashboard'}\n </strong>\n .Please choose which dashboard to view the panel in:\n </p>\n <AsyncSelect\n isClearable\n isLoading={loading}\n defaultOptions={true}\n loadOptions={debouncedLoadOptions}\n onChange={setOption}\n placeholder=\"Start typing to search for dashboard\"\n noOptionsMessage=\"No dashboards found\"\n />\n </>\n ) : null}\n </div>\n <Modal.ButtonRow>\n <Button variant=\"secondary\" onClick={onDismiss} fill=\"outline\">\n Cancel\n </Button>\n <Button onClick={onViewPanel} disabled={!Boolean(option)}>\n {option ? `View panel in ${option?.label}...` : 'View panel in dashboard...'}\n </Button>\n </Modal.ButtonRow>\n </Modal>\n );\n}\n\nasync function loadOptionsAsync(uid: string, searchString: string, setLoading: (loading: boolean) => void) {\n setLoading(true);\n const searchHits = await getConnectedDashboards(uid);\n const options = searchHits\n .filter((d) => d.title.toLowerCase().includes(searchString.toLowerCase()))\n .map((d) => ({ label: d.title, value: d }));\n setLoading(false);\n\n return options;\n}\n\nfunction getStyles(theme: GrafanaTheme2) {\n return {\n container: css``,\n };\n}\n"],"names":["mapDispatchToProps","getFolderByUid","FolderLibraryPanelsPage","navModel","folderUid","folder","loading","useAsync","async","selected","setSelected","useState","undefined","isLoading","onClick","currentFolderId","id","showSecondaryActions","showSort","showPanelFilter","onDismiss","libraryPanel","connect","state","props","uid","match","params","getNavModel","navIndex","getLoadingNav","OpenLibraryPanelModal","styles","useStyles2","getStyles","setLoading","connected","setConnected","option","setOption","useEffect","connectedDashboards","getLibraryPanelConnectedDashboards","length","getConnected","loadOptions","useCallback","searchString","options","getConnectedDashboards","filter","d","title","toLowerCase","includes","map","label","value","loadOptionsAsync","debouncedLoadOptions","useMemo","debounce","leading","trailing","Modal","onClickBackdrop","isOpen","className","container","AsyncSelect","isClearable","defaultOptions","onChange","placeholder","noOptionsMessage","Button","variant","fill","e","preventDefault","locationService","urlUtil","disabled","Boolean","theme","css"],"sourceRoot":""}
|