GridSingleSelectOptions.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { useState } from 'react';
  2. import { CellOptions } from '../../_shared/EditRow/CellOptions';
  3. import { CellIdentifier } from '@/appflowy_app/stores/effects/database/cell/cell_bd_svc';
  4. import { CellCache } from '@/appflowy_app/stores/effects/database/cell/cell_cache';
  5. import { FieldController } from '@/appflowy_app/stores/effects/database/field/field_controller';
  6. import { useCell } from '../../_shared/database-hooks/useCell';
  7. import { SelectOptionCellDataPB } from '@/services/backend/models/flowy-database/select_type_option';
  8. import { CellOptionsPopup } from '../../_shared/EditRow/CellOptionsPopup';
  9. export default function GridSingleSelectOptions({
  10. cellIdentifier,
  11. cellCache,
  12. fieldController,
  13. }: {
  14. cellIdentifier: CellIdentifier;
  15. cellCache: CellCache;
  16. fieldController: FieldController;
  17. }) {
  18. const { data } = useCell(cellIdentifier, cellCache, fieldController);
  19. const [showOptionsPopup, setShowOptionsPopup] = useState(false);
  20. const [changeOptionsTop, setChangeOptionsTop] = useState(0);
  21. const [changeOptionsLeft, setChangeOptionsLeft] = useState(0);
  22. const onEditOptionsClick = async (left: number, top: number) => {
  23. setChangeOptionsLeft(left);
  24. setChangeOptionsTop(top);
  25. setShowOptionsPopup(true);
  26. };
  27. return (
  28. <>
  29. <div className='flex w-full cursor-pointer justify-start'>
  30. <CellOptions data={data as SelectOptionCellDataPB} onEditClick={onEditOptionsClick} />
  31. </div>
  32. {showOptionsPopup && (
  33. <CellOptionsPopup
  34. top={changeOptionsTop}
  35. left={changeOptionsLeft}
  36. cellIdentifier={cellIdentifier}
  37. cellCache={cellCache}
  38. fieldController={fieldController}
  39. onOutsideClick={() => setShowOptionsPopup(false)}
  40. />
  41. )}
  42. </>
  43. );
  44. }