<commit_before>/**
 * GA4 Property Select component.
 *
 * Site Kit by Google, Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * WordPress dependencies
 */
import { useCallback } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';

/**
 * Internal dependencies
 */
import Data from 'googlesitekit-data';
import { Select, Option } from '../../../../material-components';
import ProgressBar from '../../../../components/ProgressBar';
import { MODULES_ANALYTICS_4, PROPERTY_CREATE } from '../../../analytics-4/datastore/constants';
import { MODULES_ANALYTICS } from '../../datastore/constants';
import { isValidAccountID } from '../../util';
import { trackEvent } from '../../../../util';
const { useSelect, useDispatch } = Data;

export default function PropertySelectIncludingGA4() {
// TODO: Update this select hook to pull accountID from the modules/analytics-4 datastore when GA4 module becomes separated from the Analytics one
	const accountID = useSelect( ( select ) => select( MODULES_ANALYTICS ).getAccountID() );
	const unmappedProperties = useSelect( ( select ) => select( MODULES_ANALYTICS ).getPropertiesIncludingGA4( accountID ) || [] );
	const propertyID = useSelect( ( select ) => select( MODULES_ANALYTICS_4 ).getPropertyID() );
	const isLoading = useSelect( ( select ) => (
		! select( MODULES_ANALYTICS ).hasFinishedResolution( 'getAccounts' ) ||
	! select( MODULES_ANALYTICS_4 ).hasFinishedResolution( 'getProperties', [ accountID ] )
	) );

	const { selectProperty: selectPropertyGA4 } = useDispatch( MODULES_ANALYTICS_4 );
	const { selectProperty: selectPropertyUA, setPrimaryPropertyType } = useDispatch( MODULES_ANALYTICS );

	const onChange = useCallback( ( index, item ) => {
		// TODO - check this with ua properties
		// console.debug( 'CLICK property ID ', item.dataset.value );

		const newPropertyID = item.dataset.value;
		if ( propertyID !== newPropertyID ) {
			trackEvent( 'analytics_setup', 'property_change', newPropertyID );
			if ( newPropertyID.startsWith( 'UA-' ) ) {
				selectPropertyUA( newPropertyID );
				setPrimaryPropertyType( 'ua' );

				// TODO - this requires lots of changes BUT AC mentions it...
				// selectPropertyGA4( null );
			} else {
				selectPropertyGA4( newPropertyID );
				setPrimaryPropertyType( 'ga4' );

				// TODO - this requires lots of changes BUT AC mentions it...
				// selectPropertyUA( null );
			}
		}
	}, [ propertyID, selectPropertyGA4, selectPropertyUA, setPrimaryPropertyType ] );

	if ( isLoading ) {
		return <ProgressBar small />;
	}

	// TEMP FIX SO TESTS PASS
	// not sure if should even map! better to instead support this in the component? how will know which is which when clicked?
	const properties = unmappedProperties.map( ( p ) => {
		// console.log( p );
		// no idea why nullish... seems like mistake
		if ( p?._id ) {<commit_msg>Namespace selectors now getting complex.<commit_after>/**
 * GA4 Property Select component.
 *
 * Site Kit by Google, Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * WordPress dependencies
 */
import { useCallback } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';

/**
 * Internal dependencies
 */
import Data from 'googlesitekit-data';
import { Select, Option } from '../../../../material-components';
import ProgressBar from '../../../../components/ProgressBar';
import { MODULES_ANALYTICS_4, PROPERTY_CREATE } from '../../../analytics-4/datastore/constants';
import { MODULES_ANALYTICS } from '../../datastore/constants';
import { isValidAccountID } from '../../util';
import { trackEvent } from '../../../../util';
const { useSelect, useDispatch } = Data;

export default function PropertySelectIncludingGA4() {
// TODO: Update this select hook to pull accountID from the modules/analytics-4 datastore when GA4 module becomes separated from the Analytics one
	const accountID = useSelect( ( select ) => select( MODULES_ANALYTICS ).getAccountID() );
	const unmappedProperties = useSelect( ( select ) => select( MODULES_ANALYTICS ).getPropertiesIncludingGA4( accountID ) || [] );
	const propertyID = useSelect( ( select ) => select( MODULES_ANALYTICS_4 ).getPropertyID() );
	const isLoading = useSelect( ( select ) => (
		! select( MODULES_ANALYTICS ).hasFinishedResolution( 'getAccounts' ) ||
	! select( MODULES_ANALYTICS_4 ).hasFinishedResolution( 'getProperties', [ accountID ] )
	) );

	const ga4Dispatch = useDispatch( MODULES_ANALYTICS_4 );
	const uaDispatch = useDispatch( MODULES_ANALYTICS );

	const onChange = useCallback( ( index, item ) => {
		// TODO - check this with ua properties
		// console.debug( 'CLICK property ID ', item.dataset.value );

		const newPropertyID = item.dataset.value;
		if ( propertyID !== newPropertyID ) {
			trackEvent( 'analytics_setup', 'property_change', newPropertyID );
			if ( newPropertyID.startsWith( 'UA-' ) ) {
				uaDispatch.selectPropertyUA( newPropertyID );
				uaDispatch.setPrimaryPropertyType( 'ua' );

				// TODO - this requires lots of changes BUT AC mentions it...
				// selectPropertyGA4( null );
			} else {
				ga4Dispatch.selectProperty( newPropertyID );
				uaDispatch.setPrimaryPropertyType( 'ga4' );

				// TODO - this requires lots of changes BUT AC mentions it...
				// selectPropertyUA( null );
			}
		}
	}, [ propertyID, ga4Dispatch, uaDispatch ] );

	if ( isLoading ) {
		return <ProgressBar small />;
	}

	// TEMP FIX SO TESTS PASS
	// not sure if should even map! better to instead support this in the component? how will know which is which when clicked?
	const properties = unmappedProperties.map( ( p ) => {
		// console.log( p );
		// no idea why nullish... seems like mistake
		if ( p?._id ) {
{'fraction_non_alphanumeric': 0.12257299540536534, 'fraction_numerical': 0.007410701052319549, 'mean_word_length': 3.7454289732770745, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1696675', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1918, 'n_words': 642}