@@ -19,7 +19,7 @@ import Acknowledgements from "@/components/Acknowledgements";
1919import { getAccessToken } from "@auth0/nextjs-auth0" ;
2020import { BookmarkService } from "@/lib/bookmarkService" ;
2121import Discussion from "@/components/Discussion" ;
22- import { useRouter } from "next/navigation" ;
22+ import { useRouter , usePathname } from "next/navigation" ;
2323import { ICON_SIZE } from "@/constants" ;
2424import { extractUsernameFromUrl } from "@/lib/services/github" ;
2525import Breadcrumbs from "@/components/Breadcrumbs" ;
@@ -40,7 +40,33 @@ export default function ClientRulePage(props: ClientRulePageProps) {
4040 const [ authorUsername , setAuthorUsername ] = useState < string | null > ( null ) ;
4141 const relatedRules = props . relatedRulesMapping || [ ] ;
4242 const router = useRouter ( ) ;
43+ const pathname = usePathname ( ) ;
44+ const [ isAdminPage , setIsAdminPage ] = useState ( false ) ;
4345 const [ isLoadingUsername , setIsLoadingUsername ] = useState ( false ) ;
46+
47+ useEffect ( ( ) => {
48+ // Check if we're inside TinaCMS admin iframe
49+ if ( typeof window === 'undefined' ) return ;
50+
51+ const isInIframe = window . self !== window . top ;
52+ let parentIsAdmin = false ;
53+
54+ if ( isInIframe ) {
55+ try {
56+ parentIsAdmin = window . top ?. location . pathname . includes ( '/admin' ) || false ;
57+ } catch ( e ) {
58+ // If we can't access parent URL but we're in iframe, assume it's admin
59+ // TinaCMS always renders the preview in an iframe
60+ parentIsAdmin = true ;
61+ }
62+ }
63+
64+ const isAdmin = pathname ?. includes ( '/admin' ) ||
65+ window . location . pathname . includes ( '/admin' ) ||
66+ parentIsAdmin ;
67+
68+ setIsAdminPage ( isAdmin ) ;
69+ } , [ pathname ] ) ;
4470 const ruleData = useTina ( {
4571 query : ruleQueryProps ?. query ,
4672 variables : ruleQueryProps ?. variables ,
@@ -194,24 +220,28 @@ export default function ClientRulePage(props: ClientRulePageProps) {
194220 </ a >
195221 </ p >
196222 < div className = "flex items-center gap-4 text-2xl" >
197- < Bookmark
198- ruleGuid = { rule ?. guid || '' }
223+ < Bookmark
224+ ruleGuid = { rule ?. guid || '' }
199225 isBookmarked = { isBookmarked }
200226 onBookmarkToggle = { ( newStatus ) => setIsBookmarked ( newStatus ) }
201227 />
202- < IconLink
203- href = { `/admin#/~/${ sanitizedBasePath } /${ rule ?. uri } ` }
204- title = "Edit rule"
205- tooltipOpaque = { true }
206- children = { < RiPencilLine size = { ICON_SIZE } /> }
207- />
208- < IconLink
209- href = { `https://github.com/SSWConsulting/SSW.Rules.Content/blob/main/rules/${ rule ?. uri } /rule.md` }
210- target = "_blank"
211- title = "View rule on GitHub"
212- tooltipOpaque = { true }
213- children = { < RiGithubLine size = { ICON_SIZE } className = "rule-icon" /> }
214- />
228+ { ! isAdminPage && (
229+ < >
230+ < IconLink
231+ href = { `/admin#/~/${ sanitizedBasePath } /${ rule ?. uri } ` }
232+ title = "Edit rule"
233+ tooltipOpaque = { true }
234+ children = { < RiPencilLine size = { ICON_SIZE } /> }
235+ />
236+ < IconLink
237+ href = { `https://github.com/SSWConsulting/SSW.Rules.Content/blob/main/rules/${ rule ?. uri } /rule.md` }
238+ target = "_blank"
239+ title = "View rule on GitHub"
240+ tooltipOpaque = { true }
241+ children = { < RiGithubLine size = { ICON_SIZE } className = "rule-icon" /> }
242+ />
243+ </ >
244+ ) }
215245 </ div >
216246 </ div >
217247 </ div >
0 commit comments