GridSingleSelectOptions.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { useState } from 'react';
  2. import { CellOptions } from '$app/components/_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 '$app/components/_shared/database-hooks/useCell';
  7. import { SelectOptionCellDataPB, SelectOptionPB } from '@/services/backend/models/flowy-database/select_type_option';
  8. import { CellOptionsPopup } from '$app/components/_shared/EditRow/CellOptionsPopup';
  9. import { EditCellOptionPopup } from '$app/components/_shared/EditRow/EditCellOptionPopup';
  10. export default function GridSingleSelectOptions({
  11. cellIdentifier,
  12. cellCache,
  13. fieldController,
  14. }: {
  15. cellIdentifier: CellIdentifier;
  16. cellCache: CellCache;
  17. fieldController: FieldController;
  18. }) {
  19. const { data } = useCell(cellIdentifier, cellCache, fieldController);
  20. const [showOptionsPopup, setShowOptionsPopup] = useState(false);
  21. const [changeOptionsTop, setChangeOptionsTop] = useState(0);
  22. const [changeOptionsLeft, setChangeOptionsLeft] = useState(0);
  23. const [showEditCellOption, setShowEditCellOption] = useState(false);
  24. const [editCellOptionTop, setEditCellOptionTop] = useState(0);
  25. const [editCellOptionLeft, setEditCellOptionLeft] = useState(0);
  26. const [editingSelectOption, setEditingSelectOption] = useState<SelectOptionPB | undefined>();
  27. const onEditOptionsClick = async (left: number, top: number) => {
  28. setChangeOptionsLeft(left);
  29. setChangeOptionsTop(top);
  30. setShowOptionsPopup(true);
  31. };
  32. const onOpenOptionDetailClick = (_left: number, _top: number, _select_option: SelectOptionPB) => {
  33. setEditingSelectOption(_select_option);
  34. setShowEditCellOption(true);
  35. setEditCellOptionLeft(_left);
  36. setEditCellOptionTop(_top);
  37. };
  38. return (
  39. <>
  40. <div className='flex w-full cursor-pointer justify-start'>
  41. <CellOptions data={data as SelectOptionCellDataPB} onEditClick={onEditOptionsClick} />
  42. </div>
  43. {showOptionsPopup && (
  44. <CellOptionsPopup
  45. top={changeOptionsTop}
  46. left={changeOptionsLeft}
  47. cellIdentifier={cellIdentifier}
  48. cellCache={cellCache}
  49. fieldController={fieldController}
  50. onOutsideClick={() => setShowOptionsPopup(false)}
  51. openOptionDetail={onOpenOptionDetailClick}
  52. />
  53. )}
  54. {showEditCellOption && editingSelectOption && (
  55. <EditCellOptionPopup
  56. top={editCellOptionTop}
  57. left={editCellOptionLeft}
  58. cellIdentifier={cellIdentifier}
  59. editingSelectOption={editingSelectOption}
  60. onOutsideClick={() => {
  61. setShowEditCellOption(false);
  62. }}
  63. ></EditCellOptionPopup>
  64. )}
  65. </>
  66. );
  67. }