Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arminmeh committed Nov 20, 2024
1 parent 438aab6 commit 1fe6121
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import useEventCallback from '@mui/utils/useEventCallback';
import {
getDataGridUtilityClass,
GRID_CHECKBOX_SELECTION_FIELD,
gridColumnDefinitionsSelector,
gridColumnLookupSelector,
GridLogicOperator,
gridRowsLookupSelector,
GridSingleSelectColDef,
} from '@mui/x-data-grid';
import { getValueOptions, getVisibleRows } from '@mui/x-data-grid/internals';
Expand Down Expand Up @@ -43,16 +45,13 @@ const GridToolbarPromptControlRoot = styled('div', {
flexDirection: 'row',
});

function sampleData(
apiRef: React.MutableRefObject<GridApiPremium>,
rootProps: DataGridPremiumProcessedProps,
) {
const columns = Object.values(gridColumnLookupSelector(apiRef));
const rows = rootProps.rows;
function sampleData(apiRef: React.MutableRefObject<GridApiPremium>) {
const columns = gridColumnDefinitionsSelector(apiRef);
const rows = Object.values(gridRowsLookupSelector(apiRef));
const columnExamples: Record<string, any[]> = {};

columns.forEach((column) => {
columnExamples[column.field] = rows.slice(0, 5).map(() => {
columnExamples[column.field] = Array.from({ length: Math.min(5, rows.length) }).map(() => {
const row = rows[Math.floor(Math.random() * rows.length)];
if (column.valueGetter) {
return column.valueGetter(row[column.field] as never, row, column, apiRef);
Expand All @@ -68,7 +67,7 @@ function generateContext(
apiRef: React.MutableRefObject<GridApiPremium>,
examples?: Record<string, any[]>,
) {
const columns = Object.values(gridColumnLookupSelector(apiRef));
const columns = gridColumnDefinitionsSelector(apiRef);
const columnsContext = columns.map((column) => ({
field: column.field,
description: column.description ?? null,
Expand Down Expand Up @@ -115,8 +114,8 @@ function GridToolbarPromptControl(props: GridToolbarPromptControlProps) {

const classes = useUtilityClasses(rootProps, isRecording);
const examplesFromData = React.useMemo(
() => (allowDataSampling ? sampleData(apiRef, rootProps) : undefined),
[apiRef, rootProps, allowDataSampling],
() => (allowDataSampling ? sampleData(apiRef) : undefined),
[apiRef, allowDataSampling],
);

const processPrompt = React.useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ function RecordButton(props: RecordButtonProps) {
<rootProps.slots.baseTooltip
title={
recording
? apiRef.current.getLocaleText('toolbarPromptControlRecordButtonDefaultLabel')
: apiRef.current.getLocaleText('toolbarPromptControlRecordButtonActiveLabel')
? apiRef.current.getLocaleText('toolbarPromptControlRecordButtonActiveLabel')
: apiRef.current.getLocaleText('toolbarPromptControlRecordButtonDefaultLabel')
}
>
<div>
Expand Down

0 comments on commit 1fe6121

Please sign in to comment.