MCPcopy Create free account
hub / github.com/HelloCSV/HelloCSV / SheetDataEditorCell

Function SheetDataEditorCell

src/sheet/components/SheetDataEditorCell.tsx:37–216  ·  view source on GitHub ↗
({
  rowId,
  sheetDefinition,
  columnDefinition,
  value,
  onUpdated,
  allData,
  clearRowsSelection,
  errorsText,
  enumLabelDict,
}: Props)

Source from the content-addressed store, hash-verified

35}
36
37export 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') : ''

Callers

nothing calls this directly

Calls 10

useTranslationsFunction · 0.90
useImporterDefinitionFunction · 0.90
getCellDisplayValueFunction · 0.90
isColumnReadOnlyFunction · 0.90
useLongPressFunction · 0.90
getLabelDictFunction · 0.90
getLabelDictValueFunction · 0.90
tFunction · 0.85
updateValueFunction · 0.85

Tested by

no test coverage detected