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AAuB,OAAD,CAAQ3F,KAAK,QAAQ4F,QAAS9D,EAAS+D,KAAK,UAAUC,QAAQ,YAA9D,qBAGA,SAAC,EAAAH,OAAD,CACE3F,KAAK,SACL8F,QAAQ,YACRF,QAAStD,GAAayD,EAAAA,EAAAA,SAAQjD,GAAU,IACxCkD,KAAK,oBAJP,8BAQA,SAAC,EAAAL,OAAD,CAAQ3F,KAAK,SAAS8F,QAAQ,UAAUF,QAAStD,GAAayD,EAAAA,EAAAA,SAAQjD,GAAU,IAASkD,KAAK,OAA9F,qCCzLGC,EAAiB,IAA0B,YAAzB,UAAElE,GAAuB,EACtD,MAAOuC,EAAQ4B,IAAa7D,EAAAA,EAAAA,WAAS,GAC/B8D,GAAoBjE,EAAAA,EAAAA,GAAuBH,GAC3CqE,IAAyB,WAACnE,EAAAA,EAAAA,aAAYkE,UAAb,iBAAC,EAAgClH,eAAjC,QAAC,EAAyCmE,QAEzE,OACE,iCACE,SAAC,EAAAiD,cAAD,CACEL,KAAK,OACLJ,QAAS,IAAMM,GAAU,GACzB,aAAW,mBACXI,UAAWF,EAJb,8BASC9B,IAAU,SAACzC,EAAD,CAAqBC,QAAS,IAAMoE,GAAU,GAAQnE,UAAWA","sources":["webpack://grafana/./public/app/features/explore/AddToDashboard/addToDashboard.ts","webpack://grafana/./public/app/features/explore/AddToDashboard/AddToDashboardModal.tsx","webpack://grafana/./public/app/features/explore/AddToDashboard/index.tsx"],"sourcesContent":["import { DataFrame, DataQuery, DataSourceRef } from '@grafana/data';\nimport { backendSrv } from 'app/core/services/backend_srv';\nimport {\n getNewDashboardModelData,\n setDashboardToFetchFromLocalStorage,\n} from 'app/features/dashboard/state/initDashboard';\nimport { DashboardDTO, ExplorePanelData } from 'app/types';\n\nexport enum AddToDashboardError {\n FETCH_DASHBOARD = 'fetch-dashboard',\n SET_DASHBOARD_LS = 'set-dashboard-ls-error',\n}\n\ninterface AddPanelToDashboardOptions {\n queries: DataQuery[];\n queryResponse: ExplorePanelData;\n datasource?: DataSourceRef;\n dashboardUid?: string;\n}\n\nfunction createDashboard(): DashboardDTO {\n const dto = getNewDashboardModelData();\n\n // getNewDashboardModelData adds by default the \"add-panel\" panel. We don't want that.\n dto.dashboard.panels = [];\n\n return dto;\n}\n\nexport async function setDashboardInLocalStorage(options: AddPanelToDashboardOptions) {\n const panelType = getPanelType(options.queries, options.queryResponse);\n const panel = {\n targets: options.queries,\n type: panelType,\n title: 'New Panel',\n gridPos: { x: 0, y: 0, w: 12, h: 8 },\n datasource: options.datasource,\n };\n\n let dto: DashboardDTO;\n\n if (options.dashboardUid) {\n try {\n dto = await backendSrv.getDashboardByUid(options.dashboardUid);\n } catch (e) {\n throw AddToDashboardError.FETCH_DASHBOARD;\n }\n } else {\n dto = createDashboard();\n }\n\n dto.dashboard.panels = [panel, ...(dto.dashboard.panels ?? [])];\n\n try {\n setDashboardToFetchFromLocalStorage(dto);\n } catch {\n throw AddToDashboardError.SET_DASHBOARD_LS;\n }\n}\n\nconst isVisible = (query: DataQuery) => !query.hide;\nconst hasRefId = (refId: DataFrame['refId']) => (frame: DataFrame) => frame.refId === refId;\n\nfunction getPanelType(queries: DataQuery[], queryResponse: ExplorePanelData) {\n for (const { refId } of queries.filter(isVisible)) {\n // traceview is not supported in dashboards, skipping it for now.\n const hasQueryRefId = hasRefId(refId);\n if (queryResponse.graphFrames.some(hasQueryRefId)) {\n return 'timeseries';\n }\n if (queryResponse.logsFrames.some(hasQueryRefId)) {\n return 'logs';\n }\n if (queryResponse.nodeGraphFrames.some(hasQueryRefId)) {\n return 'nodeGraph';\n }\n if (queryResponse.traceFrames.some(hasQueryRefId)) {\n return 'traces';\n }\n }\n\n // falling back to table\n return 'table';\n}\n","import { partial } from 'lodash';\nimport React, { useEffect, useState } from 'react';\nimport { DeepMap, FieldError, useForm } from 'react-hook-form';\nimport { useSelector } from 'react-redux';\n\nimport { locationUtil, SelectableValue } from '@grafana/data';\nimport { config, locationService, reportInteraction } from '@grafana/runtime';\nimport { Alert, Button, Field, InputControl, Modal, RadioButtonGroup } from '@grafana/ui';\nimport { DashboardPicker } from 'app/core/components/Select/DashboardPicker';\nimport { removeDashboardToFetchFromLocalStorage } from 'app/features/dashboard/state/initDashboard';\nimport { ExploreId } from 'app/types';\n\nimport { getExploreItemSelector } from '../state/selectors';\n\nimport { setDashboardInLocalStorage, AddToDashboardError } from './addToDashboard';\n\nenum SaveTarget {\n NewDashboard = 'new-dashboard',\n ExistingDashboard = 'existing-dashboard',\n}\n\nconst SAVE_TARGETS: Array> = [\n {\n label: 'New dashboard',\n value: SaveTarget.NewDashboard,\n },\n {\n label: 'Existing dashboard',\n value: SaveTarget.ExistingDashboard,\n },\n];\n\ninterface SaveTargetDTO {\n saveTarget: SaveTarget;\n}\ninterface SaveToNewDashboardDTO extends SaveTargetDTO {\n saveTarget: SaveTarget.NewDashboard;\n}\n\ninterface SaveToExistingDashboard extends SaveTargetDTO {\n saveTarget: SaveTarget.ExistingDashboard;\n dashboardUid: string;\n}\n\ntype FormDTO = SaveToNewDashboardDTO | SaveToExistingDashboard;\n\nfunction assertIsSaveToExistingDashboardError(\n errors: DeepMap\n): asserts errors is DeepMap {\n // the shape of the errors object is always compatible with the type above, but we need to\n // explicitly assert its type so that TS can narrow down FormDTO to SaveToExistingDashboard\n // when we use it in the form.\n}\n\nfunction getDashboardURL(dashboardUid?: string) {\n return dashboardUid ? `d/${dashboardUid}` : 'dashboard/new';\n}\n\nenum GenericError {\n UNKNOWN = 'unknown-error',\n NAVIGATION = 'navigation-error',\n}\n\ninterface SubmissionError {\n error: AddToDashboardError | GenericError;\n message: string;\n}\n\ninterface Props {\n onClose: () => void;\n exploreId: ExploreId;\n}\n\nexport const AddToDashboardModal = ({ onClose, exploreId }: Props) => {\n const exploreItem = useSelector(getExploreItemSelector(exploreId))!;\n const [submissionError, setSubmissionError] = useState();\n const {\n handleSubmit,\n control,\n formState: { errors },\n watch,\n } = useForm({\n defaultValues: { saveTarget: SaveTarget.NewDashboard },\n });\n const saveTarget = watch('saveTarget');\n\n const onSubmit = async (openInNewTab: boolean, data: FormDTO) => {\n setSubmissionError(undefined);\n const dashboardUid = data.saveTarget === SaveTarget.ExistingDashboard ? data.dashboardUid : undefined;\n\n reportInteraction('e2d_submit', {\n newTab: openInNewTab,\n saveTarget: data.saveTarget,\n queries: exploreItem.queries.length,\n });\n\n try {\n await setDashboardInLocalStorage({\n dashboardUid,\n datasource: exploreItem.datasourceInstance?.getRef(),\n queries: exploreItem.queries,\n queryResponse: exploreItem.queryResponse,\n });\n } catch (error) {\n switch (error) {\n case AddToDashboardError.FETCH_DASHBOARD:\n setSubmissionError({ error, message: 'Could not fetch dashboard information. Please try again.' });\n break;\n case AddToDashboardError.SET_DASHBOARD_LS:\n setSubmissionError({ error, message: 'Could not add panel to dashboard. Please try again.' });\n break;\n default:\n setSubmissionError({ error: GenericError.UNKNOWN, message: 'Something went wrong. Please try again.' });\n }\n return;\n }\n\n const dashboardURL = getDashboardURL(dashboardUid);\n if (!openInNewTab) {\n onClose();\n locationService.push(locationUtil.stripBaseFromUrl(dashboardURL));\n return;\n }\n\n const didTabOpen = !!global.open(config.appUrl + dashboardURL, '_blank');\n if (!didTabOpen) {\n setSubmissionError({\n error: GenericError.NAVIGATION,\n message: 'Could not navigate to the selected dashboard. Please try again.',\n });\n removeDashboardToFetchFromLocalStorage();\n return;\n }\n onClose();\n };\n\n useEffect(() => {\n reportInteraction('e2d_open');\n }, []);\n\n return (\n \n
\n (\n \n \n \n )}\n name=\"saveTarget\"\n />\n\n {saveTarget === SaveTarget.ExistingDashboard &&\n (() => {\n assertIsSaveToExistingDashboardError(errors);\n return (\n (\n \n onChange(d?.uid)}\n />\n \n )}\n control={control}\n name=\"dashboardUid\"\n shouldUnregister\n rules={{ required: { value: true, message: 'This field is required.' } }}\n />\n );\n })()}\n\n {submissionError && (\n \n {submissionError.message}\n \n )}\n\n \n \n \n Open in new tab\n \n \n \n \n
\n );\n};\n","import React, { useState } from 'react';\nimport { useSelector } from 'react-redux';\n\nimport { ToolbarButton } from '@grafana/ui';\nimport { ExploreId } from 'app/types';\n\nimport { getExploreItemSelector } from '../state/selectors';\n\nimport { AddToDashboardModal } from './AddToDashboardModal';\n\ninterface Props {\n exploreId: ExploreId;\n}\n\nexport const AddToDashboard = ({ exploreId }: Props) => {\n const [isOpen, setIsOpen] = useState(false);\n const selectExploreItem = getExploreItemSelector(exploreId);\n const explorePaneHasQueries = !!useSelector(selectExploreItem)?.queries?.length;\n\n return (\n <>\n setIsOpen(true)}\n aria-label=\"Add to dashboard\"\n disabled={!explorePaneHasQueries}\n >\n Add to dashboard\n \n\n {isOpen && setIsOpen(false)} exploreId={exploreId} />}\n \n );\n};\n"],"names":["AddToDashboardError","async","setDashboardInLocalStorage","options","panelType","queries","queryResponse","refId","filter","isVisible","hasQueryRefId","hasRefId","graphFrames","some","logsFrames","nodeGraphFrames","traceFrames","getPanelType","panel","targets","type","title","gridPos","x","y","w","h","datasource","dto","dashboardUid","backendSrv","e","FETCH_DASHBOARD","getNewDashboardModelData","dashboard","panels","createDashboard","setDashboardToFetchFromLocalStorage","SET_DASHBOARD_LS","query","hide","frame","SaveTarget","SAVE_TARGETS","label","value","NewDashboard","ExistingDashboard","GenericError","AddToDashboardModal","onClose","exploreId","exploreItem","useSelector","getExploreItemSelector","submissionError","setSubmissionError","useState","handleSubmit","control","formState","errors","watch","useForm","defaultValues","saveTarget","onSubmit","openInNewTab","data","undefined","reportInteraction","newTab","length","datasourceInstance","getRef","error","message","UNKNOWN","dashboardURL","getDashboardURL","locationService","locationUtil","global","open","config","NAVIGATION","removeDashboardToFetchFromLocalStorage","useEffect","Modal","onDismiss","isOpen","InputControl","render","field","Field","description","RadioButtonGroup","id","name","onChange","invalid","DashboardPicker","inputId","defaultOptions","d","uid","shouldUnregister","rules","required","Alert","severity","Button","onClick","fill","variant","partial","icon","AddToDashboard","setIsOpen","selectExploreItem","explorePaneHasQueries","ToolbarButton","disabled"],"sourceRoot":""}