LockedQuerySection.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import type { PGPolicy } from '@supabase/pg-meta'
  2. import { Lock } from 'lucide-react'
  3. interface LockedCreateQuerySection {
  4. schema: string
  5. selectedPolicy?: PGPolicy
  6. isRenamingPolicy: boolean
  7. formFields: { name: string; table: string; behavior: string; command: string; roles: string }
  8. }
  9. export const LockedCreateQuerySection = ({
  10. schema,
  11. isRenamingPolicy,
  12. selectedPolicy,
  13. formFields,
  14. }: LockedCreateQuerySection) => {
  15. const isEditing = selectedPolicy !== undefined
  16. const { name, table, behavior, command, roles } = formFields
  17. return (
  18. <div className="bg-surface-300 pt-2 pb-1">
  19. <div className="flex items-center justify-between px-5 mb-1">
  20. <div className="flex items-center">
  21. <div className="pl-0.5 pr-5 flex items-center justify-center">
  22. <Lock size={14} className="text-foreground-lighter" />
  23. </div>
  24. <p className="text-xs text-foreground-lighter font-mono uppercase">
  25. Use options above to edit
  26. </p>
  27. </div>
  28. </div>
  29. <div className="flex items-start" style={{ fontSize: '14px' }}>
  30. <p className="px-6 font-mono text-sm text-foreground-light select-none">1</p>
  31. <p className="font-mono tracking-tighter">
  32. <span className="text-[#569cd6]">{isEditing ? 'alter' : 'create'}</span> policy "
  33. {isRenamingPolicy ? selectedPolicy?.name : name.length === 0 ? 'policy_name' : name}"
  34. </p>
  35. </div>
  36. <div className="flex items-start" style={{ fontSize: '14px' }}>
  37. <p className="px-6 font-mono text-sm text-foreground-light select-none">2</p>
  38. <p className="font-mono tracking-tighter">
  39. <span className="text-[#569cd6]">on</span> "{schema}"."
  40. {table}"
  41. </p>
  42. </div>
  43. {!isEditing && (
  44. <>
  45. <div className="flex items-start" style={{ fontSize: '14px' }}>
  46. <p className="px-6 font-mono text-sm text-foreground-light select-none">3</p>
  47. <p className="font-mono tracking-tighter">
  48. <span className="text-[#569cd6]">as</span> {behavior.toLocaleUpperCase()}
  49. </p>
  50. </div>
  51. <div className="flex items-start" style={{ fontSize: '14px' }}>
  52. <p className="px-6 font-mono text-sm text-foreground-light select-none">4</p>
  53. <p className="font-mono tracking-tighter">
  54. <span className="text-[#569cd6]">for</span> {command.toLocaleUpperCase()}
  55. </p>
  56. </div>
  57. </>
  58. )}
  59. <div className="flex items-start" style={{ fontSize: '14px' }}>
  60. <p className="px-6 font-mono text-sm text-foreground-light select-none">5</p>
  61. <p className="font-mono tracking-tighter">
  62. <span className="text-[#569cd6]">to</span> {roles.length === 0 ? 'public' : roles}
  63. </p>
  64. </div>
  65. <div className="flex items-start" style={{ fontSize: '14px' }}>
  66. <p className="px-6 font-mono text-sm text-foreground-light select-none">6</p>
  67. <p className="font-mono tracking-tighter">
  68. <span className="text-[#569cd6]">{command === 'insert' ? 'with check' : 'using'}</span>{' '}
  69. <span className="text-[#ffd700]">(</span>
  70. </p>
  71. </div>
  72. </div>
  73. )
  74. }
  75. export const LockedRenameQuerySection = ({
  76. oldName,
  77. newName,
  78. schema,
  79. table,
  80. lineNumber,
  81. }: {
  82. oldName: string
  83. newName: string
  84. schema: string
  85. table: string
  86. lineNumber: number
  87. }) => {
  88. return (
  89. <div className="bg-surface-300 py-1">
  90. <div className="flex items-center" style={{ fontSize: '14px' }}>
  91. <div className="w-[57px]">
  92. <p className="w-[31px] flex justify-end font-mono text-sm text-foreground-light select-none">
  93. {lineNumber}
  94. </p>
  95. </div>
  96. <p className="font-mono tracking-tighter">
  97. <span className="text-[#569cd6]">alter</span> policy "{oldName}"
  98. </p>
  99. </div>
  100. <div className="flex items-center" style={{ fontSize: '14px' }}>
  101. <div className="w-[57px]">
  102. <p className="w-[31px] flex justify-end font-mono text-sm text-foreground-light select-none">
  103. {lineNumber + 1}
  104. </p>
  105. </div>
  106. <p className="font-mono tracking-tighter">
  107. <span className="text-[#569cd6]">on</span> "{schema}"."{table}"
  108. </p>
  109. </div>
  110. <div className="flex items-center" style={{ fontSize: '14px' }}>
  111. <div className="w-[57px]">
  112. <p className="w-[31px] flex justify-end font-mono text-sm text-foreground-light select-none">
  113. {lineNumber + 2}
  114. </p>
  115. </div>
  116. <p className="font-mono tracking-tighter">
  117. <span className="text-[#569cd6]">rename</span> to "{newName}";
  118. </p>
  119. </div>
  120. </div>
  121. )
  122. }