Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 4.0.3 #432

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": true,
"decorators": false,
"dynamicImport": true
}
}
}
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).

## [4.0.3]

### Changed
- Countries list is now loaded from php file and not from the manifest json.

### Removed
- Countries list from cache.

### Added
- Translations for the countries list for 14 languages.

## [4.0.2]

### Fixed
Expand Down Expand Up @@ -423,6 +434,7 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a

- Initial production release.

[4.0.3]: https://github.com/infinum/eightshift-forms/compare/4.0.2...4.0.3
[4.0.2]: https://github.com/infinum/eightshift-forms/compare/4.0.1...4.0.2
[4.0.1]: https://github.com/infinum/eightshift-forms/compare/4.0.0...4.0.1
[4.0.0]: https://github.com/infinum/eightshift-forms/compare/3.1.12...4.0.0
Expand Down
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion eightshift-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Description: Eightshift Forms is a complete form builder plugin that utilizes modern Block editor features with multiple third-party integrations, bringing your project to a new level.
* Author: WordPress team @Infinum
* Author URI: https://eightshift.com/
* Version: 4.0.2
* Version: 4.0.3
* Text Domain: eightshift-forms
*
* @package EightshiftForms
Expand Down
3,588 changes: 2,443 additions & 1,145 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@eightshift/frontend-libs": "^12.0.0",
"@eightshift/frontend-libs": "^12.1.4",
"autosize": "^6.0.1",
"choices.js": "^10.2.0",
"dropzone": "^6.0.0-beta.2",
Expand Down
151 changes: 10 additions & 141 deletions src/Blocks/SettingsBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@

namespace EightshiftForms\Blocks;

use EightshiftForms\Cache\ManifestCache;
use EightshiftForms\Cache\SettingsCache;
use EightshiftForms\Countries\CountriesInterface;
use EightshiftForms\Geolocation\GeolocationInterface;
use EightshiftFormsVendor\EightshiftFormsUtils\Helpers\UtilsDeveloperHelper;
use EightshiftFormsVendor\EightshiftFormsUtils\Helpers\UtilsHooksHelper;
use EightshiftFormsVendor\EightshiftFormsUtils\Settings\UtilsSettingGlobalInterface;
use EightshiftFormsVendor\EightshiftFormsUtils\Helpers\UtilsSettingsHelper;
use EightshiftFormsVendor\EightshiftFormsUtils\Helpers\UtilsSettingsOutputHelper;
use EightshiftFormsVendor\EightshiftFormsUtils\Settings\UtilsSettingInterface;
use EightshiftFormsVendor\EightshiftLibs\Cache\ManifestCacheInterface;
use EightshiftFormsVendor\EightshiftLibs\Services\ServiceInterface;

/**
Expand Down Expand Up @@ -47,11 +43,6 @@ class SettingsBlocks implements UtilsSettingGlobalInterface, UtilsSettingInterfa
*/
public const SETTINGS_TYPE_KEY = 'blocks';

/**
* Transient cache name for block country data set. No need to flush it because it is short live.
*/
public const CACHE_BLOCK_COUNTRY_DATE_SET_NAME = 'es_block_country_data_set_cache';

/**
* Country keys.
*/
Expand Down Expand Up @@ -79,24 +70,24 @@ class SettingsBlocks implements UtilsSettingGlobalInterface, UtilsSettingInterfa
private GeolocationInterface $geolocation;

/**
* Instance variable for manifest cache.
* Instance variable of countries data.
*
* @var ManifestCacheInterface
* @var CountriesInterface
*/
private $manifestCache;
private CountriesInterface $countries;

/**
* Create a new admin instance.
*
* @param GeolocationInterface $geolocation Inject geolocation which holds data about for storing to geolocation.
* @param ManifestCacheInterface $manifestCache Inject manifest cache.
* @param CountriesInterface $countries Inject countries which holds data about for storing to countries.
*/
public function __construct(
GeolocationInterface $geolocation,
ManifestCacheInterface $manifestCache
CountriesInterface $countries
) {
$this->geolocation = $geolocation;
$this->manifestCache = $manifestCache;
$this->countries = $countries;
}

/**
Expand Down Expand Up @@ -261,7 +252,7 @@ public function getSettingsGlobalData(): array
'textareaIsReadOnly' => true,
'textareaIsPreventSubmit' => true,
'textareaName' => 'country',
'textareaValue' => \wp_json_encode($this->getCountriesDataSet(), \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE),
'textareaValue' => \wp_json_encode($this->countries->getCountriesDataSet(), \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE),
'textareaSize' => 'huge',
'textareaLimitHeight' => true,
],
Expand Down Expand Up @@ -345,129 +336,7 @@ public function getCountryDatasetValue(string $formId): array
'dataset' => $phoneDatasetValue,
'preselectedValue' => $preselectedValue,
],
'countries' => $this->getCountriesDataSet(),
];
}

/**
* Get countries data set depending on the provided filter and default set.
*
* @param bool $useFullOutput Used to output limited output used for seetings and output.
*
* @return array<string, mixed>
*/
private function getCountriesDataSet(bool $useFullOutput = true): array
{
$output = \get_transient(SettingsBlocks::CACHE_BLOCK_COUNTRY_DATE_SET_NAME) ?: []; // phpcs:ignore WordPress.PHP.DisallowShortTernary.Found

// Prevent cache.
if (UtilsDeveloperHelper::isDeveloperSkipCacheActive()) {
$output = [];
}

if (!$output) {
$countries = $this->manifestCache->getManifestCacheTopItem(ManifestCache::COUNTRIES_KEY, ManifestCache::TYPE_FORMS);

$output = [
'default' => [
'label' => \__('Default', 'eightshift-forms'),
'slug' => 'default',
'items' => $countries,
'codes' => \array_map(
static function ($item) {
return [
'label' => $item[0],
'value' => $item[1],
];
},
$countries
)
]
];

$alternative = [];
$filterName = UtilsHooksHelper::getFilterName(['block', 'country', 'alternativeDataSet']);
if (\has_filter($filterName)) {
$alternative = \apply_filters($filterName, []);
}

$alternativeOutput = [];

if ($alternative) {
foreach ($alternative as $value) {
$label = $value['label'] ?? '';
$slug = $value['slug'] ?? '';
$removed = isset($value['remove']) ? \array_flip($value['remove']) : [];
$onlyUse = isset($value['onlyUse']) ? \array_flip($value['onlyUse']) : [];
$changed = $value['change'] ?? [];

if (!$label || !$slug) {
continue;
}

$slug = \strtolower(\str_replace(' ', '-', $slug));

$alternativeOutput[$slug] = [
'label' => $label,
'slug' => $slug,
'items' => $countries,
];

$itemOutput = [];

foreach ($alternativeOutput[$slug]['items'] as $key => $item) {
$countryCode = $item[1] ? \strtolower($item[1]) : '';

// Only use.
if ($onlyUse && !isset($onlyUse[$countryCode])) {
continue;
}

// Remove item from list.
if (isset($removed[$countryCode])) {
continue;
}

// // Change label in the list.
foreach ($changed as $changedKey => $changedValue) {
if ($countryCode === $changedKey) {
$item[0] = $changedValue;
}
}

$itemOutput[] = $item;
}


$alternativeOutput[$slug]['items'] = $itemOutput;
}
}

$output = \array_merge(
$alternativeOutput,
$output,
);

\set_transient(SettingsBlocks::CACHE_BLOCK_COUNTRY_DATE_SET_NAME, $output, SettingsCache::CACHE_TRANSIENTS_TIMES['quick']);
}

if ($useFullOutput) {
return $output;
}

return [
'label' => $output['default']['label'],
'slug' => $output['default']['slug'],
'items' => \array_values(\array_map(
static function ($item) {
return [
'label' => $item['label'],
'value' => $item['slug'],
];
},
$output
)),
'codes' => $output['default']['codes'],
'countries' => $this->countries->getCountriesDataSet(),
];
}

Expand Down Expand Up @@ -497,7 +366,7 @@ function ($option) use ($selectedValue) {
'selectOptionIsSelected' => $value === $selectedValue,
];
},
$this->getCountriesDataSet(false)[$list]
$this->countries->getCountriesDataSet(false)[$list]
);
}
}
11 changes: 0 additions & 11 deletions src/Cache/ManifestCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace EightshiftForms\Cache;

use EightshiftFormsVendor\EightshiftFormsUtils\Config\UtilsConfig;
use EightshiftFormsVendor\EightshiftFormsUtils\Helpers\UtilsDataHelper;
use EightshiftFormsVendor\EightshiftLibs\Cache\AbstractManifestCache;
use EightshiftFormsVendor\EightshiftLibs\Helpers\Helpers;

Expand All @@ -29,13 +28,6 @@ class ManifestCache extends AbstractManifestCache
*/
public const TYPE_FORMS = 'forms';

/**
* Cache key - countries.
*
* @var string
*/
public const COUNTRIES_KEY = 'countries';

/**
* Cache key - countries.
*
Expand Down Expand Up @@ -92,9 +84,6 @@ protected function getCacheBuilder(): array
parent::getCacheBuilder(),
[
self::TYPE_FORMS => [
self::COUNTRIES_KEY => [
'pathCustom' => UtilsDataHelper::getDataManifestPath('countries'),
],
self::TLD_KEY => [
'fileName' => "Validation{$sep}manifest.json",
'path' => 'srcDestination',
Expand Down
Loading
Loading