/** * External dependencies */ import { CodeEditor } from '@nab/code-editor'; import type { CustomPhpScopeRule, Maybe, ScopeRule } from '@nab/types'; /** * Internal dependencies */ import './style.scss'; import { CustomUrlScope } from '../custom-url-scope'; import { getScopeExplanation } from '../explanation'; import { useExperimentAttribute } from '../../../hooks'; export const UrlsOrPhpScope = (): JSX.Element => { const rules = useExperimentAttribute( 'scope' ) || []; const status = useExperimentAttribute( 'status' ) ?? 'running'; const [ firstRule ] = rules; if ( isCustomPhpScopeRule( firstRule ) ) { return ; } if ( ! rules.length ) { return

{ getScopeExplanation( 'urls', [], status ) }

; } return ; }; // ============ // HELPER VIEWS // ============ const PhpCode = ( { rule, }: { readonly rule: CustomPhpScopeRule; } ): JSX.Element => { const status = useExperimentAttribute( 'status' ) ?? 'running'; return (

{ getScopeExplanation( 'urls-or-php', [ rule ], status ) }

line.replaceAll( '\t', ' ' ) ) .map( ( line ) => ` ${ line }` ), '}', ].join( '\n' ) } readOnly />
); }; // ======= // HELPERS // ======= export const isCustomPhpScopeRule = ( r: Maybe< ScopeRule > ): r is CustomPhpScopeRule => 'php-snippet' === r?.attributes.type;