({
rowId,
sheetDefinition,
columnDefinition,
value,
onUpdated,
allData,
clearRowsSelection,
errorsText,
enumLabelDict,
}: Props)
| 35 | } |
| 36 | |
| 37 | export default function SheetDataEditorCell({ |
| 38 | rowId, |
| 39 | sheetDefinition, |
| 40 | columnDefinition, |
| 41 | value, |
| 42 | onUpdated, |
| 43 | allData, |
| 44 | clearRowsSelection, |
| 45 | errorsText, |
| 46 | enumLabelDict, |
| 47 | }: Props) { |
| 48 | const { t } = useTranslations(); |
| 49 | const { availableActions } = useImporterDefinition(); |
| 50 | |
| 51 | const [editMode, setEditMode] = useState(false); |
| 52 | const inputRef = useRef<HTMLInputElement>(null); |
| 53 | |
| 54 | useEffect(() => { |
| 55 | if (editMode) { |
| 56 | clearRowsSelection(); |
| 57 | if (inputRef.current) { |
| 58 | inputRef.current.focus(); |
| 59 | } |
| 60 | } |
| 61 | // We don't want to include clearRowsSelection in the dependencies array, since it's should impact the clearing itself |
| 62 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 63 | }, [editMode]); |
| 64 | |
| 65 | const { displayValue, valueEmpty } = getCellDisplayValue( |
| 66 | sheetDefinition, |
| 67 | columnDefinition, |
| 68 | value, |
| 69 | enumLabelDict |
| 70 | ); |
| 71 | |
| 72 | const readOnly = |
| 73 | isColumnReadOnly(columnDefinition) || |
| 74 | !availableActions.includes('editRows'); |
| 75 | |
| 76 | const longPressHandlers = useLongPress( |
| 77 | () => { |
| 78 | if (!readOnly) setEditMode(true); |
| 79 | }, |
| 80 | { disabled: readOnly } |
| 81 | ); |
| 82 | |
| 83 | const cellBackgroundColor = errorsText |
| 84 | ? 'bg-hello-csv-danger-extra-light' |
| 85 | : readOnly |
| 86 | ? 'bg-hello-csv-muted' |
| 87 | : ''; |
| 88 | |
| 89 | if (!editMode) { |
| 90 | return ( |
| 91 | <SheetTooltip |
| 92 | variant={errorsText ? 'error' : 'info'} |
| 93 | tooltipText={ |
| 94 | errorsText ? errorsText : readOnly ? t('sheet.readOnly') : '' |
nothing calls this directly
no test coverage detected