Skip to content

Commit

Permalink
Merge branch 'trunk' into feature/96-analytics-programs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomalec committed Jan 10, 2021
2 parents 09ac118 + 00d6ec1 commit 024f58e
Show file tree
Hide file tree
Showing 33 changed files with 1,018 additions and 176 deletions.
48 changes: 48 additions & 0 deletions bin/prefix-vendor-namespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env php
<?php
declare( strict_types=1 );

// phpcs:ignoreFile

$replacements = [
'League\\Container' => 'league/container',
'League\\ISO3166' => 'league/iso3166',
];
$vendor_dir = dirname( __DIR__ ) . '/vendor';
$new_namespace = 'Automattic\\WooCommerce\\GoogleListingsAndAds\\Vendor';

foreach ( $replacements as $namespace => $path ) {
$files = array_filter(
explode(
"\n",
`find {$vendor_dir}/{$path} -iname '*.php'`
)
);

$quoted = preg_quote( $namespace, '#' );
foreach ( $files as $file ) {
$contents = file_get_contents( $file );

// Check to see whether a replacement has already run. Just in case.
if ( false !== strpos( $contents, $new_namespace ) ) {
continue 2;
}

file_put_contents(
$file,
preg_replace(
"#^(\s*)(use|namespace)\s*({$quoted})#m",
"\$1\$2 {$new_namespace}\\\\\$3",
$contents
)
);
}

// Update the namespace in the composer.json file.
$composer_file = "{$vendor_dir}/{$path}/composer.json";
$composer_contents = file_get_contents( $composer_file );
file_put_contents(
$composer_file,
str_replace( "\"{$namespace}", "\"{$new_namespace}\\{$namespace}", $composer_contents )
);
}
29 changes: 0 additions & 29 deletions bin/prefix-vendor-namespaces.sh

This file was deleted.

10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"automattic/jetpack-connection": "^1.20",
"google/apiclient": "^2.7",
"googleads/google-ads-php": "^6.1",
"league/container": "^3.3"
"league/container": "^3.3",
"league/iso3166": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^6.5 || ^7",
Expand All @@ -21,7 +22,8 @@
"autoload": {
"psr-4": {
"Automattic\\WooCommerce\\GoogleListingsAndAds\\": "src/",
"Automattic\\WooCommerce\\GoogleListingsAndAds\\Vendor\\League\\Container\\": "vendor/league/container/src/"
"Automattic\\WooCommerce\\GoogleListingsAndAds\\Vendor\\League\\Container\\": "vendor/league/container/src/",
"Automattic\\WooCommerce\\GoogleListingsAndAds\\Vendor\\League\\ISO3166\\": "vendor/league/iso3166/src/"
}
},
"autoload-dev": {
Expand All @@ -38,11 +40,11 @@
"scripts": {
"post-install-cmd": [
"Google\\Task\\Composer::cleanup",
"sh ./bin/prefix-vendor-namespaces.sh"
"php ./bin/prefix-vendor-namespace.php"
],
"post-update-cmd": [
"Google\\Task\\Composer::cleanup",
"sh ./bin/prefix-vendor-namespaces.sh"
"php ./bin/prefix-vendor-namespace.php"
]
},
"extra": {
Expand Down
99 changes: 78 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion google-listings-and-ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function () {
);

/**
* Get out main container object.
* Get our main container object.
*
* @return ContainerInterface
*/
Expand Down
46 changes: 46 additions & 0 deletions js/src/components/app-country-multi-select/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* External dependencies
*/
import { SelectControl } from '@woocommerce/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import './index.scss';

const AppCountryMultiSelect = ( props ) => {
const { value = [], onChange = () => {} } = props;

// TODO: get list of countries from backend API.
const options = [
{
key: 'AUS',
label: 'Australia',
value: { id: 'AUS' },
},
{
key: 'USA',
label: 'United States of America',
value: { id: 'USA' },
},
];

return (
<SelectControl
className="app-country-multi-select"
multiple
isSearchable
inlineTags
options={ options }
placeholder={ __(
'Start typing to filter countries…',
'google-listings-and-ads'
) }
selected={ value }
onChange={ onChange }
/>
);
};

export default AppCountryMultiSelect;
20 changes: 20 additions & 0 deletions js/src/components/app-country-multi-select/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.app-country-multi-select {
// don't show the default magnifier icon.
i.material-icons-outlined {
display: none;
}

// CSS hacks to fix the input UI.
&.woocommerce-select-control {
.components-base-control {
.woocommerce-select-control__control-input,
.woocommerce-select-control__tags {
margin: 0;
}

.woocommerce-tag {
max-height: 24px;
}
}
}
}
Loading

0 comments on commit 024f58e

Please sign in to comment.