kibana/x-pack/plugins/lens/public/datatable_visualization/components/cell_value.tsx
Brandon Kobel 4584a8b570
Elastic License 2.0 (#90099)
* Updating everything except the license headers themselves

* Applying ESLint rules

* Manually replacing the stragglers
2021-02-03 18:12:39 -08:00

32 lines
1.2 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React, { useContext } from 'react';
import { EuiDataGridCellValueElementProps } from '@elastic/eui';
import type { FormatFactory } from '../../types';
import type { DataContextType } from './types';
export const createGridCell = (
formatters: Record<string, ReturnType<FormatFactory>>,
DataContext: React.Context<DataContextType>
) => ({ rowIndex, columnId }: EuiDataGridCellValueElementProps) => {
const { table } = useContext(DataContext);
const rowValue = table?.rows[rowIndex][columnId];
const content = formatters[columnId]?.convert(rowValue, 'html');
return (
<span
/*
* dangerouslySetInnerHTML is necessary because the field formatter might produce HTML markup
* which is produced in a safe way.
*/
dangerouslySetInnerHTML={{ __html: content }} // eslint-disable-line react/no-danger
data-test-subj="lnsTableCellContent"
className="lnsDataTableCellContent"
/>
);
};