@perses-dev/prometheus-plugin 0.52.1 → 0.53.0

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 (143) hide show
  1. package/__mf/js/Prometheus.712b445d.js +5 -0
  2. package/__mf/js/async/1101.9cf067ee.js +73 -0
  3. package/__mf/js/async/1441.c735f7dd.js +1 -0
  4. package/__mf/js/async/1576.8eac7ce9.js +1 -0
  5. package/__mf/js/async/1964.1d168a86.js +2 -0
  6. package/__mf/js/async/212.69f85c2b.js +1 -0
  7. package/__mf/js/async/2188.d2c5eadd.js +1 -0
  8. package/__mf/js/async/2292.57d8fd0d.js +2 -0
  9. package/__mf/js/async/2675.27451820.js +1 -0
  10. package/__mf/js/async/3224.b63f87bf.js +1 -0
  11. package/__mf/js/async/3507.f1653337.js +101 -0
  12. package/__mf/js/async/3863.7192dfdf.js +2 -0
  13. package/__mf/js/async/3960.3eedafbd.js +2 -0
  14. package/__mf/js/async/3980.0b0d272c.js +2 -0
  15. package/__mf/js/async/4062.06f48b93.js +1 -0
  16. package/__mf/js/async/4075.88e3f633.js +1 -0
  17. package/__mf/js/async/4238.422a1b1c.js +1 -0
  18. package/__mf/js/async/4323.fdf7d039.js +1 -0
  19. package/__mf/js/async/4368.5aeca58a.js +2 -0
  20. package/__mf/js/async/4368.5aeca58a.js.LICENSE.txt +15 -0
  21. package/__mf/js/async/4421.39621b12.js +1 -0
  22. package/__mf/js/async/4535.f24704ea.js +1 -0
  23. package/__mf/js/async/4665.cad36935.js +1 -0
  24. package/__mf/js/async/5214.0fca84ed.js +1 -0
  25. package/__mf/js/async/5257.ce463cb7.js +1 -0
  26. package/__mf/js/async/537.82230699.js +1 -0
  27. package/__mf/js/async/5409.955ffd51.js +1 -0
  28. package/__mf/js/async/5614.cce8ba96.js +1 -0
  29. package/__mf/js/async/5724.794828e3.js +1 -0
  30. package/__mf/js/async/5774.a3fae698.js +1 -0
  31. package/__mf/js/async/5790.a9b31ca8.js +1 -0
  32. package/__mf/js/async/5876.1976752d.js +2 -0
  33. package/__mf/js/async/{3057.e568f9b6.js.LICENSE.txt → 5876.1976752d.js.LICENSE.txt} +1 -23
  34. package/__mf/js/async/5981.eb502d27.js +2 -0
  35. package/__mf/js/async/6292.2afe0c6d.js +1 -0
  36. package/__mf/js/async/6377.c40920f2.js +2 -0
  37. package/__mf/js/async/6441.38c30276.js +7 -0
  38. package/__mf/js/async/6441.38c30276.js.LICENSE.txt +21 -0
  39. package/__mf/js/async/6770.7099bb3b.js +1 -0
  40. package/__mf/js/async/684.f7b5c16e.js +1 -0
  41. package/__mf/js/async/694.8462a746.js +1 -0
  42. package/__mf/js/async/7272.6fa2f127.js +1 -0
  43. package/__mf/js/async/7376.2e948f2b.js +1 -0
  44. package/__mf/js/async/738.a1ffff79.js +1 -0
  45. package/__mf/js/async/7740.a8777825.js +1 -0
  46. package/__mf/js/async/8045.7f554a45.js +10 -0
  47. package/__mf/js/async/8216.e689c178.js +1 -0
  48. package/__mf/js/async/8488.cbbe542b.js +1 -0
  49. package/__mf/js/async/8587.40df6f5c.js +1 -0
  50. package/__mf/js/async/8706.9a6f6579.js +1 -0
  51. package/__mf/js/async/8930.700a5439.js +1 -0
  52. package/__mf/js/async/9173.915b80af.js +2 -0
  53. package/__mf/js/async/9550.642ce5ad.js +38 -0
  54. package/__mf/js/async/9817.70eae424.js +1 -0
  55. package/__mf/js/async/__federation_expose_PrometheusDatasource.71aecfaf.js +1 -0
  56. package/__mf/js/async/__federation_expose_PrometheusExplorer.80dd9b47.js +1 -0
  57. package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.e7eaadbd.js +1 -0
  58. package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.24d74e40.js +1 -0
  59. package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.ea97322b.js +1 -0
  60. package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.90b49f7e.js +1 -0
  61. package/__mf/js/main.61a2057a.js +5 -0
  62. package/lib/cjs/components/PromQLEditor.js +1 -0
  63. package/lib/cjs/components/TreeNode.js +9 -1
  64. package/lib/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +40 -9
  65. package/lib/components/PromQLEditor.d.ts.map +1 -1
  66. package/lib/components/PromQLEditor.js +1 -0
  67. package/lib/components/PromQLEditor.js.map +1 -1
  68. package/lib/components/TreeNode.js +9 -1
  69. package/lib/components/TreeNode.js.map +1 -1
  70. package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  71. package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +40 -9
  72. package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  73. package/mf-manifest.json +262 -483
  74. package/mf-stats.json +272 -493
  75. package/package.json +6 -6
  76. package/__mf/js/622.cc663737.js +0 -5
  77. package/__mf/js/Prometheus.6aae9c64.js +0 -5
  78. package/__mf/js/async/1465.3b5e12d5.js +0 -1
  79. package/__mf/js/async/1620.6376bd14.js +0 -2
  80. package/__mf/js/async/1964.95da06f6.js +0 -2
  81. package/__mf/js/async/212.bd5d617a.js +0 -1
  82. package/__mf/js/async/2285.15378f70.js +0 -1
  83. package/__mf/js/async/2569.daf868a6.js +0 -10
  84. package/__mf/js/async/2675.99cf926f.js +0 -1
  85. package/__mf/js/async/3057.e568f9b6.js +0 -7
  86. package/__mf/js/async/3090.9fb5fe73.js +0 -2
  87. package/__mf/js/async/3224.23f0dccf.js +0 -1
  88. package/__mf/js/async/3355.a4dbcdb0.js +0 -1
  89. package/__mf/js/async/3818.dde21d04.js +0 -1
  90. package/__mf/js/async/3871.6915e369.js +0 -1
  91. package/__mf/js/async/3960.129d5ef5.js +0 -2
  92. package/__mf/js/async/3980.7cea5715.js +0 -2
  93. package/__mf/js/async/4062.3ab7f987.js +0 -1
  94. package/__mf/js/async/4075.b77ca1c7.js +0 -1
  95. package/__mf/js/async/4238.8e4d29d5.js +0 -1
  96. package/__mf/js/async/4323.4266fd6a.js +0 -1
  97. package/__mf/js/async/4421.42e889f6.js +0 -1
  98. package/__mf/js/async/5214.027c4332.js +0 -1
  99. package/__mf/js/async/528.d364bb0e.js +0 -1
  100. package/__mf/js/async/5345.1f4fc17b.js +0 -1
  101. package/__mf/js/async/537.6911ea2e.js +0 -1
  102. package/__mf/js/async/5503.a728b5d7.js +0 -1
  103. package/__mf/js/async/5724.6ee6ec51.js +0 -1
  104. package/__mf/js/async/5769.f14c9663.js +0 -1
  105. package/__mf/js/async/5774.9b0b6be1.js +0 -1
  106. package/__mf/js/async/5790.2273e061.js +0 -1
  107. package/__mf/js/async/5913.4e5abd09.js +0 -73
  108. package/__mf/js/async/5914.bd342d22.js +0 -74
  109. package/__mf/js/async/5981.40bed0d0.js +0 -2
  110. package/__mf/js/async/6292.7b8efa78.js +0 -1
  111. package/__mf/js/async/6377.ca974d89.js +0 -2
  112. package/__mf/js/async/6770.adb1c939.js +0 -1
  113. package/__mf/js/async/684.ca510333.js +0 -1
  114. package/__mf/js/async/694.f861d67c.js +0 -1
  115. package/__mf/js/async/7272.a763aa92.js +0 -1
  116. package/__mf/js/async/7376.c7eb05b9.js +0 -1
  117. package/__mf/js/async/738.aca54e25.js +0 -1
  118. package/__mf/js/async/7740.0c5363fd.js +0 -1
  119. package/__mf/js/async/8488.5237550f.js +0 -1
  120. package/__mf/js/async/8587.4891ea90.js +0 -1
  121. package/__mf/js/async/8930.9fbbc975.js +0 -1
  122. package/__mf/js/async/8980.afe002d4.js +0 -28
  123. package/__mf/js/async/9173.e8fbead5.js +0 -2
  124. package/__mf/js/async/9550.e19763f8.js +0 -38
  125. package/__mf/js/async/__federation_expose_PrometheusDatasource.f9c8cf41.js +0 -1
  126. package/__mf/js/async/__federation_expose_PrometheusExplorer.171d04eb.js +0 -1
  127. package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.8551745e.js +0 -1
  128. package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.a4085adb.js +0 -1
  129. package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.46f99477.js +0 -1
  130. package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.fc3c5730.js +0 -1
  131. package/__mf/js/main.1c9e712b.js +0 -1
  132. /package/__mf/css/async/{5263.dacad691.css → 1576.dacad691.css} +0 -0
  133. /package/__mf/css/async/{6759.dacad691.css → 2188.dacad691.css} +0 -0
  134. /package/__mf/js/async/{5913.4e5abd09.js.LICENSE.txt → 1101.9cf067ee.js.LICENSE.txt} +0 -0
  135. /package/__mf/js/async/{1964.95da06f6.js.LICENSE.txt → 1964.1d168a86.js.LICENSE.txt} +0 -0
  136. /package/__mf/js/async/{3090.9fb5fe73.js.LICENSE.txt → 2292.57d8fd0d.js.LICENSE.txt} +0 -0
  137. /package/__mf/js/async/{1620.6376bd14.js.LICENSE.txt → 3863.7192dfdf.js.LICENSE.txt} +0 -0
  138. /package/__mf/js/async/{3960.129d5ef5.js.LICENSE.txt → 3960.3eedafbd.js.LICENSE.txt} +0 -0
  139. /package/__mf/js/async/{3980.7cea5715.js.LICENSE.txt → 3980.0b0d272c.js.LICENSE.txt} +0 -0
  140. /package/__mf/js/async/{5981.40bed0d0.js.LICENSE.txt → 5981.eb502d27.js.LICENSE.txt} +0 -0
  141. /package/__mf/js/async/{6377.ca974d89.js.LICENSE.txt → 6377.c40920f2.js.LICENSE.txt} +0 -0
  142. /package/__mf/js/async/{2569.daf868a6.js.LICENSE.txt → 8045.7f554a45.js.LICENSE.txt} +0 -0
  143. /package/__mf/js/async/{9173.e8fbead5.js.LICENSE.txt → 9173.915b80af.js.LICENSE.txt} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/TreeNode.tsx"],"sourcesContent":["// Copyright 2025 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\n// Forked from https://github.com/prometheus/prometheus/blob/65f610353919b1c7b42d3776c3a95b68046a6bba/web/ui/mantine-ui/src/pages/query/TreeNode.tsx\n\nimport { Box, CircularProgress, List, ListItem, Stack, Tooltip, Typography, useTheme } from '@mui/material';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport { ReactElement, useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';\nimport AlertCircle from 'mdi-material-ui/AlertCircle';\nimport { StatusError } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector } from '../model';\nimport ASTNode, { nodeType } from './promql/ast';\nimport { escapeString, getNodeChildren } from './promql/utils';\nimport { formatNode } from './promql/format';\nimport serializeNode from './promql/serialize';\nimport { functionSignatures } from './promql/functionSignatures';\nimport { useInstantQuery } from './query';\n\n// The indentation factor for each level of the tree.\nconst nodeIndent = 5;\nconst connectorWidth = nodeIndent * 5;\n\n// max number of label names and values to show in the individual query status\nconst maxLabelNames = 10;\nconst maxLabelValues = 10;\n\ntype NodeState = 'waiting' | 'running' | 'error' | 'success';\n\n// mergeChildStates basically returns the \"worst\" state found among the children.\nconst mergeChildStates = (states: NodeState[]): NodeState => {\n if (states.includes('error')) {\n return 'error';\n }\n if (states.includes('waiting')) {\n return 'waiting';\n }\n if (states.includes('running')) {\n return 'running';\n }\n\n return 'success';\n};\n\ninterface TreeNodeProps {\n // The AST node to render.\n node: ASTNode;\n // The parent element of this node.\n parentEl?: HTMLDivElement | null;\n // Used to compute the position of the connector line between this node and its parent.\n reverse: boolean;\n // Datasource used for the node's individual query.\n datasource: PrometheusDatasourceSelector;\n // The index of this node in its parent's children.\n // Used to render the node's individual query.\n childIdx: number;\n // Function to report the node state to the parent.\n // Used to render the node's individual query.\n reportNodeState?: (childIdx: number, state: NodeState) => void;\n}\n\nexport default function TreeNode({\n node,\n parentEl,\n reverse,\n datasource,\n childIdx,\n reportNodeState,\n}: TreeNodeProps): ReactElement {\n const theme = useTheme();\n const children = getNodeChildren(node);\n\n // A normal ref won't work properly here because the ref's `current` property\n // going from `null` to defined won't trigger a re-render of the child\n // component, since it's not a React state update. So we manually have to\n // create a state update using a callback ref. See also\n // https://tkdodo.eu/blog/avoiding-use-effect-with-callback-refs\n const [nodeEl, setNodeEl] = useState<HTMLDivElement | null>(null);\n const nodeRef = useCallback((node: HTMLDivElement) => setNodeEl(node), []);\n\n const [resultStats, setResultStats] = useState<{\n numSeries: number;\n labelExamples: Record<string, Array<{ value: string; count: number }>>;\n sortedLabelCards: Array<[string, number]>;\n }>({\n numSeries: 0,\n labelExamples: {},\n sortedLabelCards: [],\n });\n\n const [connectorStyle, setConnectorStyle] = useState({\n borderColor: theme.palette.grey['500'],\n borderLeftStyle: 'solid',\n borderLeftWidth: 2,\n width: connectorWidth,\n left: -connectorWidth,\n });\n\n const [childStates, setChildStates] = useState<NodeState[]>(children.map(() => 'waiting'));\n const mergedChildState = useMemo(() => mergeChildStates(childStates), [childStates]);\n\n // Optimize range vector selector fetches to give us the info we're looking for\n // more cheaply. E.g. 'foo[7w]' can be expensive to fully fetch, but wrapping it\n // in 'last_over_time(foo[7w])' is cheaper and also gives us all the info we\n // need (number of series and labels).\n let queryNode = node;\n if (queryNode.type === nodeType.matrixSelector) {\n queryNode = {\n type: nodeType.call,\n func: functionSignatures.last_over_time!,\n args: [node],\n };\n }\n\n // Individual query for the current node\n const {\n data: instantQueryResponse,\n isFetching,\n error,\n } = useInstantQuery(serializeNode(queryNode) ?? '', datasource, mergedChildState === 'success');\n\n // report the node state to the parent\n useEffect(() => {\n if (reportNodeState) {\n if (mergedChildState === 'error' || error) {\n reportNodeState(childIdx, 'error');\n } else if (isFetching) {\n reportNodeState(childIdx, 'running');\n }\n }\n }, [mergedChildState, error, isFetching, reportNodeState, childIdx]);\n\n // This function is passed down to the child nodes so they can report their state.\n const childReportNodeState = useCallback(\n (childIdx: number, state: NodeState) => {\n setChildStates((prev) => {\n const newStates = [...prev];\n newStates[childIdx] = state;\n return newStates;\n });\n },\n [setChildStates]\n );\n\n // Update the size and position of tree connector lines based on the node's and its parent's position.\n useLayoutEffect(() => {\n if (parentEl === undefined) {\n // We're the root node.\n return;\n }\n\n if (parentEl === null || nodeEl === null) {\n // Either of the two connected nodes hasn't been rendered yet.\n return;\n }\n\n const parentRect = parentEl.getBoundingClientRect();\n const nodeRect = nodeEl.getBoundingClientRect();\n if (reverse) {\n setConnectorStyle((prevStyle) => ({\n ...prevStyle,\n top: 'calc(50% - 1px)',\n bottom: nodeRect.bottom - parentRect.top,\n borderTopLeftRadius: 10,\n borderTopStyle: 'solid',\n borderBottomLeftRadius: undefined,\n }));\n } else {\n setConnectorStyle((prevStyle) => ({\n ...prevStyle,\n top: parentRect.bottom - nodeRect.top,\n bottom: 'calc(50% - 1px)',\n borderBottomLeftRadius: 10,\n borderBottomStyle: 'solid',\n borderTopLeftRadius: undefined,\n }));\n }\n }, [parentEl, nodeEl, reverse, nodeRef, setConnectorStyle]);\n\n // Update the node info state based on the query result.\n useEffect(() => {\n if (instantQueryResponse?.status !== 'success') {\n return;\n }\n\n if (reportNodeState) {\n reportNodeState(childIdx, 'success');\n }\n\n let resultSeries = 0;\n // labelValuesByName records the number of times each label value appears for each label name.\n const labelValuesByName: Record<string, Record<string, number>> = {};\n const { resultType, result } = instantQueryResponse.data;\n\n if (resultType === 'scalar' || resultType === 'string') {\n resultSeries = 1;\n } else if (result && result.length > 0) {\n resultSeries = result.length;\n result.forEach((s) => {\n Object.entries(s.metric).forEach(([ln, lv]) => {\n // TODO: If we ever want to include __name__ here again, we cannot use the\n // last_over_time(foo[7d]) optimization since that removes the metric name.\n if (ln !== '__name__') {\n labelValuesByName[ln] = labelValuesByName[ln] ?? {};\n labelValuesByName[ln]![lv] = (labelValuesByName[ln]![lv] ?? 0) + 1;\n }\n });\n });\n }\n\n // labelCardinalities records the number of unique label values for each label name.\n const labelCardinalities: Record<string, number> = {};\n // labelExamples records the most common label values for each label name.\n const labelExamples: Record<string, Array<{ value: string; count: number }>> = {};\n Object.entries(labelValuesByName).forEach(([ln, lvs]) => {\n labelCardinalities[ln] = Object.keys(lvs).length;\n // Sort label values by their number of occurrences within this label name.\n labelExamples[ln] = Object.entries(lvs)\n .sort(([, aCnt], [, bCnt]) => bCnt - aCnt)\n .slice(0, maxLabelValues)\n .map(([lv, cnt]) => ({ value: lv, count: cnt }));\n });\n\n setResultStats({\n numSeries: resultSeries,\n sortedLabelCards: Object.entries(labelCardinalities).sort((a, b) => b[1] - a[1]),\n labelExamples,\n });\n }, [instantQueryResponse, reportNodeState, childIdx]);\n\n const innerNode = (\n <Stack direction=\"row\" gap={2}>\n <Box\n ref={nodeRef}\n sx={{\n position: 'relative',\n display: 'inline-block',\n padding: 1,\n marginBottom: 1.5,\n borderRadius: 2,\n backgroundColor: theme.palette.background.code,\n }}\n >\n {parentEl !== undefined && (\n // Connector line between this node and its parent.\n <Box\n sx={{\n position: 'absolute',\n display: 'inline-block',\n ...connectorStyle,\n }}\n />\n )}\n {/* The node (visible box) itself. */}\n {formatNode(node, false, 1)}\n </Box>\n {/* The node's individual query: */}\n <QueryStatus\n mergedChildState={mergedChildState}\n isFetching={isFetching}\n error={error}\n resultStats={resultStats}\n responseTime={instantQueryResponse?.responseTime}\n />\n </Stack>\n );\n\n if (node.type === nodeType.binaryExpr) {\n return (\n <div>\n <Box ml={nodeIndent}>\n <TreeNode\n node={children[0]!}\n parentEl={nodeEl}\n reverse={true}\n datasource={datasource}\n childIdx={0}\n reportNodeState={childReportNodeState}\n />\n </Box>\n {innerNode}\n <Box ml={nodeIndent}>\n <TreeNode\n node={children[1]!}\n parentEl={nodeEl}\n reverse={false}\n datasource={datasource}\n childIdx={1}\n reportNodeState={childReportNodeState}\n />\n </Box>\n </div>\n );\n }\n\n return (\n <div>\n {innerNode}\n {children.map((child, idx) => (\n <Box ml={nodeIndent} key={idx}>\n <TreeNode\n node={child}\n parentEl={nodeEl}\n reverse={false}\n datasource={datasource}\n childIdx={idx}\n reportNodeState={childReportNodeState}\n />\n </Box>\n ))}\n </div>\n );\n}\n\ninterface QueryStatusProps {\n mergedChildState: NodeState;\n isFetching: boolean;\n error: StatusError | null;\n resultStats: {\n numSeries: number;\n labelExamples: Record<string, Array<{ value: string; count: number }>>;\n sortedLabelCards: Array<[string, number]>;\n };\n responseTime?: number;\n}\n\nfunction QueryStatus({\n mergedChildState,\n isFetching,\n error,\n resultStats,\n responseTime,\n}: QueryStatusProps): ReactElement {\n if (mergedChildState === 'waiting') {\n return <ProgressState text=\"Waiting for child query\" />;\n }\n\n if (mergedChildState === 'running') {\n return <ProgressState text=\"Running\" />;\n }\n\n if (mergedChildState === 'error') {\n return (\n <Stack>\n <AlertCircle />\n Blocked on child query error\n </Stack>\n );\n }\n\n if (isFetching) {\n return <ProgressState text=\"Loading\" />;\n }\n\n if (error) {\n return (\n <Box\n display=\"flex\"\n alignItems=\"center\"\n gap={1}\n sx={{ color: (theme) => theme.palette.error.main }}\n marginBottom={1.5}\n >\n <AlertCircle />\n <Typography variant=\"body2\">\n <strong>Error executing query:</strong> {error.message}\n </Typography>\n </Box>\n );\n }\n\n return (\n <Stack direction=\"row\" gap={1} alignItems=\"center\" marginBottom={1.5}>\n <Typography variant=\"body2\" component=\"span\" sx={{ color: (theme) => theme.palette.grey[500] }}>\n {resultStats.numSeries} result{resultStats.numSeries !== 1 && 's'}\n &nbsp;&nbsp;–&nbsp;&nbsp;\n {responseTime ? `${Math.round(responseTime)}ms` : '? ms'}\n {resultStats.sortedLabelCards.length > 0 && <>&nbsp;&nbsp;–</>}\n </Typography>\n {resultStats.sortedLabelCards.slice(0, maxLabelNames).map(([ln, cnt]) => (\n <Tooltip\n key={ln}\n title={\n <Box>\n <List dense>\n {resultStats.labelExamples[ln]?.map(({ value, count }) => (\n <ListItem\n key={value}\n sx={{\n display: 'flex',\n gap: 1,\n py: 0,\n px: 0.5,\n }}\n >\n <CircleIcon sx={{ fontSize: 8 }} />\n <Typography\n variant=\"body2\"\n component=\"span\"\n sx={{\n color: (theme) =>\n theme.palette.mode === 'dark' // TODO we shouldnt have to do that I guess..\n ? theme.palette.warning.dark\n : theme.palette.warning.main,\n fontFamily: 'monospace',\n }}\n >\n {escapeString(value)}\n </Typography>\n <Typography variant=\"body2\" component=\"span\">\n ({count}x)\n </Typography>\n </ListItem>\n ))}\n {cnt > maxLabelValues && (\n <ListItem\n sx={{\n display: 'flex',\n gap: 1,\n py: 0,\n px: 0.5,\n }}\n >\n <CircleIcon sx={{ fontSize: 8 }} />\n <Typography variant=\"body2\">. . .</Typography>\n </ListItem>\n )}\n </List>\n </Box>\n }\n arrow\n >\n <span style={{ cursor: 'pointer', whiteSpace: 'nowrap' }}>\n <Typography\n variant=\"body2\"\n component=\"span\"\n sx={{ fontFamily: 'monospace', color: (theme) => theme.palette.success.main }}\n >\n {ln}\n </Typography>\n <Typography variant=\"body2\" component=\"span\" sx={{ color: (theme) => theme.palette.grey[500] }}>\n : {cnt}\n </Typography>\n </span>\n </Tooltip>\n ))}\n {resultStats.sortedLabelCards.length > maxLabelNames ? (\n <Typography variant=\"body2\">...{resultStats.sortedLabelCards.length - maxLabelNames} more...</Typography>\n ) : null}\n </Stack>\n );\n}\n\nfunction ProgressState({ text }: { text: string }): ReactElement {\n return (\n <Box display=\"flex\" alignItems=\"center\" gap={1} marginBottom={1.5}>\n <CircularProgress size={16} color=\"secondary\" />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {text}...\n </Typography>\n </Box>\n );\n}\n"],"names":["Box","CircularProgress","List","ListItem","Stack","Tooltip","Typography","useTheme","CircleIcon","useCallback","useEffect","useLayoutEffect","useMemo","useState","AlertCircle","nodeType","escapeString","getNodeChildren","formatNode","serializeNode","functionSignatures","useInstantQuery","nodeIndent","connectorWidth","maxLabelNames","maxLabelValues","mergeChildStates","states","includes","TreeNode","node","parentEl","reverse","datasource","childIdx","reportNodeState","theme","children","nodeEl","setNodeEl","nodeRef","resultStats","setResultStats","numSeries","labelExamples","sortedLabelCards","connectorStyle","setConnectorStyle","borderColor","palette","grey","borderLeftStyle","borderLeftWidth","width","left","childStates","setChildStates","map","mergedChildState","queryNode","type","matrixSelector","call","func","last_over_time","args","data","instantQueryResponse","isFetching","error","childReportNodeState","state","prev","newStates","undefined","parentRect","getBoundingClientRect","nodeRect","prevStyle","top","bottom","borderTopLeftRadius","borderTopStyle","borderBottomLeftRadius","borderBottomStyle","status","resultSeries","labelValuesByName","resultType","result","length","forEach","s","Object","entries","metric","ln","lv","labelCardinalities","lvs","keys","sort","aCnt","bCnt","slice","cnt","value","count","a","b","innerNode","direction","gap","ref","sx","position","display","padding","marginBottom","borderRadius","backgroundColor","background","code","QueryStatus","responseTime","binaryExpr","div","ml","child","idx","ProgressState","text","alignItems","color","main","variant","strong","message","component","Math","round","title","dense","py","px","fontSize","mode","warning","dark","fontFamily","arrow","span","style","cursor","whiteSpace","success","size"],"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,oJAAoJ;;AAEpJ,SAASA,GAAG,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,gBAAgB;AAC5G,OAAOC,gBAAgB,yBAAyB;AAChD,SAAuBC,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACjG,OAAOC,iBAAiB,8BAA8B;AAGtD,SAAkBC,QAAQ,QAAQ,eAAe;AACjD,SAASC,YAAY,EAAEC,eAAe,QAAQ,iBAAiB;AAC/D,SAASC,UAAU,QAAQ,kBAAkB;AAC7C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DAC9B,KAAC3I;4CAAWiI,SAAQ;sDAAQ;;;;;;;oBAMtCe,KAAK;8BAEL,cAAA,MAACC;wBAAKC,OAAO;4BAAEC,QAAQ;4BAAWC,YAAY;wBAAS;;0CACrD,KAACpJ;gCACCiI,SAAQ;gCACRG,WAAU;gCACVxB,IAAI;oCAAEmC,YAAY;oCAAahB,OAAO,CAACjG,QAAUA,MAAMa,OAAO,CAAC0G,OAAO,CAACrB,IAAI;gCAAC;0CAE3EtC;;0CAEH,MAAC1F;gCAAWiI,SAAQ;gCAAQG,WAAU;gCAAOxB,IAAI;oCAAEmB,OAAO,CAACjG,QAAUA,MAAMa,OAAO,CAACC,IAAI,CAAC,IAAI;gCAAC;;oCAAG;oCAC3FuD;;;;;mBA5DFT;YAiERvD,YAAYI,gBAAgB,CAAC6C,MAAM,GAAGlE,8BACrC,MAAClB;gBAAWiI,SAAQ;;oBAAQ;oBAAI9F,YAAYI,gBAAgB,CAAC6C,MAAM,GAAGlE;oBAAc;;iBAClF;;;AAGV;AAEA,SAAS0G,cAAc,EAAEC,IAAI,EAAoB;IAC/C,qBACE,MAACnI;QAAIoH,SAAQ;QAAOgB,YAAW;QAASpB,KAAK;QAAGM,cAAc;;0BAC5D,KAACrH;gBAAiB2J,MAAM;gBAAIvB,OAAM;;0BAClC,MAAC/H;gBAAWiI,SAAQ;gBAAQF,OAAM;;oBAC/BF;oBAAK;;;;;AAId"}
1
+ {"version":3,"sources":["../../../src/components/TreeNode.tsx"],"sourcesContent":["// Copyright 2025 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\n// Forked from https://github.com/prometheus/prometheus/blob/65f610353919b1c7b42d3776c3a95b68046a6bba/web/ui/mantine-ui/src/pages/query/TreeNode.tsx\n\nimport { Box, CircularProgress, List, ListItem, Stack, Tooltip, Typography, useTheme } from '@mui/material';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport { ReactElement, useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';\nimport AlertCircle from 'mdi-material-ui/AlertCircle';\nimport { StatusError } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector } from '../model';\nimport ASTNode, { nodeType } from './promql/ast';\nimport { escapeString, getNodeChildren } from './promql/utils';\nimport { formatNode } from './promql/format';\nimport serializeNode from './promql/serialize';\nimport { functionSignatures } from './promql/functionSignatures';\nimport { useInstantQuery } from './query';\n\n// The indentation factor for each level of the tree.\nconst nodeIndent = 5;\nconst connectorWidth = nodeIndent * 5;\n\n// max number of label names and values to show in the individual query status\nconst maxLabelNames = 10;\nconst maxLabelValues = 10;\n\ntype NodeState = 'waiting' | 'running' | 'error' | 'success';\n\n// mergeChildStates basically returns the \"worst\" state found among the children.\nconst mergeChildStates = (states: NodeState[]): NodeState => {\n if (states.includes('error')) {\n return 'error';\n }\n if (states.includes('waiting')) {\n return 'waiting';\n }\n if (states.includes('running')) {\n return 'running';\n }\n\n return 'success';\n};\n\ninterface TreeNodeProps {\n // The AST node to render.\n node: ASTNode;\n // The parent element of this node.\n parentEl?: HTMLDivElement | null;\n // Used to compute the position of the connector line between this node and its parent.\n reverse: boolean;\n // Datasource used for the node's individual query.\n datasource: PrometheusDatasourceSelector;\n // The index of this node in its parent's children.\n // Used to render the node's individual query.\n childIdx: number;\n // Function to report the node state to the parent.\n // Used to render the node's individual query.\n reportNodeState?: (childIdx: number, state: NodeState) => void;\n}\n\nexport default function TreeNode({\n node,\n parentEl,\n reverse,\n datasource,\n childIdx,\n reportNodeState,\n}: TreeNodeProps): ReactElement {\n const theme = useTheme();\n const children = getNodeChildren(node);\n\n // A normal ref won't work properly here because the ref's `current` property\n // going from `null` to defined won't trigger a re-render of the child\n // component, since it's not a React state update. So we manually have to\n // create a state update using a callback ref. See also\n // https://tkdodo.eu/blog/avoiding-use-effect-with-callback-refs\n const [nodeEl, setNodeEl] = useState<HTMLDivElement | null>(null);\n const nodeRef = useCallback((node: HTMLDivElement) => setNodeEl(node), []);\n\n const [resultStats, setResultStats] = useState<{\n numSeries: number;\n labelExamples: Record<string, Array<{ value: string; count: number }>>;\n sortedLabelCards: Array<[string, number]>;\n }>({\n numSeries: 0,\n labelExamples: {},\n sortedLabelCards: [],\n });\n\n const [connectorStyle, setConnectorStyle] = useState({\n borderColor: theme.palette.grey['500'],\n borderLeftStyle: 'solid',\n borderLeftWidth: 2,\n width: connectorWidth,\n left: -connectorWidth,\n });\n\n const [childStates, setChildStates] = useState<NodeState[]>(children.map(() => 'waiting'));\n const mergedChildState = useMemo(() => mergeChildStates(childStates), [childStates]);\n\n // Optimize range vector selector fetches to give us the info we're looking for\n // more cheaply. E.g. 'foo[7w]' can be expensive to fully fetch, but wrapping it\n // in 'last_over_time(foo[7w])' is cheaper and also gives us all the info we\n // need (number of series and labels).\n let queryNode = node;\n if (queryNode.type === nodeType.matrixSelector) {\n queryNode = {\n type: nodeType.call,\n func: functionSignatures.last_over_time!,\n args: [node],\n };\n }\n\n // Individual query for the current node\n const {\n data: instantQueryResponse,\n isFetching,\n error,\n } = useInstantQuery(serializeNode(queryNode) ?? '', datasource, mergedChildState === 'success');\n\n // report the node state to the parent\n useEffect(() => {\n if (reportNodeState) {\n if (mergedChildState === 'error' || error) {\n reportNodeState(childIdx, 'error');\n } else if (isFetching) {\n reportNodeState(childIdx, 'running');\n }\n }\n }, [mergedChildState, error, isFetching, reportNodeState, childIdx]);\n\n // This function is passed down to the child nodes so they can report their state.\n const childReportNodeState = useCallback(\n (childIdx: number, state: NodeState) => {\n setChildStates((prev) => {\n const newStates = [...prev];\n newStates[childIdx] = state;\n return newStates;\n });\n },\n [setChildStates]\n );\n\n // Update the size and position of tree connector lines based on the node's and its parent's position.\n useLayoutEffect(() => {\n if (parentEl === undefined) {\n // We're the root node.\n return;\n }\n\n if (parentEl === null || nodeEl === null) {\n // Either of the two connected nodes hasn't been rendered yet.\n return;\n }\n\n const parentRect = parentEl.getBoundingClientRect();\n const nodeRect = nodeEl.getBoundingClientRect();\n if (reverse) {\n setConnectorStyle((prevStyle) => ({\n ...prevStyle,\n top: 'calc(50% - 1px)',\n bottom: nodeRect.bottom - parentRect.top,\n borderTopLeftRadius: 10,\n borderTopStyle: 'solid',\n borderBottomLeftRadius: undefined,\n }));\n } else {\n setConnectorStyle((prevStyle) => ({\n ...prevStyle,\n top: parentRect.bottom - nodeRect.top,\n bottom: 'calc(50% - 1px)',\n borderBottomLeftRadius: 10,\n borderBottomStyle: 'solid',\n borderTopLeftRadius: undefined,\n }));\n }\n }, [parentEl, nodeEl, reverse, nodeRef, setConnectorStyle]);\n\n // Update the node info state based on the query result.\n useEffect(() => {\n if (instantQueryResponse?.status !== 'success') {\n return;\n }\n\n if (reportNodeState) {\n reportNodeState(childIdx, 'success');\n }\n\n let resultSeries = 0;\n // labelValuesByName records the number of times each label value appears for each label name.\n const labelValuesByName: Record<string, Record<string, number>> = {};\n const { resultType, result } = instantQueryResponse.data;\n\n if (resultType === 'scalar' || resultType === 'string') {\n resultSeries = 1;\n } else if (result && result.length > 0) {\n resultSeries = result.length;\n result.forEach((s) => {\n Object.entries(s.metric).forEach(([ln, lv]) => {\n // TODO: If we ever want to include __name__ here again, we cannot use the\n // last_over_time(foo[7d]) optimization since that removes the metric name.\n if (ln !== '__name__') {\n labelValuesByName[ln] = labelValuesByName[ln] ?? {};\n labelValuesByName[ln]![lv] = (labelValuesByName[ln]![lv] ?? 0) + 1;\n }\n });\n });\n }\n\n // labelCardinalities records the number of unique label values for each label name.\n const labelCardinalities: Record<string, number> = {};\n // labelExamples records the most common label values for each label name.\n const labelExamples: Record<string, Array<{ value: string; count: number }>> = {};\n Object.entries(labelValuesByName).forEach(([ln, lvs]) => {\n labelCardinalities[ln] = Object.keys(lvs).length;\n // Sort label values by their number of occurrences within this label name.\n labelExamples[ln] = Object.entries(lvs)\n .sort(([, aCnt], [, bCnt]) => bCnt - aCnt)\n .slice(0, maxLabelValues)\n .map(([lv, cnt]) => ({ value: lv, count: cnt }));\n });\n\n setResultStats({\n numSeries: resultSeries,\n sortedLabelCards: Object.entries(labelCardinalities).sort((a, b) => b[1] - a[1]),\n labelExamples,\n });\n }, [instantQueryResponse, reportNodeState, childIdx]);\n\n const innerNode = (\n <Stack direction=\"row\" gap={2}>\n <Box\n ref={nodeRef}\n sx={{\n position: 'relative',\n display: 'inline-block',\n padding: 1,\n marginBottom: 1.5,\n borderRadius: 2,\n backgroundColor: theme.palette.background.code,\n }}\n >\n {parentEl !== undefined && (\n // Connector line between this node and its parent.\n <Box\n sx={{\n position: 'absolute',\n display: 'inline-block',\n ...connectorStyle,\n }}\n />\n )}\n {/* The node (visible box) itself. */}\n {formatNode(node, false, 1)}\n </Box>\n {/* The node's individual query: */}\n <QueryStatus\n mergedChildState={mergedChildState}\n isFetching={isFetching}\n error={error}\n resultStats={resultStats}\n responseTime={instantQueryResponse?.responseTime}\n />\n </Stack>\n );\n\n if (node.type === nodeType.binaryExpr) {\n return (\n <div>\n <Box ml={nodeIndent}>\n <TreeNode\n node={children[0]!}\n parentEl={nodeEl}\n reverse={true}\n datasource={datasource}\n childIdx={0}\n reportNodeState={childReportNodeState}\n />\n </Box>\n {innerNode}\n <Box ml={nodeIndent}>\n <TreeNode\n node={children[1]!}\n parentEl={nodeEl}\n reverse={false}\n datasource={datasource}\n childIdx={1}\n reportNodeState={childReportNodeState}\n />\n </Box>\n </div>\n );\n }\n\n return (\n <div>\n {innerNode}\n {children.map((child, idx) => (\n <Box ml={nodeIndent} key={idx}>\n <TreeNode\n node={child}\n parentEl={nodeEl}\n reverse={false}\n datasource={datasource}\n childIdx={idx}\n reportNodeState={childReportNodeState}\n />\n </Box>\n ))}\n </div>\n );\n}\n\ninterface QueryStatusProps {\n mergedChildState: NodeState;\n isFetching: boolean;\n error: StatusError | null;\n resultStats: {\n numSeries: number;\n labelExamples: Record<string, Array<{ value: string; count: number }>>;\n sortedLabelCards: Array<[string, number]>;\n };\n responseTime?: number;\n}\n\nfunction QueryStatus({\n mergedChildState,\n isFetching,\n error,\n resultStats,\n responseTime,\n}: QueryStatusProps): ReactElement {\n if (mergedChildState === 'waiting') {\n return <ProgressState text=\"Waiting for child query\" />;\n }\n\n if (mergedChildState === 'running') {\n return <ProgressState text=\"Running\" />;\n }\n\n if (mergedChildState === 'error') {\n return (\n <Stack>\n <AlertCircle />\n Blocked on child query error\n </Stack>\n );\n }\n\n if (isFetching) {\n return <ProgressState text=\"Loading\" />;\n }\n\n if (error) {\n return (\n <Box\n display=\"flex\"\n alignItems=\"center\"\n gap={1}\n sx={{ color: (theme) => theme.palette.error.main }}\n marginBottom={1.5}\n >\n <AlertCircle />\n <Typography variant=\"body2\">\n <strong>Error executing query:</strong> {error.message}\n </Typography>\n </Box>\n );\n }\n\n return (\n <Stack direction=\"row\" gap={1} alignItems=\"center\" marginBottom={1.5}>\n <Typography variant=\"body2\" component=\"span\" sx={{ color: (theme) => theme.palette.grey[500] }}>\n {resultStats.numSeries} result{resultStats.numSeries !== 1 && 's'}\n &nbsp;&nbsp;–&nbsp;&nbsp;\n {responseTime ? `${Math.round(responseTime)}ms` : '? ms'}\n {resultStats.sortedLabelCards.length > 0 && <>&nbsp;&nbsp;–</>}\n </Typography>\n {resultStats.sortedLabelCards.slice(0, maxLabelNames).map(([ln, cnt]) => (\n <Tooltip\n key={ln}\n title={\n <Box>\n <List dense>\n {resultStats.labelExamples[ln]?.map(({ value, count }) => (\n <ListItem\n key={value}\n sx={{\n display: 'flex',\n gap: 1,\n py: 0,\n px: 0.5,\n }}\n >\n <CircleIcon sx={{ fontSize: 8 }} />\n <Typography\n variant=\"body2\"\n component=\"span\"\n sx={{\n color: (theme) =>\n theme.palette.mode === 'dark' // TODO we shouldnt have to do that I guess..\n ? theme.palette.warning.dark\n : theme.palette.warning.main,\n fontFamily: 'monospace',\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n flexGrow: 1,\n }}\n >\n {escapeString(value)}\n </Typography>\n <Typography\n variant=\"body2\"\n component=\"span\"\n sx={{\n whiteSpace: 'nowrap',\n flexShrink: 0,\n }}\n >\n ({count}x)\n </Typography>\n </ListItem>\n ))}\n {cnt > maxLabelValues && (\n <ListItem\n sx={{\n display: 'flex',\n gap: 1,\n py: 0,\n px: 0.5,\n }}\n >\n <CircleIcon sx={{ fontSize: 8 }} />\n <Typography variant=\"body2\">. . .</Typography>\n </ListItem>\n )}\n </List>\n </Box>\n }\n arrow\n >\n <span style={{ cursor: 'pointer', whiteSpace: 'nowrap' }}>\n <Typography\n variant=\"body2\"\n component=\"span\"\n sx={{ fontFamily: 'monospace', color: (theme) => theme.palette.success.main }}\n >\n {ln}\n </Typography>\n <Typography variant=\"body2\" component=\"span\" sx={{ color: (theme) => theme.palette.grey[500] }}>\n : {cnt}\n </Typography>\n </span>\n </Tooltip>\n ))}\n {resultStats.sortedLabelCards.length > maxLabelNames ? (\n <Typography variant=\"body2\">...{resultStats.sortedLabelCards.length - maxLabelNames} more...</Typography>\n ) : null}\n </Stack>\n );\n}\n\nfunction ProgressState({ text }: { text: string }): ReactElement {\n return (\n <Box display=\"flex\" alignItems=\"center\" gap={1} marginBottom={1.5}>\n <CircularProgress size={16} color=\"secondary\" />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {text}...\n </Typography>\n </Box>\n );\n}\n"],"names":["Box","CircularProgress","List","ListItem","Stack","Tooltip","Typography","useTheme","CircleIcon","useCallback","useEffect","useLayoutEffect","useMemo","useState","AlertCircle","nodeType","escapeString","getNodeChildren","formatNode","serializeNode","functionSignatures","useInstantQuery","nodeIndent","connectorWidth","maxLabelNames","maxLabelValues","mergeChildStates","states","includes","TreeNode","node","parentEl","reverse","datasource","childIdx","reportNodeState","theme","children","nodeEl","setNodeEl","nodeRef","resultStats","setResultStats","numSeries","labelExamples","sortedLabelCards","connectorStyle","setConnectorStyle","borderColor","palette","grey","borderLeftStyle","borderLeftWidth","width","left","childStates","setChildStates","map","mergedChildState","queryNode","type","matrixSelector","call","func","last_over_time","args","data","instantQueryResponse","isFetching","error","childReportNodeState","state","prev","newStates","undefined","parentRect","getBoundingClientRect","nodeRect","prevStyle","top","bottom","borderTopLeftRadius","borderTopStyle","borderBottomLeftRadius","borderBottomStyle","status","resultSeries","labelValuesByName","resultType","result","length","forEach","s","Object","entries","metric","ln","lv","labelCardinalities","lvs","keys","sort","aCnt","bCnt","slice","cnt","value","count","a","b","innerNode","direction","gap","ref","sx","position","display","padding","marginBottom","borderRadius","backgroundColor","background","code","QueryStatus","responseTime","binaryExpr","div","ml","child","idx","ProgressState","text","alignItems","color","main","variant","strong","message","component","Math","round","title","dense","py","px","fontSize","mode","warning","dark","fontFamily","whiteSpace","overflow","textOverflow","flexGrow","flexShrink","arrow","span","style","cursor","success","size"],"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,oJAAoJ;;AAEpJ,SAASA,GAAG,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,gBAAgB;AAC5G,OAAOC,gBAAgB,yBAAyB;AAChD,SAAuBC,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACjG,OAAOC,iBAAiB,8BAA8B;AAGtD,SAAkBC,QAAQ,QAAQ,eAAe;AACjD,SAASC,YAAY,EAAEC,eAAe,QAAQ,iBAAiB;AAC/D,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,OAAOC,mBAAmB,qBA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;wCACJC,IAAI;oCACN;;sDAEA,KAACxI;4CAAW0G,IAAI;gDAAE+B,UAAU;4CAAE;;sDAC9B,KAAC3I;4CAAWiI,SAAQ;sDAAQ;;;;;;;oBAMtCoB,KAAK;8BAEL,cAAA,MAACC;wBAAKC,OAAO;4BAAEC,QAAQ;4BAAWR,YAAY;wBAAS;;0CACrD,KAAChJ;gCACCiI,SAAQ;gCACRG,WAAU;gCACVxB,IAAI;oCAAEmC,YAAY;oCAAahB,OAAO,CAACjG,QAAUA,MAAMa,OAAO,CAAC8G,OAAO,CAACzB,IAAI;gCAAC;0CAE3EtC;;0CAEH,MAAC1F;gCAAWiI,SAAQ;gCAAQG,WAAU;gCAAOxB,IAAI;oCAAEmB,OAAO,CAACjG,QAAUA,MAAMa,OAAO,CAACC,IAAI,CAAC,IAAI;gCAAC;;oCAAG;oCAC3FuD;;;;;mBAvEFT;YA4ERvD,YAAYI,gBAAgB,CAAC6C,MAAM,GAAGlE,8BACrC,MAAClB;gBAAWiI,SAAQ;;oBAAQ;oBAAI9F,YAAYI,gBAAgB,CAAC6C,MAAM,GAAGlE;oBAAc;;iBAClF;;;AAGV;AAEA,SAAS0G,cAAc,EAAEC,IAAI,EAAoB;IAC/C,qBACE,MAACnI;QAAIoH,SAAQ;QAAOgB,YAAW;QAASpB,KAAK;QAAGM,cAAc;;0BAC5D,KAACrH;gBAAiB+J,MAAM;gBAAI3B,OAAM;;0BAClC,MAAC/H;gBAAWiI,SAAQ;gBAAQF,OAAM;;oBAC/BF;oBAAK;;;;;AAId"}
@@ -1 +1 @@
1
- {"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":"AAuBA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAYrC,OAAO,EACL,oCAAoC,EAIrC,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,GAAG,YAAY,CAgFzG"}
1
+ {"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":"AAuBA,OAAO,EAAE,YAAY,EAAe,MAAM,OAAO,CAAC;AAYlD,OAAO,EACL,oCAAoC,EAIrC,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,GAAG,YAAY,CAiHzG"}
@@ -15,6 +15,7 @@ import { produce } from 'immer';
15
15
  import { DatasourceSelect, useDatasource, useDatasourceClient, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
16
16
  import { useId } from '@perses-dev/components';
17
17
  import { FormControl, Stack, TextField } from '@mui/material';
18
+ import { useCallback } from 'react';
18
19
  import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PROM_DATASOURCE_KIND } from '../../model';
19
20
  import { DEFAULT_SCRAPE_INTERVAL } from '../types';
20
21
  import { PromQLEditor } from '../../components';
@@ -22,8 +23,7 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
22
23
  /**
23
24
  * The options editor component for editing a PrometheusTimeSeriesQuery's spec.
24
25
  */ export function PrometheusTimeSeriesQueryEditor(props) {
25
- const { onChange, value } = props;
26
- const { datasource } = value;
26
+ const { onChange, value, value: { query, datasource }, queryHandlerSettings } = props;
27
27
  const datasourceSelectValue = datasource ?? DEFAULT_PROM;
28
28
  const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page
29
29
  const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, PROM_DATASOURCE_KIND);
@@ -45,6 +45,37 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
45
45
  }
46
46
  throw new Error('Got unexpected non-Prometheus datasource selector');
47
47
  };
48
+ const handlePromQlEditorChanges = useCallback((e)=>{
49
+ handleQueryChange(e);
50
+ if (queryHandlerSettings?.watchQueryChanges) {
51
+ queryHandlerSettings?.watchQueryChanges(e);
52
+ }
53
+ }, [
54
+ queryHandlerSettings,
55
+ handleQueryChange
56
+ ]);
57
+ const handleLegendSpecChange = useCallback((e)=>{
58
+ handleFormatChange(e.target.value);
59
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
60
+ ...value,
61
+ seriesNameFormat: e.target.value
62
+ });
63
+ }, [
64
+ queryHandlerSettings,
65
+ handleFormatChange,
66
+ value
67
+ ]);
68
+ const handleMinStepSpecChange = useCallback((e)=>{
69
+ handleMinStepChange(e.target.value ? e.target.value : undefined);
70
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
71
+ ...value,
72
+ minStep: e.target.value
73
+ });
74
+ }, [
75
+ queryHandlerSettings,
76
+ handleMinStepChange,
77
+ value
78
+ ]);
48
79
  return /*#__PURE__*/ _jsxs(Stack, {
49
80
  spacing: 2,
50
81
  children: [
@@ -66,10 +97,10 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
66
97
  url: promURL
67
98
  }
68
99
  },
69
- value: value.query,
100
+ value: query,
70
101
  datasource: selectedDatasource,
71
- onChange: handleQueryChange,
72
- onBlur: handleQueryBlur
102
+ onChange: handlePromQlEditorChanges,
103
+ onBlur: queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined
73
104
  }),
74
105
  /*#__PURE__*/ _jsxs(Stack, {
75
106
  direction: "row",
@@ -81,16 +112,16 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
81
112
  placeholder: "Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...",
82
113
  helperText: "Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.",
83
114
  value: format ?? '',
84
- onChange: (e)=>handleFormatChange(e.target.value),
85
- onBlur: handleFormatBlur
115
+ onChange: handleLegendSpecChange,
116
+ onBlur: queryHandlerSettings?.runWithOnBlur ? handleFormatBlur : undefined
86
117
  }),
87
118
  /*#__PURE__*/ _jsx(TextField, {
88
119
  label: "Min Step",
89
120
  placeholder: minStepPlaceholder,
90
121
  helperText: "Lower bound for the step. If not provided, the scrape interval of the datasource is used.",
91
122
  value: minStep ?? '',
92
- onChange: (e)=>handleMinStepChange(e.target.value ? e.target.value : undefined),
93
- onBlur: handleMinStepBlur,
123
+ onChange: handleMinStepSpecChange,
124
+ onBlur: queryHandlerSettings?.runWithOnBlur ? handleMinStepBlur : undefined,
94
125
  sx: {
95
126
  width: '250px'
96
127
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.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 { produce } from 'immer';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n useDatasource,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { useId } from '@perses-dev/components';\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport { ReactElement } from 'react';\nimport {\n DEFAULT_PROM,\n DurationString,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n} from '../../model';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PromQLEditor } from '../../components';\nimport {\n PrometheusTimeSeriesQueryEditorProps,\n useQueryState,\n useFormatState,\n useMinStepState,\n} from './query-editor-model';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): ReactElement {\n const { onChange, value } = props;\n const { datasource } = value;\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n\n const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page\n\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n PROM_DATASOURCE_KIND\n ) as PrometheusDatasourceSelector;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const { data: datasourceResource } = useDatasource(selectedDatasource);\n\n const { handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\n const { minStep, handleMinStepChange, handleMinStepBlur } = useMinStepState(props);\n const minStepPlaceholder =\n minStep ??\n (datasourceResource && (datasourceResource?.plugin.spec as PrometheusDatasourceSpec).scrapeInterval) ??\n DEFAULT_SCRAPE_INTERVAL;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\" fullWidth={false}>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\n onChange={handleDatasourceChange}\n labelId={datasourceSelectLabelID}\n label=\"Prometheus Datasource\"\n notched\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.query} // here we are passing `value.query` and not `query` from useQueryState in order to get updates only on onBlur events\n datasource={selectedDatasource}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n />\n <Stack direction=\"row\" spacing={2}>\n <TextField\n fullWidth\n label=\"Legend\"\n placeholder=\"Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...\"\n helperText=\"Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.\"\n value={format ?? ''}\n onChange={(e) => handleFormatChange(e.target.value)}\n onBlur={handleFormatBlur}\n />\n <TextField\n label=\"Min Step\"\n placeholder={minStepPlaceholder}\n helperText=\"Lower bound for the step. If not provided, the scrape interval of the datasource is used.\"\n value={minStep ?? ''}\n onChange={(e) => handleMinStepChange(e.target.value ? (e.target.value as DurationString) : undefined)}\n onBlur={handleMinStepBlur}\n sx={{ width: '250px' }}\n />\n </Stack>\n </Stack>\n );\n}\n"],"names":["produce","DatasourceSelect","useDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","useId","FormControl","Stack","TextField","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","DEFAULT_SCRAPE_INTERVAL","PromQLEditor","useQueryState","useFormatState","useMinStepState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","datasourceSelectValue","datasourceSelectLabelID","selectedDatasource","data","client","promURL","options","datasourceUrl","datasourceResource","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","minStep","handleMinStepChange","handleMinStepBlur","minStepPlaceholder","plugin","spec","scrapeInterval","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","spacing","margin","fullWidth","datasourcePluginKind","labelId","label","notched","completeConfig","remote","url","query","onBlur","direction","placeholder","helperText","e","target","sx","width"],"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,OAAO,QAAQ,QAAQ;AA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AAsF;gBACtF,MAAMC,iBAAiBrC,sBAAsBmC,QAAQG,YAAYH;gBACjEC,MAAMxB,UAAU,GAAGyB;YACrB;YAEF;QACF;QAEA,MAAM,IAAIE,MAAM;IAClB;IAEA,qBACE,MAAC1C;QAAM2C,SAAS;;0BACd,KAAC5C;gBAAY6C,QAAO;gBAAQC,WAAW;0BACrC,cAAA,KAACnD;oBACCoD,sBAAsBzC;oBACtBS,OAAOE;oBACPH,UAAUwB;oBACVU,SAAS9B;oBACT+B,OAAM;oBACNC,OAAO;;;0BAGX,KAAC1C;gBACC2C,gBAAgB;oBAAEC,QAAQ;wBAAEC,KAAK/B;oBAAQ;gBAAE;gBAC3CP,OAAOA,MAAMuC,KAAK;gBAClBtC,YAAYG;gBACZL,UAAUY;gBACV6B,QAAQ5B;;0BAEV,MAAC1B;gBAAMuD,WAAU;gBAAMZ,SAAS;;kCAC9B,KAAC1C;wBACC4C,SAAS;wBACTG,OAAM;wBACNQ,aAAY;wBACZC,YAAW;wBACX3C,OAAOa,UAAU;wBACjBd,UAAU,CAAC6C,IAAM9B,mBAAmB8B,EAAEC,MAAM,CAAC7C,KAAK;wBAClDwC,QAAQzB;;kCAEV,KAAC5B;wBACC+C,OAAM;wBACNQ,aAAavB;wBACbwB,YAAW;wBACX3C,OAAOgB,WAAW;wBAClBjB,UAAU,CAAC6C,IAAM3B,oBAAoB2B,EAAEC,MAAM,CAAC7C,KAAK,GAAI4C,EAAEC,MAAM,CAAC7C,KAAK,GAAsB2B;wBAC3Fa,QAAQtB;wBACR4B,IAAI;4BAAEC,OAAO;wBAAQ;;;;;;AAK/B"}
1
+ {"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.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 { produce } from 'immer';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n useDatasource,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { useId } from '@perses-dev/components';\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport { ReactElement, useCallback } from 'react';\nimport {\n DEFAULT_PROM,\n DurationString,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n} from '../../model';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PromQLEditor } from '../../components';\nimport {\n PrometheusTimeSeriesQueryEditorProps,\n useQueryState,\n useFormatState,\n useMinStepState,\n} from './query-editor-model';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): ReactElement {\n const {\n onChange,\n value,\n value: { query, datasource },\n queryHandlerSettings,\n } = props;\n\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n\n const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page\n\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n PROM_DATASOURCE_KIND\n ) as PrometheusDatasourceSelector;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const { data: datasourceResource } = useDatasource(selectedDatasource);\n\n const { handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\n const { minStep, handleMinStepChange, handleMinStepBlur } = useMinStepState(props);\n const minStepPlaceholder =\n minStep ??\n (datasourceResource && (datasourceResource?.plugin.spec as PrometheusDatasourceSpec).scrapeInterval) ??\n DEFAULT_SCRAPE_INTERVAL;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n const handlePromQlEditorChanges = useCallback(\n (e: string) => {\n handleQueryChange(e);\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings?.watchQueryChanges(e);\n }\n },\n [queryHandlerSettings, handleQueryChange]\n );\n\n const handleLegendSpecChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n handleFormatChange(e.target.value);\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, seriesNameFormat: e.target.value });\n },\n [queryHandlerSettings, handleFormatChange, value]\n );\n\n const handleMinStepSpecChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n handleMinStepChange(e.target.value ? (e.target.value as DurationString) : undefined);\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, minStep: e.target.value });\n },\n [queryHandlerSettings, handleMinStepChange, value]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\" fullWidth={false}>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\n onChange={handleDatasourceChange}\n labelId={datasourceSelectLabelID}\n label=\"Prometheus Datasource\"\n notched\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={query} // here we are passing `value.query` and not `query` from useQueryState in order to get updates only on onBlur events\n datasource={selectedDatasource}\n onChange={handlePromQlEditorChanges}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined}\n />\n <Stack direction=\"row\" spacing={2}>\n <TextField\n fullWidth\n label=\"Legend\"\n placeholder=\"Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...\"\n helperText=\"Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.\"\n value={format ?? ''}\n onChange={handleLegendSpecChange}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleFormatBlur : undefined}\n />\n <TextField\n label=\"Min Step\"\n placeholder={minStepPlaceholder}\n helperText=\"Lower bound for the step. If not provided, the scrape interval of the datasource is used.\"\n value={minStep ?? ''}\n onChange={handleMinStepSpecChange}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleMinStepBlur : undefined}\n sx={{ width: '250px' }}\n />\n </Stack>\n </Stack>\n );\n}\n"],"names":["produce","DatasourceSelect","useDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","useId","FormControl","Stack","TextField","useCallback","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","DEFAULT_SCRAPE_INTERVAL","PromQLEditor","useQueryState","useFormatState","useMinStepState","PrometheusTimeSeriesQueryEditor","props","onChange","value","query","datasource","queryHandlerSettings","datasourceSelectValue","datasourceSelectLabelID","selectedDatasource","data","client","promURL","options","datasourceUrl","datasourceResource","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","minStep","handleMinStepChange","handleMinStepBlur","minStepPlaceholder","plugin","spec","scrapeInterval","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","handlePromQlEditorChanges","e","watchQueryChanges","handleLegendSpecChange","target","setWatchOtherSpecs","seriesNameFormat","handleMinStepSpecChange","spacing","margin","fullWidth","datasourcePluginKind","labelId","label","notched","completeConfig","remote","url","onBlur","runWithOnBlur","direction","placeholder","helperText","sx","width"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;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