PolicyEditorModalTitle.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { noop } from 'lodash'
  2. import { ChevronLeft, FlaskConical } from 'lucide-react'
  3. import { Button } from 'ui'
  4. import { POLICY_MODAL_VIEWS } from '../Policies.constants'
  5. import { DocsButton } from '@/components/ui/DocsButton'
  6. import { DOCS_URL } from '@/lib/constants'
  7. interface PolicyEditorModalTitleProps {
  8. view: string
  9. schema: string
  10. table: string
  11. isNewPolicy: boolean
  12. showAssistantPreview: boolean
  13. onSelectBackFromTemplates: () => void
  14. onToggleFeaturePreviewModal: () => void
  15. }
  16. const PolicyEditorModalTitle = ({
  17. view,
  18. schema,
  19. table,
  20. isNewPolicy,
  21. showAssistantPreview,
  22. onSelectBackFromTemplates = noop,
  23. onToggleFeaturePreviewModal,
  24. }: PolicyEditorModalTitleProps) => {
  25. const getTitle = () => {
  26. if (view === POLICY_MODAL_VIEWS.EDITOR || view === POLICY_MODAL_VIEWS.SELECTION) {
  27. return `${isNewPolicy ? 'Adding new policy to' : 'Editing policy from'} ${schema}.${table}`
  28. }
  29. if (view === POLICY_MODAL_VIEWS.REVIEW) {
  30. return `Reviewing policy to be ${isNewPolicy ? 'created' : 'updated'} on ${schema}.${table}`
  31. }
  32. }
  33. if (view === POLICY_MODAL_VIEWS.TEMPLATES) {
  34. return (
  35. <div>
  36. <div className="flex items-center space-x-3">
  37. <span
  38. onClick={onSelectBackFromTemplates}
  39. className="cursor-pointer text-foreground-lighter transition-colors hover:text-foreground"
  40. >
  41. <ChevronLeft strokeWidth={2} size={14} />
  42. </span>
  43. <h4>Select a template to use for your new policy</h4>
  44. </div>
  45. </div>
  46. )
  47. }
  48. return (
  49. <div className="w-full flex items-center justify-between gap-x-4">
  50. <h4 className="truncate" title={getTitle()}>
  51. {getTitle()}
  52. </h4>
  53. <div className="flex items-center gap-x-2 pr-6">
  54. {showAssistantPreview && view === POLICY_MODAL_VIEWS.EDITOR && (
  55. <Button type="default" icon={<FlaskConical />} onClick={onToggleFeaturePreviewModal}>
  56. Try Briven Assistant
  57. </Button>
  58. )}
  59. <DocsButton className="mt-[-4px]" href={`${DOCS_URL}/learn/auth-deep-dive/auth-policies`} />
  60. </div>
  61. </div>
  62. )
  63. }
  64. export default PolicyEditorModalTitle