@perses-dev/dashboards 0.44.0 → 0.45.0-rc0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/cjs/components/DashboardStickyToolbar/DashboardStickyToolbar.js +2 -2
  2. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +3 -3
  3. package/dist/cjs/components/DownloadButton/DownloadButton.js +1 -2
  4. package/dist/cjs/components/EditJsonButton/EditJsonButton.js +1 -2
  5. package/dist/cjs/components/GridLayout/GridItemContent.js +1 -2
  6. package/dist/cjs/components/GridLayout/GridLayout.js +1 -1
  7. package/dist/cjs/components/GridLayout/GridTitle.js +0 -1
  8. package/dist/cjs/components/Panel/Panel.js +1 -0
  9. package/dist/cjs/components/Panel/PanelHeader.js +5 -1
  10. package/dist/cjs/components/Panel/PanelLinks.js +137 -0
  11. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +32 -8
  12. package/dist/cjs/components/PanelDrawer/PanelPreview.js +1 -2
  13. package/dist/cjs/components/PanelDrawer/usePanelEditor.js +9 -6
  14. package/dist/cjs/components/index.js +0 -2
  15. package/dist/cjs/constants/user-interface-text.js +0 -2
  16. package/dist/cjs/context/DatasourceStoreProvider.js +3 -1
  17. package/dist/cjs/utils/index.js +0 -1
  18. package/dist/cjs/validation/panel.js +12 -2
  19. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +1 -1
  20. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
  21. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  22. package/dist/components/DashboardToolbar/DashboardToolbar.js +2 -2
  23. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  24. package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -1
  25. package/dist/components/DownloadButton/DownloadButton.js +1 -2
  26. package/dist/components/DownloadButton/DownloadButton.js.map +1 -1
  27. package/dist/components/EditJsonButton/EditJsonButton.d.ts.map +1 -1
  28. package/dist/components/EditJsonButton/EditJsonButton.js +1 -2
  29. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
  30. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  31. package/dist/components/GridLayout/GridItemContent.js +1 -2
  32. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  33. package/dist/components/GridLayout/GridLayout.js +1 -1
  34. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  35. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  36. package/dist/components/GridLayout/GridTitle.js +0 -1
  37. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  38. package/dist/components/Panel/Panel.d.ts.map +1 -1
  39. package/dist/components/Panel/Panel.js +1 -0
  40. package/dist/components/Panel/Panel.js.map +1 -1
  41. package/dist/components/Panel/PanelHeader.d.ts +5 -3
  42. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  43. package/dist/components/Panel/PanelHeader.js +8 -4
  44. package/dist/components/Panel/PanelHeader.js.map +1 -1
  45. package/dist/components/Panel/PanelLinks.d.ts +5 -0
  46. package/dist/components/Panel/PanelLinks.d.ts.map +1 -0
  47. package/dist/components/Panel/PanelLinks.js +124 -0
  48. package/dist/components/Panel/PanelLinks.js.map +1 -0
  49. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  50. package/dist/components/PanelDrawer/PanelEditorForm.js +34 -10
  51. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  52. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
  53. package/dist/components/PanelDrawer/PanelPreview.js +1 -2
  54. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  55. package/dist/components/PanelDrawer/usePanelEditor.d.ts +1 -0
  56. package/dist/components/PanelDrawer/usePanelEditor.d.ts.map +1 -1
  57. package/dist/components/PanelDrawer/usePanelEditor.js +9 -6
  58. package/dist/components/PanelDrawer/usePanelEditor.js.map +1 -1
  59. package/dist/components/index.d.ts +0 -2
  60. package/dist/components/index.d.ts.map +1 -1
  61. package/dist/components/index.js +0 -2
  62. package/dist/components/index.js.map +1 -1
  63. package/dist/constants/user-interface-text.d.ts +0 -2
  64. package/dist/constants/user-interface-text.d.ts.map +1 -1
  65. package/dist/constants/user-interface-text.js +0 -2
  66. package/dist/constants/user-interface-text.js.map +1 -1
  67. package/dist/context/DatasourceStoreProvider.js +3 -1
  68. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  69. package/dist/utils/index.d.ts +0 -1
  70. package/dist/utils/index.d.ts.map +1 -1
  71. package/dist/utils/index.js +0 -1
  72. package/dist/utils/index.js.map +1 -1
  73. package/dist/validation/panel.d.ts +51 -3
  74. package/dist/validation/panel.d.ts.map +1 -1
  75. package/dist/validation/panel.js +12 -2
  76. package/dist/validation/panel.js.map +1 -1
  77. package/package.json +6 -6
  78. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +0 -216
  79. package/dist/cjs/components/TimeRangeControls/index.js +0 -30
  80. package/dist/cjs/components/ToolbarIconButton/ToolbarIconButton.js +0 -40
  81. package/dist/cjs/components/ToolbarIconButton/index.js +0 -30
  82. package/dist/cjs/utils/time.js +0 -29
  83. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +0 -13
  84. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +0 -1
  85. package/dist/components/TimeRangeControls/TimeRangeControls.js +0 -192
  86. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +0 -1
  87. package/dist/components/TimeRangeControls/index.d.ts +0 -2
  88. package/dist/components/TimeRangeControls/index.d.ts.map +0 -1
  89. package/dist/components/TimeRangeControls/index.js +0 -15
  90. package/dist/components/TimeRangeControls/index.js.map +0 -1
  91. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts +0 -6
  92. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts.map +0 -1
  93. package/dist/components/ToolbarIconButton/ToolbarIconButton.js +0 -32
  94. package/dist/components/ToolbarIconButton/ToolbarIconButton.js.map +0 -1
  95. package/dist/components/ToolbarIconButton/index.d.ts +0 -2
  96. package/dist/components/ToolbarIconButton/index.d.ts.map +0 -1
  97. package/dist/components/ToolbarIconButton/index.js +0 -15
  98. package/dist/components/ToolbarIconButton/index.js.map +0 -1
  99. package/dist/utils/time.d.ts +0 -5
  100. package/dist/utils/time.d.ts.map +0 -1
  101. package/dist/utils/time.js +0 -23
  102. package/dist/utils/time.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/DatasourceStoreProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactNode, useCallback, useMemo, useState } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n ProjectDatasource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasource,\n useEvent,\n EphemeralDashboardResource,\n DatasourceDefinition,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource | EphemeralDashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\nexport type BuildDatasourceProxyUrlParams = {\n project?: string;\n dashboard?: string;\n name: string;\n};\n\nexport type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;\n\n/**\n * The external API for fetching datasource resources\n */\nexport interface DatasourceApi {\n buildProxyUrl?: BuildDatasourceProxyUrlFunc;\n\n getDatasource: (project: string, selector: DatasourceSelector) => Promise<ProjectDatasource | undefined>;\n\n getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasource | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<ProjectDatasource[]>;\n\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps) {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginKind: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata('Datasource'),\n project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginKind),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.kind === datasourcePluginKind);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource(\n dashboardResource.kind === 'Dashboard'\n ? ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as DashboardResource)\n : ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as EphemeralDashboardResource)\n );\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({ spec, selectorName, selectorGroup: group, editLink, saved }: AddDatasouceSelectItemParams) => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && (isFirst || isExplicitDefault)) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useState","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","buildDatasourceProxyUrl","dashboard","name","datasource","getDatasource","globalDatasource","getGlobalDatasource","Error","kind","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","result","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6C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IAEA,OAAO;QAAE3B;QAASC;IAAQ;AAC5B"}
1
+ {"version":3,"sources":["../../src/context/DatasourceStoreProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactNode, useCallback, useMemo, useState } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n ProjectDatasource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasource,\n useEvent,\n EphemeralDashboardResource,\n DatasourceDefinition,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource | EphemeralDashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\nexport type BuildDatasourceProxyUrlParams = {\n project?: string;\n dashboard?: string;\n name: string;\n};\n\nexport type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;\n\n/**\n * The external API for fetching datasource resources\n */\nexport interface DatasourceApi {\n buildProxyUrl?: BuildDatasourceProxyUrlFunc;\n\n getDatasource: (project: string, selector: DatasourceSelector) => Promise<ProjectDatasource | undefined>;\n\n getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasource | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<ProjectDatasource[]>;\n\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps) {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginKind: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata(['Datasource']),\n project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginKind),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.kind === datasourcePluginKind);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource(\n dashboardResource.kind === 'Dashboard'\n ? ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as DashboardResource)\n : ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as EphemeralDashboardResource)\n );\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({ spec, selectorName, selectorGroup: group, editLink, saved }: AddDatasouceSelectItemParams) => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && (isFirst || isExplicitDefault)) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useState","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","buildDatasourceProxyUrl","dashboard","name","datasource","getDatasource","globalDatasource","getGlobalDatasource","Error","kind","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","result","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAoBA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAClE,SAOEC,QAAQ,QAGH,mBAAmB;AAC1B,SACEC,sBAAsB,EAGtBC,iBAAiB,QAGZ,4BAA4B;AAkC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gCAAAA,qBAAsBiC;YAC5BiC,YAAYF;YACZ9B;YACApC,UAAU;gBACRe,MAAMb,KAAKgB,MAAM,CAACH,IAAI;gBACtBN,MAAM0B;gBACN2B;YACF;QACF;QACAN,UAAUa,GAAG,CAAClC;QAEd,MAAMmC,oBAAoB,CAACJ,gBAAgBhE,KAAKoD,OAAO,IAAI,CAACK;QAC5D,IAAI5B,OAAO,CAAC,EAAE,IAAK2B,CAAAA,WAAWY,iBAAgB,GAAI;YAChD,8GAA8G;YAC9GvC,OAAO,CAAC,EAAE,CAACiC,KAAK,GAAG;gBACjB;oBACEvD,MAAM,CAAC,SAAS,EAAE0B,aAAa,MAAM,EAAE2B,MAAM,CAAC,CAAC;oBAC/C9D,UAAU;wBACRe,MAAMb,KAAKgB,MAAM,CAACH,IAAI;oBACxB;gBACF;aACD;YACD,kGAAkG;YAClG,wGAAwG;YACxG,gDAAgD;YAChD4C,uBAAuBW;QACzB;QAEA,qEAAqE;QACrE,IAAIJ,cAAc;YAChB,IAAK,IAAIK,IAAIZ,uBAAuB,IAAI,GAAGY,IAAIV,mBAAmBU,IAAK;oBACpExC;oBAAAA;gBAAAA,CAAAA,CAAAA,oBAAAA,aAAAA,OAAO,CAACwC,EAAE,cAAVxC,iCAAAA,WAAYiC,KAAK,cAAjBjC,8BAAAA,mBAAqB,EAAE,AAAD,EACpByC,MAAM,CAAC,CAACC,OAA+BA,KAAKzE,QAAQ,CAACS,IAAI,KAAK0B,cAC9DuC,OAAO,CAAC,CAACD;oBACRA,KAAKE,UAAU,GAAG;gBACpB;YACJ;QACF;QAEAjB,UAAU;IACZ;IAEA,OAAO;QAAE3B;QAASC;IAAQ;AAC5B"}
@@ -1,3 +1,2 @@
1
1
  export * from './panelUtils';
2
- export * from './time';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC"}
@@ -11,6 +11,5 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  export * from './panelUtils';
14
- export * from './time';
15
14
 
16
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './panelUtils';\nexport * from './time';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,eAAe;AAC7B,cAAc,SAAS"}
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './panelUtils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,eAAe"}
@@ -3,17 +3,65 @@ export declare const panelEditorValidationSchema: z.ZodObject<{
3
3
  name: z.ZodString;
4
4
  groupId: z.ZodNumber;
5
5
  description: z.ZodOptional<z.ZodString>;
6
- type: z.ZodString;
6
+ selection: z.ZodObject<{
7
+ type: z.ZodString;
8
+ kind: z.ZodString;
9
+ }, "strip", z.ZodTypeAny, {
10
+ kind: string;
11
+ type: string;
12
+ }, {
13
+ kind: string;
14
+ type: string;
15
+ }>;
16
+ links: z.ZodOptional<z.ZodArray<z.ZodObject<{
17
+ name: z.ZodOptional<z.ZodString>;
18
+ url: z.ZodString;
19
+ tooltip: z.ZodOptional<z.ZodString>;
20
+ renderVariables: z.ZodOptional<z.ZodBoolean>;
21
+ targetBlank: z.ZodOptional<z.ZodBoolean>;
22
+ }, "strip", z.ZodTypeAny, {
23
+ url: string;
24
+ name?: string | undefined;
25
+ tooltip?: string | undefined;
26
+ renderVariables?: boolean | undefined;
27
+ targetBlank?: boolean | undefined;
28
+ }, {
29
+ url: string;
30
+ name?: string | undefined;
31
+ tooltip?: string | undefined;
32
+ renderVariables?: boolean | undefined;
33
+ targetBlank?: boolean | undefined;
34
+ }>, "many">>;
7
35
  }, "strip", z.ZodTypeAny, {
36
+ selection: {
37
+ kind: string;
38
+ type: string;
39
+ };
8
40
  name: string;
9
41
  groupId: number;
10
- type: string;
11
42
  description?: string | undefined;
43
+ links?: {
44
+ url: string;
45
+ name?: string | undefined;
46
+ tooltip?: string | undefined;
47
+ renderVariables?: boolean | undefined;
48
+ targetBlank?: boolean | undefined;
49
+ }[] | undefined;
12
50
  }, {
51
+ selection: {
52
+ kind: string;
53
+ type: string;
54
+ };
13
55
  name: string;
14
56
  groupId: number;
15
- type: string;
16
57
  description?: string | undefined;
58
+ links?: {
59
+ url: string;
60
+ name?: string | undefined;
61
+ tooltip?: string | undefined;
62
+ renderVariables?: boolean | undefined;
63
+ targetBlank?: boolean | undefined;
64
+ }[] | undefined;
17
65
  }>;
18
66
  export type PanelEditorValidationType = z.infer<typeof panelEditorValidationSchema>;
19
67
  //# sourceMappingURL=panel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../../src/validation/panel.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;EAKtC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
1
+ {"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../../src/validation/panel.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBtC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
@@ -12,10 +12,20 @@
12
12
  // limitations under the License.
13
13
  import { z } from 'zod';
14
14
  export const panelEditorValidationSchema = z.object({
15
- name: z.string().nonempty('Required'),
15
+ name: z.string().min(1, 'Required'),
16
16
  groupId: z.number(),
17
17
  description: z.string().optional(),
18
- type: z.string().nonempty('Required')
18
+ selection: z.object({
19
+ type: z.string(),
20
+ kind: z.string()
21
+ }),
22
+ links: z.array(z.object({
23
+ name: z.string().optional(),
24
+ url: z.string().min(1, 'Required'),
25
+ tooltip: z.string().optional(),
26
+ renderVariables: z.boolean().optional(),
27
+ targetBlank: z.boolean().optional()
28
+ })).optional()
19
29
  });
20
30
 
21
31
  //# sourceMappingURL=panel.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/validation/panel.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { z } from 'zod';\n\nexport const panelEditorValidationSchema = z.object({\n name: z.string().nonempty('Required'),\n groupId: z.number(),\n description: z.string().optional(),\n type: z.string().nonempty('Required'),\n});\n\nexport type PanelEditorValidationType = z.infer<typeof panelEditorValidationSchema>;\n"],"names":["z","panelEditorValidationSchema","object","name","string","nonempty","groupId","number","description","optional","type"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,CAAC,QAAQ,MAAM;AAExB,OAAO,MAAMC,8BAA8BD,EAAEE,MAAM,CAAC;IAClDC,MAAMH,EAAEI,MAAM,GAAGC,QAAQ,CAAC;IAC1BC,SAASN,EAAEO,MAAM;IACjBC,aAAaR,EAAEI,MAAM,GAAGK,QAAQ;IAChCC,MAAMV,EAAEI,MAAM,GAAGC,QAAQ,CAAC;AAC5B,GAAG"}
1
+ {"version":3,"sources":["../../src/validation/panel.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { z } from 'zod';\n\nexport const panelEditorValidationSchema = z.object({\n name: z.string().min(1, 'Required'),\n groupId: z.number(),\n description: z.string().optional(),\n selection: z.object({\n type: z.string(),\n kind: z.string(),\n }),\n links: z\n .array(\n z.object({\n name: z.string().optional(),\n url: z.string().min(1, 'Required'),\n tooltip: z.string().optional(),\n renderVariables: z.boolean().optional(),\n targetBlank: z.boolean().optional(),\n })\n )\n .optional(),\n});\n\nexport type PanelEditorValidationType = z.infer<typeof panelEditorValidationSchema>;\n"],"names":["z","panelEditorValidationSchema","object","name","string","min","groupId","number","description","optional","selection","type","kind","links","array","url","tooltip","renderVariables","boolean","targetBlank"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,CAAC,QAAQ,MAAM;AAExB,OAAO,MAAMC,8BAA8BD,EAAEE,MAAM,CAAC;IAClDC,MAAMH,EAAEI,MAAM,GAAGC,GAAG,CAAC,GAAG;IACxBC,SAASN,EAAEO,MAAM;IACjBC,aAAaR,EAAEI,MAAM,GAAGK,QAAQ;IAChCC,WAAWV,EAAEE,MAAM,CAAC;QAClBS,MAAMX,EAAEI,MAAM;QACdQ,MAAMZ,EAAEI,MAAM;IAChB;IACAS,OAAOb,EACJc,KAAK,CACJd,EAAEE,MAAM,CAAC;QACPC,MAAMH,EAAEI,MAAM,GAAGK,QAAQ;QACzBM,KAAKf,EAAEI,MAAM,GAAGC,GAAG,CAAC,GAAG;QACvBW,SAAShB,EAAEI,MAAM,GAAGK,QAAQ;QAC5BQ,iBAAiBjB,EAAEkB,OAAO,GAAGT,QAAQ;QACrCU,aAAanB,EAAEkB,OAAO,GAAGT,QAAQ;IACnC,IAEDA,QAAQ;AACb,GAAG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/dashboards",
3
- "version": "0.44.0",
3
+ "version": "0.45.0-rc0",
4
4
  "description": "The dashboards feature in Perses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -29,9 +29,9 @@
29
29
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
30
30
  },
31
31
  "dependencies": {
32
- "@perses-dev/components": "0.44.0",
33
- "@perses-dev/core": "0.44.0",
34
- "@perses-dev/plugin-system": "0.44.0",
32
+ "@perses-dev/components": "0.45.0-rc0",
33
+ "@perses-dev/core": "0.45.0-rc0",
34
+ "@perses-dev/plugin-system": "0.45.0-rc0",
35
35
  "@types/react-grid-layout": "^1.3.2",
36
36
  "date-fns": "^2.28.0",
37
37
  "immer": "^9.0.15",
@@ -45,8 +45,8 @@
45
45
  "zustand": "^4.3.3"
46
46
  },
47
47
  "devDependencies": {
48
- "@perses-dev/internal-utils": "0.44.0",
49
- "@perses-dev/storybook": "0.44.0",
48
+ "@perses-dev/internal-utils": "0.45.0-rc0",
49
+ "@perses-dev/storybook": "0.45.0-rc0",
50
50
  "history": "^5.3.0",
51
51
  "intersection-observer": "^0.12.2"
52
52
  },
@@ -1,216 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- DEFAULT_REFRESH_INTERVAL_OPTIONS: function() {
25
- return DEFAULT_REFRESH_INTERVAL_OPTIONS;
26
- },
27
- DEFAULT_TIME_RANGE_OPTIONS: function() {
28
- return DEFAULT_TIME_RANGE_OPTIONS;
29
- },
30
- TimeRangeControls: function() {
31
- return TimeRangeControls;
32
- }
33
- });
34
- const _jsxruntime = require("react/jsx-runtime");
35
- const _Refresh = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Refresh"));
36
- const _material = require("@mui/material");
37
- const _components = require("@perses-dev/components");
38
- const _pluginsystem = require("@perses-dev/plugin-system");
39
- const _core = require("@perses-dev/core");
40
- const _react = require("react");
41
- const _constants = require("../../constants");
42
- const _context = require("../../context");
43
- const _ToolbarIconButton = require("../ToolbarIconButton");
44
- const _useDashboard = require("../../context/useDashboard");
45
- function _interop_require_default(obj) {
46
- return obj && obj.__esModule ? obj : {
47
- default: obj
48
- };
49
- }
50
- const DEFAULT_TIME_RANGE_OPTIONS = [
51
- {
52
- value: {
53
- pastDuration: '5m'
54
- },
55
- display: 'Last 5 minutes'
56
- },
57
- {
58
- value: {
59
- pastDuration: '15m'
60
- },
61
- display: 'Last 15 minutes'
62
- },
63
- {
64
- value: {
65
- pastDuration: '30m'
66
- },
67
- display: 'Last 30 minutes'
68
- },
69
- {
70
- value: {
71
- pastDuration: '1h'
72
- },
73
- display: 'Last 1 hour'
74
- },
75
- {
76
- value: {
77
- pastDuration: '6h'
78
- },
79
- display: 'Last 6 hours'
80
- },
81
- {
82
- value: {
83
- pastDuration: '12h'
84
- },
85
- display: 'Last 12 hours'
86
- },
87
- {
88
- value: {
89
- pastDuration: '24h'
90
- },
91
- display: 'Last 1 day'
92
- },
93
- {
94
- value: {
95
- pastDuration: '7d'
96
- },
97
- display: 'Last 7 days'
98
- },
99
- {
100
- value: {
101
- pastDuration: '14d'
102
- },
103
- display: 'Last 14 days'
104
- }
105
- ];
106
- const DEFAULT_REFRESH_INTERVAL_OPTIONS = [
107
- {
108
- value: {
109
- pastDuration: '0s'
110
- },
111
- display: 'Off'
112
- },
113
- {
114
- value: {
115
- pastDuration: '5s'
116
- },
117
- display: '5s'
118
- },
119
- {
120
- value: {
121
- pastDuration: '10s'
122
- },
123
- display: '10s'
124
- },
125
- {
126
- value: {
127
- pastDuration: '15s'
128
- },
129
- display: '15s'
130
- },
131
- {
132
- value: {
133
- pastDuration: '30s'
134
- },
135
- display: '30s'
136
- },
137
- {
138
- value: {
139
- pastDuration: '60s'
140
- },
141
- display: '1m'
142
- }
143
- ];
144
- const DEFAULT_HEIGHT = '34px';
145
- function TimeRangeControls({ heightPx, showTimeRangeSelector = true, showRefreshButton = true, showRefreshInterval = true, timePresets = DEFAULT_TIME_RANGE_OPTIONS }) {
146
- const { timeRange, setTimeRange, refresh, refreshInterval, setRefreshInterval } = (0, _pluginsystem.useTimeRange)();
147
- // TODO: Remove this since it couples to the dashboard context
148
- const dashboardDuration = (0, _context.useDashboardDuration)();
149
- const { dashboard, setDashboard } = (0, _useDashboard.useDashboard)();
150
- // Convert height to a string, then use the string for styling
151
- const height = heightPx === undefined ? DEFAULT_HEIGHT : `${heightPx}px`;
152
- // add time shortcut if one does not match duration from dashboard JSON
153
- if (!timePresets.some((option)=>option.value.pastDuration === dashboardDuration)) {
154
- if ((0, _core.isDurationString)(dashboardDuration)) {
155
- timePresets.push({
156
- value: {
157
- pastDuration: dashboardDuration
158
- },
159
- display: `Last ${dashboardDuration}`
160
- });
161
- }
162
- }
163
- // set the new refresh interval both in the dashboard context & as query param
164
- const handleRefreshIntervalChange = (0, _react.useCallback)((duration)=>{
165
- setDashboard(dashboard.kind === 'Dashboard' ? {
166
- ...dashboard,
167
- spec: {
168
- ...dashboard.spec,
169
- refreshInterval: duration
170
- }
171
- } : {
172
- ...dashboard,
173
- spec: {
174
- ...dashboard.spec,
175
- refreshInterval: duration
176
- }
177
- });
178
- setRefreshInterval(duration);
179
- }, [
180
- dashboard,
181
- setDashboard,
182
- setRefreshInterval
183
- ]);
184
- return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
185
- direction: "row",
186
- spacing: 1,
187
- children: [
188
- showTimeRangeSelector && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.DateTimeRangePicker, {
189
- timeOptions: timePresets,
190
- value: timeRange,
191
- onChange: setTimeRange,
192
- height: height
193
- }),
194
- showRefreshButton && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.InfoTooltip, {
195
- description: _constants.TOOLTIP_TEXT.refreshDashboard,
196
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_ToolbarIconButton.ToolbarIconButton, {
197
- "aria-label": _constants.TOOLTIP_TEXT.refreshDashboard,
198
- onClick: refresh,
199
- sx: {
200
- height
201
- },
202
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Refresh.default, {})
203
- })
204
- }),
205
- showRefreshInterval && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.InfoTooltip, {
206
- description: _constants.TOOLTIP_TEXT.refreshDashboardInterval,
207
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.RefreshIntervalPicker, {
208
- timeOptions: DEFAULT_REFRESH_INTERVAL_OPTIONS,
209
- value: refreshInterval,
210
- onChange: handleRefreshIntervalChange,
211
- height: height
212
- })
213
- })
214
- ]
215
- });
216
- }
@@ -1,30 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- _export_star(require("./TimeRangeControls"), exports);
18
- function _export_star(from, to) {
19
- Object.keys(from).forEach(function(k) {
20
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
21
- Object.defineProperty(to, k, {
22
- enumerable: true,
23
- get: function() {
24
- return from[k];
25
- }
26
- });
27
- }
28
- });
29
- return from;
30
- }
@@ -1,40 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- Object.defineProperty(exports, "ToolbarIconButton", {
18
- enumerable: true,
19
- get: function() {
20
- return ToolbarIconButton;
21
- }
22
- });
23
- const _jsxruntime = require("react/jsx-runtime");
24
- const _react = require("react");
25
- const _material = require("@mui/material");
26
- function IconButton(props, ref) {
27
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(StyledIconButton, {
28
- ref: ref,
29
- variant: "outlined",
30
- color: "secondary",
31
- ...props
32
- });
33
- }
34
- const StyledIconButton = (0, _material.styled)(_material.Button)(({ theme })=>({
35
- // Using a button with some adjusted styles because it is easier to inherit
36
- // styling and variants from themes than with an IconButton.
37
- padding: theme.spacing(0.5),
38
- minWidth: 'auto'
39
- }));
40
- const ToolbarIconButton = /*#__PURE__*/ (0, _react.forwardRef)(IconButton);
@@ -1,30 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- _export_star(require("./ToolbarIconButton"), exports);
18
- function _export_star(from, to) {
19
- Object.keys(from).forEach(function(k) {
20
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
21
- Object.defineProperty(to, k, {
22
- enumerable: true,
23
- get: function() {
24
- return from[k];
25
- }
26
- });
27
- }
28
- });
29
- return from;
30
- }
@@ -1,29 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- Object.defineProperty(exports, "useSuggestedStepMs", {
18
- enumerable: true,
19
- get: function() {
20
- return useSuggestedStepMs;
21
- }
22
- });
23
- const _core = require("@perses-dev/core");
24
- const _pluginsystem = require("@perses-dev/plugin-system");
25
- function useSuggestedStepMs(width) {
26
- const { absoluteTimeRange } = (0, _pluginsystem.useTimeRange)();
27
- if (width === undefined) return 0;
28
- return (0, _core.getSuggestedStepMs)(absoluteTimeRange, width);
29
- }
@@ -1,13 +0,0 @@
1
- import { TimeOption } from '@perses-dev/components';
2
- export declare const DEFAULT_TIME_RANGE_OPTIONS: TimeOption[];
3
- export declare const DEFAULT_REFRESH_INTERVAL_OPTIONS: TimeOption[];
4
- interface TimeRangeControlsProps {
5
- heightPx?: number;
6
- showTimeRangeSelector?: boolean;
7
- showRefreshButton?: boolean;
8
- showRefreshInterval?: boolean;
9
- timePresets?: TimeOption[];
10
- }
11
- export declare function TimeRangeControls({ heightPx, showTimeRangeSelector, showRefreshButton, showRefreshInterval, timePresets, }: TimeRangeControlsProps): import("react/jsx-runtime").JSX.Element;
12
- export {};
13
- //# sourceMappingURL=TimeRangeControls.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TimeRangeControls.d.ts","sourceRoot":"","sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"names":[],"mappings":"AAeA,OAAO,EAA2D,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAS7G,eAAO,MAAM,0BAA0B,EAAE,UAAU,EAUlD,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE,UAAU,EAOxD,CAAC;AAIF,UAAU,sBAAsB;IAE9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC5B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,qBAA4B,EAC5B,iBAAwB,EACxB,mBAA0B,EAC1B,WAAwC,GACzC,EAAE,sBAAsB,2CAoExB"}