1111// See the License for the specific language governing permissions and
1212// limitations under the License.
1313
14- import { PanelData , PanelProps } from '@perses-dev/plugin-system' ;
14+ import {
15+ PanelData ,
16+ PanelProps ,
17+ replaceVariablesInString ,
18+ useAllVariableValues ,
19+ VariableStateMap ,
20+ } from '@perses-dev/plugin-system' ;
1521import { Table , TableCellConfigs , TableColumnConfig } from '@perses-dev/components' ;
1622import { ReactElement , useEffect , useMemo , useState } from 'react' ;
1723import { formatValue , Labels , QueryDataType , TimeSeries , TimeSeriesData , transformData } from '@perses-dev/core' ;
@@ -157,22 +163,30 @@ function ColumnFilterDropdown({
157163 * If column is hidden, return undefined.
158164 * If column do not have a definition, return a default column config.
159165 */
160- function generateColumnConfig ( name : string , columnSettings : ColumnSettings [ ] ) : TableColumnConfig < unknown > | undefined {
166+ function generateColumnConfig (
167+ name : string ,
168+ columnSettings : ColumnSettings [ ] ,
169+ allVariables : VariableStateMap
170+ ) : TableColumnConfig < unknown > | undefined {
161171 for ( const column of columnSettings ) {
162172 if ( column . name === name ) {
163173 if ( column . hide ) {
164174 return undefined ;
165175 }
166176
167177 const { name, header, headerDescription, enableSorting, width, align, dataLink } = column ;
178+ const modifiedDataLink = dataLink
179+ ? { ...dataLink , url : replaceVariablesInString ( dataLink . url , allVariables ) }
180+ : undefined ;
181+
168182 return {
169183 accessorKey : name ,
170184 header : header ?? name ,
171185 headerDescription,
172186 enableSorting,
173187 width,
174188 align,
175- dataLink,
189+ dataLink : modifiedDataLink ,
176190 ...generateCellContentConfig ( column ) ,
177191 } ;
178192 }
@@ -195,6 +209,7 @@ export type TableProps = PanelProps<TableOptions, TimeSeriesData>;
195209
196210export function TablePanel ( { contentDimensions, spec, queryResults } : TableProps ) : ReactElement | null {
197211 const theme = useTheme ( ) ;
212+ const allVariables = useAllVariableValues ( ) ;
198213
199214 // TODO: handle other query types
200215 const queryMode = getTablePanelQueryOptions ( spec ) . mode ;
@@ -273,7 +288,7 @@ export function TablePanel({ contentDimensions, spec, queryResults }: TableProps
273288 for ( const columnSetting of spec . columnSettings ?? [ ] ) {
274289 if ( customizedColumns . has ( columnSetting . name ) ) continue ; // Skip duplicates
275290
276- const columnConfig = generateColumnConfig ( columnSetting . name , spec . columnSettings ?? [ ] ) ;
291+ const columnConfig = generateColumnConfig ( columnSetting . name , spec . columnSettings ?? [ ] , allVariables ) ;
277292 if ( columnConfig !== undefined ) {
278293 columns . push ( columnConfig ) ;
279294 customizedColumns . add ( columnSetting . name ) ;
@@ -284,7 +299,7 @@ export function TablePanel({ contentDimensions, spec, queryResults }: TableProps
284299 if ( ! spec . defaultColumnHidden ) {
285300 for ( const key of keys ) {
286301 if ( ! customizedColumns . has ( key ) ) {
287- const columnConfig = generateColumnConfig ( key , spec . columnSettings ?? [ ] ) ;
302+ const columnConfig = generateColumnConfig ( key , spec . columnSettings ?? [ ] , allVariables ) ;
288303 if ( columnConfig !== undefined ) {
289304 columns . push ( columnConfig ) ;
290305 }
@@ -293,7 +308,7 @@ export function TablePanel({ contentDimensions, spec, queryResults }: TableProps
293308 }
294309
295310 return columns ;
296- } , [ keys , spec . columnSettings , spec . defaultColumnHidden ] ) ;
311+ } , [ keys , spec . columnSettings , spec . defaultColumnHidden , allVariables ] ) ;
297312
298313 // Generate cell settings that will be used by the table to render cells (text color, background color, ...)
299314 const cellConfigs : TableCellConfigs = useMemo ( ( ) => {
0 commit comments