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