View File Name : 7409.24316c87d08c1053c46a.js.map
\n );\n};\n\n// group state history by labels\nexport function groupStateByLabels(\n history: Array
>\n): StateHistoryMap {\n const items: StateHistoryRowItem[] = history.map((item) => {\n // let's grab the last matching set of `{}` since the alert name could also contain { or }\n const LABELS_REGEX = /{.*?}/g;\n const stringifiedLabels = item.text.match(LABELS_REGEX)?.at(-1) ?? '';\n\n return {\n id: String(item.id),\n state: item.newState,\n // let's omit the labels for each entry since it's just added noise to each state history item\n text: item.text.replace(stringifiedLabels, ''),\n data: item.data,\n timestamp: item.updated,\n stringifiedLabels,\n };\n });\n\n // we have to group our state history items by their unique combination of tags since we want to display a DynamicTable for each alert instance\n // (effectively unique combination of labels)\n return groupBy(items, (item) => item.stringifiedLabels);\n}\n\n// match a string either by exact text match or with regular expression when in the form of \"//\"\nexport function matchKey(groupKey: string, textFilter: string) {\n // if the text filter is empty we show all matches\n if (textFilter === '') {\n return true;\n }\n\n const isRegExp = textFilter.startsWith('/') && textFilter.endsWith('/');\n\n // not a regular expression, use normal text matching\n if (!isRegExp) {\n return groupKey.includes(textFilter);\n }\n\n // regular expression, try parsing and applying\n // when we fail to parse the text as a regular expression, we return no match\n try {\n return new RegExp(textFilter.slice(1, -1)).test(groupKey);\n } catch (err) {\n return false;\n }\n}\n\nfunction renderValueCell(item: StateHistoryRow) {\n const matches = item.data.data?.evalMatches ?? [];\n\n return (\n <>\n {item.data.text}\n \n {matches.map((match) => (\n \n ))}\n \n >\n );\n}\n\nfunction renderStateCell(item: StateHistoryRow) {\n return ;\n}\n\nfunction renderTimestampCell(item: StateHistoryRow) {\n return (\n {item.data.timestamp && {dateTimeFormat(item.data.timestamp)}}
\n );\n}\n\nconst LabelsWrapper = ({ children }: React.PropsWithChildren<{}>) => {\n const { wrapper } = useStyles2(getStyles);\n return {children}
;\n};\n\nconst TimestampStyle = css`\n display: flex;\n align-items: flex-end;\n flex-direction: column;\n`;\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n wrapper: css`\n & > * {\n margin-right: ${theme.spacing(1)};\n }\n `,\n tableGroupKey: css`\n margin-top: ${theme.spacing(2)};\n margin-bottom: ${theme.spacing(2)};\n `,\n goupKeyText: css({\n overflowX: 'auto',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n display: 'block',\n }),\n});\n\nexport default StateHistory;\n"],"names":["useManagedAlertStateHistory","alertId","dispatch","history","useUnifiedAlertingSelector","state","StateHistory","textFilter","setTextFilter","handleTextFilter","event","loading","error","result","styles","getStyles","LoadingPlaceholder","Alert","columns","renderStateCell","renderValueCell","renderTimestampCell","tables","groupStateByLabels","groupKey","matchKey","items","tableItems","historyItem","DynamicTable","Field","Label","Stack","Tooltip","Icon","Input","item","LABELS_REGEX","stringifiedLabels","matches","LabelsWrapper","match","AlertLabel","AlertStateTag","TimestampStyle","children","wrapper","theme"],"sourceRoot":""}