EditCellWrapper.tsx 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { CellIdentifier } from '$app/stores/effects/database/cell/cell_bd_svc';
  2. import { useCell } from '$app/components/_shared/database-hooks/useCell';
  3. import { CellCache } from '$app/stores/effects/database/cell/cell_cache';
  4. import { FieldController } from '$app/stores/effects/database/field/field_controller';
  5. import { DateCellDataPB, FieldType, SelectOptionCellDataPB } from '@/services/backend';
  6. import { TextTypeSvg } from '$app/components/_shared/svg/TextTypeSvg';
  7. import { NumberTypeSvg } from '$app/components/_shared/svg/NumberTypeSvg';
  8. import { DateTypeSvg } from '$app/components/_shared/svg/DateTypeSvg';
  9. import { SingleSelectTypeSvg } from '$app/components/_shared/svg/SingleSelectTypeSvg';
  10. import { MultiSelectTypeSvg } from '$app/components/_shared/svg/MultiSelectTypeSvg';
  11. import { ChecklistTypeSvg } from '$app/components/_shared/svg/ChecklistTypeSvg';
  12. import { UrlTypeSvg } from '$app/components/_shared/svg/UrlTypeSvg';
  13. import { useAppSelector } from '$app/stores/store';
  14. import { getBgColor } from '$app/components/_shared/getColor';
  15. import { CheckboxSvg } from '$app/components/_shared/svg/CheckboxSvg';
  16. import { EditorCheckSvg } from '$app/components/_shared/svg/EditorCheckSvg';
  17. import { EditorUncheckSvg } from '$app/components/_shared/svg/EditorUncheckSvg';
  18. import { useState } from 'react';
  19. import { EditCellText } from '$app/components/board/EditBoardRow/EditCellText';
  20. export const EditCellWrapper = ({
  21. cellIdentifier,
  22. cellCache,
  23. fieldController,
  24. }: {
  25. cellIdentifier: CellIdentifier;
  26. cellCache: CellCache;
  27. fieldController: FieldController;
  28. }) => {
  29. const { data, cellController } = useCell(cellIdentifier, cellCache, fieldController);
  30. const databaseStore = useAppSelector((state) => state.database);
  31. const [showEditField, setShowEditField] = useState(false);
  32. const onEditFieldClick = () => {
  33. setShowEditField(true);
  34. };
  35. return (
  36. <div className={'flex w-full items-center'}>
  37. <div
  38. onClick={() => onEditFieldClick()}
  39. className={'flex w-[180px] cursor-pointer items-center gap-2 rounded-lg px-4 py-2 hover:bg-shade-6'}
  40. >
  41. <div className={'h-5 w-5 flex-shrink-0'}>
  42. {cellIdentifier.fieldType === FieldType.RichText && <TextTypeSvg></TextTypeSvg>}
  43. {cellIdentifier.fieldType === FieldType.Number && <NumberTypeSvg></NumberTypeSvg>}
  44. {cellIdentifier.fieldType === FieldType.DateTime && <DateTypeSvg></DateTypeSvg>}
  45. {cellIdentifier.fieldType === FieldType.SingleSelect && <SingleSelectTypeSvg></SingleSelectTypeSvg>}
  46. {cellIdentifier.fieldType === FieldType.MultiSelect && <MultiSelectTypeSvg></MultiSelectTypeSvg>}
  47. {cellIdentifier.fieldType === FieldType.Checklist && <ChecklistTypeSvg></ChecklistTypeSvg>}
  48. {cellIdentifier.fieldType === FieldType.URL && <UrlTypeSvg></UrlTypeSvg>}
  49. {cellIdentifier.fieldType === FieldType.Checkbox && <CheckboxSvg></CheckboxSvg>}
  50. </div>
  51. <span className={'overflow-hidden text-ellipsis whitespace-nowrap'}>
  52. {databaseStore.fields[cellIdentifier.fieldId].title}
  53. </span>
  54. </div>
  55. <div className={'flex-1 cursor-pointer rounded-lg px-4 py-2 hover:bg-shade-6'}>
  56. {(cellIdentifier.fieldType === FieldType.SingleSelect ||
  57. cellIdentifier.fieldType === FieldType.MultiSelect ||
  58. cellIdentifier.fieldType === FieldType.Checklist) && (
  59. <div className={'flex items-center gap-2'}>
  60. {(data as SelectOptionCellDataPB | undefined)?.select_options?.map((option, index) => (
  61. <div className={`${getBgColor(option.color)} rounded px-2 py-0.5 text-xs`} key={index}>
  62. {option?.name || ''}
  63. </div>
  64. )) || ''}
  65. </div>
  66. )}
  67. {cellIdentifier.fieldType === FieldType.Checkbox && (
  68. <div className={'h-8 w-8'}>
  69. {(data as boolean | undefined) ? <EditorCheckSvg></EditorCheckSvg> : <EditorUncheckSvg></EditorUncheckSvg>}
  70. </div>
  71. )}
  72. {cellIdentifier.fieldType === FieldType.DateTime && <div>{(data as DateCellDataPB | undefined)?.date}</div>}
  73. {(cellIdentifier.fieldType === FieldType.RichText ||
  74. cellIdentifier.fieldType === FieldType.URL ||
  75. cellIdentifier.fieldType === FieldType.Number) &&
  76. cellController && <EditCellText data={data as string} cellController={cellController}></EditCellText>}
  77. </div>
  78. </div>
  79. );
  80. };