Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMSBIOHUB 335: Tab Through Observation Edit #1156

Merged
merged 6 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/src/components/data-grid/TextFieldDataGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import TextField, { TextFieldProps } from '@mui/material/TextField/TextField';
import useEnhancedEffect from '@mui/material/utils/useEnhancedEffect';
import { GridRenderEditCellParams, GridValidRowModel } from '@mui/x-data-grid';
import { useRef } from 'react';

interface ITextFieldCustomValidation<DataGridType extends GridValidRowModel> {
textFieldProps: TextFieldProps;
dataGridProps: GridRenderEditCellParams<DataGridType>;
}

const TextFieldDataGrid = <DataGridType extends GridValidRowModel>({

Check warning on line 11 in app/src/components/data-grid/TextFieldDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/TextFieldDataGrid.tsx#L11

Added line #L11 was not covered by tests
textFieldProps,
dataGridProps
}: ITextFieldCustomValidation<DataGridType>) => {
const ref = useRef<HTMLInputElement>();
useEnhancedEffect(() => {

Check warning on line 16 in app/src/components/data-grid/TextFieldDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/TextFieldDataGrid.tsx#L15-L16

Added lines #L15 - L16 were not covered by tests
if (dataGridProps.hasFocus) {
ref.current?.focus();

Check warning on line 18 in app/src/components/data-grid/TextFieldDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/TextFieldDataGrid.tsx#L18

Added line #L18 was not covered by tests
}
}, [dataGridProps.hasFocus]);
return (

Check warning on line 21 in app/src/components/data-grid/TextFieldDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/TextFieldDataGrid.tsx#L21

Added line #L21 was not covered by tests
<TextField
inputRef={ref}
value={dataGridProps.value ?? ''}
variant="outlined"
type="text"
inputProps={{ inputMode: 'numeric' }}
{...textFieldProps}
/>
);
};

export default TextFieldDataGrid;
48 changes: 48 additions & 0 deletions app/src/components/data-grid/TimePickerDataGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import useEnhancedEffect from '@mui/material/utils/useEnhancedEffect';
import { GridRenderEditCellParams, GridValidRowModel, useGridApiContext } from '@mui/x-data-grid';
import { LocalizationProvider, TimePicker, TimePickerProps } from '@mui/x-date-pickers';
import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
import moment from 'moment';
import { useRef } from 'react';

interface ITimePickerDataGridProps<DataGridType extends GridValidRowModel> {
dateFieldProps?: TimePickerProps<any>;
dataGridProps: GridRenderEditCellParams<DataGridType>;
}

const TimePickerDataGrid = <DataGridType extends GridValidRowModel>({

Check warning on line 13 in app/src/components/data-grid/TimePickerDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/TimePickerDataGrid.tsx#L13

Added line #L13 was not covered by tests
dateFieldProps,
dataGridProps
}: ITimePickerDataGridProps<DataGridType>) => {
const apiRef = useGridApiContext();
const ref = useRef<HTMLInputElement>(null);
useEnhancedEffect(() => {

Check warning on line 19 in app/src/components/data-grid/TimePickerDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/TimePickerDataGrid.tsx#L17-L19

Added lines #L17 - L19 were not covered by tests
if (dataGridProps.hasFocus) {
ref.current?.focus();

Check warning on line 21 in app/src/components/data-grid/TimePickerDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/TimePickerDataGrid.tsx#L21

Added line #L21 was not covered by tests
}
}, [dataGridProps.hasFocus]);
return (

Check warning on line 24 in app/src/components/data-grid/TimePickerDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/TimePickerDataGrid.tsx#L24

Added line #L24 was not covered by tests
<LocalizationProvider dateAdapter={AdapterMoment}>
<TimePicker
inputRef={ref}
value={(dataGridProps.value && moment(dataGridProps.value, 'HH:mm:ss')) || null}
onChange={(value) => {
apiRef?.current.setEditCellValue({ id: dataGridProps.id, field: dataGridProps.field, value: value });

Check warning on line 30 in app/src/components/data-grid/TimePickerDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/TimePickerDataGrid.tsx#L30

Added line #L30 was not covered by tests
}}
onAccept={(value) => {
apiRef?.current.setEditCellValue({

Check warning on line 33 in app/src/components/data-grid/TimePickerDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/TimePickerDataGrid.tsx#L33

Added line #L33 was not covered by tests
id: dataGridProps.id,
field: dataGridProps.field,
value: value?.format('HH:mm:ss')
});
}}
views={['hours', 'minutes', 'seconds']}
timeSteps={{ hours: 1, minutes: 1, seconds: 1 }}
ampm={false}
{...dateFieldProps}
/>
</LocalizationProvider>
);
};

export default TimePickerDataGrid;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import Box from '@mui/material/Box';
import CircularProgress from '@mui/material/CircularProgress';
import TextField from '@mui/material/TextField';
import useEnhancedEffect from '@mui/material/utils/useEnhancedEffect';
import { GridRenderCellParams, GridValidRowModel, useGridApiContext } from '@mui/x-data-grid';
import { IAutocompleteDataGridOption } from 'components/data-grid/autocomplete/AutocompleteDataGrid.interface';
import { DebouncedFunc } from 'lodash-es';
import { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';

export interface IAsyncAutocompleteDataGridEditCell<
DataGridType extends GridValidRowModel,
Expand Down Expand Up @@ -52,6 +53,14 @@

const apiRef = useGridApiContext();

const ref = useRef<HTMLInputElement>();

Check warning on line 56 in app/src/components/data-grid/autocomplete/AsyncAutocompleteDataGridEditCell.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/autocomplete/AsyncAutocompleteDataGridEditCell.tsx#L56

Added line #L56 was not covered by tests

useEnhancedEffect(() => {

Check warning on line 58 in app/src/components/data-grid/autocomplete/AsyncAutocompleteDataGridEditCell.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/autocomplete/AsyncAutocompleteDataGridEditCell.tsx#L58

Added line #L58 was not covered by tests
if (dataGridProps.hasFocus) {
ref.current?.focus();
console.log('Focus fired!');

Check warning on line 61 in app/src/components/data-grid/autocomplete/AsyncAutocompleteDataGridEditCell.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/autocomplete/AsyncAutocompleteDataGridEditCell.tsx#L60-L61

Added lines #L60 - L61 were not covered by tests
GrahamS-Quartech marked this conversation as resolved.
Show resolved Hide resolved
}
}, [dataGridProps.hasFocus]);
// The current data grid value
const dataGridValue = dataGridProps.value;
// The input field value
Expand Down Expand Up @@ -168,6 +177,7 @@
renderInput={(params) => (
<TextField
{...params}
inputRef={ref}
size="small"
variant="outlined"
fullWidth
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
import useEnhancedEffect from '@mui/material/utils/useEnhancedEffect';
import { GridRenderCellParams, GridValidRowModel, useGridApiContext } from '@mui/x-data-grid';
import { IAutocompleteDataGridOption } from 'components/data-grid/autocomplete/AutocompleteDataGrid.interface';
import { useRef } from 'react';

export interface IAutocompleteDataGridEditCellProps<
DataGridType extends GridValidRowModel,
Expand Down Expand Up @@ -45,6 +47,15 @@

const apiRef = useGridApiContext();

const ref = useRef<HTMLInputElement>();

Check warning on line 50 in app/src/components/data-grid/autocomplete/AutocompleteDataGridEditCell.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/autocomplete/AutocompleteDataGridEditCell.tsx#L50

Added line #L50 was not covered by tests

useEnhancedEffect(() => {

Check warning on line 52 in app/src/components/data-grid/autocomplete/AutocompleteDataGridEditCell.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/autocomplete/AutocompleteDataGridEditCell.tsx#L52

Added line #L52 was not covered by tests
if (dataGridProps.hasFocus) {
ref.current?.focus();
console.log('Focus fired!');

Check warning on line 55 in app/src/components/data-grid/autocomplete/AutocompleteDataGridEditCell.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/data-grid/autocomplete/AutocompleteDataGridEditCell.tsx#L54-L55

Added lines #L54 - L55 were not covered by tests
GrahamS-Quartech marked this conversation as resolved.
Show resolved Hide resolved
}
}, [dataGridProps.hasFocus]);

// The current data grid value
const dataGridValue = dataGridProps.value;

Expand Down Expand Up @@ -98,6 +109,7 @@
renderInput={(params) => (
<TextField
{...params}
inputRef={ref}
size="small"
variant="outlined"
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AsyncAutocompleteDataGridEditCell from 'components/data-grid/autocomplete
import { IAutocompleteDataGridOption } from 'components/data-grid/autocomplete/AutocompleteDataGrid.interface';
import { useBiohubApi } from 'hooks/useBioHubApi';
import debounce from 'lodash-es/debounce';
import { useMemo } from 'react';
import React, { useMemo } from 'react';

export interface ITaxonomyDataGridCellProps<DataGridType extends GridValidRowModel> {
dataGridProps: GridRenderEditCellParams<DataGridType>;
Expand Down
Loading
Loading