From 8429bf755c72875a41822ac7a7e2f008d31ae80f Mon Sep 17 00:00:00 2001 From: Wilker Mesquita Date: Wed, 1 Feb 2023 16:42:02 -0300 Subject: [PATCH 01/26] Enabling Nova4 and updating package.json and composer.json files --- .gitignore | 2 ++ composer.json | 9 ++++----- mix.js | 40 +++++++++++++++++++++++++++++++++++++++ package.json | 33 ++++++++++++++++++-------------- phpunit.xml.dist | 3 +-- resources/css/field.css | 0 resources/js/field.js | 6 +++--- resources/sass/field.scss | 1 - webpack.mix.js | 14 ++++++++++++-- 9 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 mix.js create mode 100644 resources/css/field.css delete mode 100644 resources/sass/field.scss diff --git a/.gitignore b/.gitignore index 8e4af26..e3493f6 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ phpunit.xml .DS_Store Thumbs.db .php_cs.cache + +auth.json diff --git a/composer.json b/composer.json index f4149f3..2e78aaf 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "license": "MIT", "require": { - "php": ">=7.1.0" + "php": "^7.4|^8.0" }, "repositories": [ { @@ -16,11 +16,10 @@ } ], "require-dev": { - "codedungeon/phpunit-result-printer": "^0.26.2", - "orchestra/testing": "^4.0", - "phpunit/phpunit": "^8.3", + "orchestra/testbench": "^7.4", + "phpunit/phpunit": "^9.5.10", "mockery/mockery": "^1.1", - "laravel/nova": "*" + "laravel/nova": "4.2" }, "autoload": { "psr-4": { diff --git a/mix.js b/mix.js new file mode 100644 index 0000000..d23678d --- /dev/null +++ b/mix.js @@ -0,0 +1,40 @@ +const mix = require('laravel-mix'); +const webpack = require('webpack'); +const path = require('path'); + +class NovaExtension { + name() { + return 'nova-extension'; + } + + register(name) { + this.name = name; + } + + webpackPlugins() { + return new webpack.ProvidePlugin({ + _: 'lodash', + Errors: 'form-backend-validation', + }); + } + + webpackConfig(webpackConfig) { + webpackConfig.externals = { + vue: 'Vue', + }; + + webpackConfig.resolve.alias = { + ...(webpackConfig.resolve.alias || {}), + 'laravel-nova': path.join( + __dirname, + '../../vendor/laravel/nova/resources/js/mixins/packages.js' + ), + }; + + webpackConfig.output = { + uniqueName: this.name, + }; + } +} + +mix.extend('nova', new NovaExtension()) diff --git a/package.json b/package.json index 72cdfd0..6b6809d 100644 --- a/package.json +++ b/package.json @@ -2,24 +2,29 @@ "private": true, "scripts": { "dev": "npm run development", - "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", - "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", - "watch-poll": "npm run watch -- --watch-poll", - "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", + "development": "mix", + "watch": "mix watch", + "watch-poll": "mix watch -- --watch-options-poll=1000", + "hot": "mix watch --hot", "prod": "npm run production", - "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" + "production": "mix --production" }, "devDependencies": { - "cross-env": "^5.0.0", - "laravel-mix": "^1.0", - "laravel-nova": "^1.0" - }, - "dependencies": { - "vue": "^2.5.0", - "vuedraggable": "^2.20.0", + "@inertiajs/inertia": "^0.11.0", + "@vue/babel-plugin-jsx": "^1.1.0", + "@vue/compiler-sfc": "^3.2.22", + "form-backend-validation": "^2.3.3", + "inflector-js": "^1.0.1", + "laravel-mix": "^6.0.41", + "lodash": "^4.17.21", + "postcss": "^8.3.11", + "vue-loader": "^16.8.3", + "vuex": "^4.0.2", "lodash.template": "^4.5.0", "mem": "^4.0.0", "js-yaml": "^3.13.1", - "webpack-dev-server": "^3.1.11" - } + "webpack-dev-server": "^3.1.11", + "vuedraggable": "^4.1.0" + }, + "dependencies": {} } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 55ae30c..a53649e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,8 +8,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" - printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer"> + stopOnFailure="false"> tests diff --git a/resources/css/field.css b/resources/css/field.css new file mode 100644 index 0000000..e69de29 diff --git a/resources/js/field.js b/resources/js/field.js index e22af62..4c5129d 100644 --- a/resources/js/field.js +++ b/resources/js/field.js @@ -1,7 +1,7 @@ Nova.booting(Vue => { - Vue.component('index-nova-inline-relationship', require('./components/IndexField')); - Vue.component('detail-nova-inline-relationship', require('./components/DetailField')); - Vue.component('form-nova-inline-relationship', require('./components/FormField')); + Vue.component('index-nova-inline-relationship', require('./components/IndexField').default); + Vue.component('detail-nova-inline-relationship', require('./components/DetailField').default); + Vue.component('form-nova-inline-relationship', require('./components/FormField').default); Vue.config.devtools = true; }); diff --git a/resources/sass/field.scss b/resources/sass/field.scss deleted file mode 100644 index f85ad40..0000000 --- a/resources/sass/field.scss +++ /dev/null @@ -1 +0,0 @@ -// Nova Tool CSS diff --git a/webpack.mix.js b/webpack.mix.js index d9623de..f75a28d 100644 --- a/webpack.mix.js +++ b/webpack.mix.js @@ -1,5 +1,15 @@ -let mix = require('laravel-mix') +let mix = require('laravel-mix'); +let path = require('path'); + +mix.alias({ + 'laravel-nova$': path.join(__dirname, 'vendor/laravel/nova/resources/js/mixins/packages.js'), + '@': path.join(__dirname, 'vendor/laravel/nova/resources/js') +}); + +require('./mix'); mix.setPublicPath('dist') .js('resources/js/field.js', 'js') - .sass('resources/sass/field.scss', 'css') + .vue({ version: 3 }) + .css('resources/css/field.css', 'css') + .nova('kirschbaum-development/inline-select'); From 572519133e10252ef1a4415806cc6364a213dfd5 Mon Sep 17 00:00:00 2001 From: Wilker Mesquita Date: Wed, 8 Feb 2023 21:03:54 -0300 Subject: [PATCH 02/26] Update field->options and request class --- src/NovaInlineRelationship.php | 25 ++++++++++++++++++++++--- src/NovaInlineRelationshipRequest.php | 13 ------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/NovaInlineRelationship.php b/src/NovaInlineRelationship.php index 613ce94..d65cd87 100644 --- a/src/NovaInlineRelationship.php +++ b/src/NovaInlineRelationship.php @@ -23,7 +23,7 @@ use Illuminate\Database\Eloquent\Relations\Concerns\SupportsDefaultModels; use KirschbaumDevelopment\NovaInlineRelationship\Traits\RequireRelationship; use KirschbaumDevelopment\NovaInlineRelationship\Observers\NovaInlineRelationshipObserver; - +use Laravel\Nova\Fields\Select; class NovaInlineRelationship extends Field { use RequireRelationship; @@ -431,7 +431,7 @@ protected function getRelationshipRule($attribute, Collection $properties): Rela protected function getPropertiesFromResource($model, $attribute): Collection { $fields = $this->getFieldsFromResource($model, $attribute); - + return $this->getPropertiesFromFields($fields) ->keyBy('attribute'); } @@ -474,7 +474,7 @@ protected function getPropertiesFromFields(Collection $fields): Collection return [ 'component' => get_class($value), 'label' => $value->name, - 'options' => $value->meta, + 'options' => $this->serializeOptions(data_get($value, 'optionsCallback'), false), 'rules' => $value->rules, 'attribute' => $value->attribute, ]; @@ -563,4 +563,23 @@ protected function setModelAttributeValue(Model $model, $attribute, array $value static::$observedModels[$modelClass][$attribute] = $this->isNullValue($value) ? null : $value; } + + /** + * Serialize options for the field. + * + * @param bool $searchable + * @return array> + */ + public function serializeOptions($optionsCallback) + { + $options = value($optionsCallback); + + if (is_callable($options)) { + $options = $options(); + } + + return collect($options ?? [])->map(function ($label, $value) { + return is_array($label) ? $label + ['value' => $value] : ['label' => $label, 'value' => $value]; + })->values()->all(); + } } diff --git a/src/NovaInlineRelationshipRequest.php b/src/NovaInlineRelationshipRequest.php index 4e3d964..2456500 100644 --- a/src/NovaInlineRelationshipRequest.php +++ b/src/NovaInlineRelationshipRequest.php @@ -9,19 +9,6 @@ class NovaInlineRelationshipRequest extends NovaRequest { - /** - * {@inheritdoc} - */ - public function duplicate( - array $query = null, - array $request = null, - array $attributes = null, - array $cookies = null, - array $files = null, - array $server = null - ) { - return parent::duplicate($query, $request, $attributes, $cookies, $files, $server); - } /** * Update list of converted files From 522244a6ef63d579d7f3f2162257088eeedeece8 Mon Sep 17 00:00:00 2001 From: Wilker Mesquita Date: Wed, 8 Feb 2023 21:04:25 -0300 Subject: [PATCH 03/26] Update details view --- resources/js/components/DetailField.vue | 47 ++++++++++--------- .../js/components/RelationshipDetailItem.vue | 20 ++------ 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/resources/js/components/DetailField.vue b/resources/js/components/DetailField.vue index cace43d..6ba1c21 100644 --- a/resources/js/components/DetailField.vue +++ b/resources/js/components/DetailField.vue @@ -1,27 +1,29 @@ diff --git a/resources/js/components/RelationshipFormItem.vue b/resources/js/components/RelationshipFormItem.vue index 47470e7..5299061 100644 --- a/resources/js/components/RelationshipFormItem.vue +++ b/resources/js/components/RelationshipFormItem.vue @@ -1,16 +1,11 @@ + From 121d57b36d603ba49e0034e1084ee4325757f087 Mon Sep 17 00:00:00 2001 From: Wilker Mesquita Date: Wed, 8 Feb 2023 21:32:41 -0300 Subject: [PATCH 05/26] cs-fix --- .github/workflows/code-style.yml | 2 +- .php_cs => .php-cs-fixer.php | 32 +++++++++---------- src/NovaInlineRelationship.php | 44 ++++++++++++++------------- src/NovaInlineRelationshipRequest.php | 1 - 4 files changed, 38 insertions(+), 41 deletions(-) rename .php_cs => .php-cs-fixer.php (80%) diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index 956d994..5b09e74 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -4,7 +4,7 @@ jobs: php-cs-fixer: runs-on: ubuntu-latest container: - image: kirschbaumdevelopment/laravel-test-runner:7.3.0 + image: kirschbaumdevelopment/laravel-test-runner:8.0 steps: - uses: actions/checkout@v1 diff --git a/.php_cs b/.php-cs-fixer.php similarity index 80% rename from .php_cs rename to .php-cs-fixer.php index 166b42b..86fd5c7 100644 --- a/.php_cs +++ b/.php-cs-fixer.php @@ -9,7 +9,7 @@ ->ignoreDotFiles(true) ->ignoreVCS(true); -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) ->setFinder($finder) ->setRules([ '@PSR2' => true, @@ -20,9 +20,14 @@ ], 'no_singleline_whitespace_before_semicolons' => true, 'no_extra_blank_lines' => [ - 'break', 'case', 'continue', 'curly_brace_block', 'default', - 'extra', 'parenthesis_brace_block', 'return', - 'square_brace_block', 'switch', 'throw', 'use', 'useTrait', 'use_trait', + 'tokens' => [ + 'curly_brace_block', + 'extra', + 'parenthesis_brace_block', + 'square_brace_block', + 'throw', + 'use', + ] ], 'cast_spaces' => [ 'space' => 'single', @@ -43,7 +48,7 @@ // 'increment_style' => ['style' => 'post'], 'short_scalar_cast' => true, 'class_attributes_separation' => [ - 'elements' => ['const', 'method', 'property'], + 'elements' => ['method' => 'one',], ], 'no_mixed_echo_print' => [ 'use' => 'echo', @@ -54,7 +59,7 @@ ], 'no_empty_statement' => true, 'unary_operator_spaces' => true, // $number ++ becomes $number++ - 'hash_to_slash_comment' => true, // # becomes // + 'single_line_comment_style' => true, // # becomes // 'standardize_not_equals' => true, // <> becomes != 'native_function_casing' => true, 'ternary_operator_spaces' => true, @@ -64,16 +69,7 @@ ], 'function_typehint_space' => true, 'no_leading_import_slash' => true, - 'blank_line_before_statement' => [ - 'statements' => [ - 'break', 'case', 'continue', - 'declare', 'default', 'die', - 'do', 'exit', 'for', 'foreach', - 'goto', 'if', 'include', - 'include_once', 'require', 'require_once', - 'return', 'switch', 'throw', 'try', 'while', 'yield', - ], - ], + 'blank_line_before_statement' => true, 'combine_consecutive_unsets' => true, 'method_chaining_indentation' => true, 'no_whitespace_in_blank_line' => true, @@ -84,7 +80,7 @@ 'compact_nullable_typehint' => true, 'explicit_string_variable' => true, 'no_leading_namespace_whitespace' => true, - 'trailing_comma_in_multiline_array' => true, + 'trailing_comma_in_multiline' => true, 'not_operator_with_successor_space' => true, 'object_operator_without_whitespace' => true, 'single_blank_line_before_namespace' => true, @@ -113,7 +109,7 @@ 'protected', 'private', ], - 'sortAlgorithm' => 'none', + 'sort_algorithm' => 'none', ], 'return_type_declaration' => [ 'space_before' => 'none', diff --git a/src/NovaInlineRelationship.php b/src/NovaInlineRelationship.php index d65cd87..056fd2c 100644 --- a/src/NovaInlineRelationship.php +++ b/src/NovaInlineRelationship.php @@ -23,7 +23,7 @@ use Illuminate\Database\Eloquent\Relations\Concerns\SupportsDefaultModels; use KirschbaumDevelopment\NovaInlineRelationship\Traits\RequireRelationship; use KirschbaumDevelopment\NovaInlineRelationship\Observers\NovaInlineRelationshipObserver; -use Laravel\Nova\Fields\Select; + class NovaInlineRelationship extends Field { use RequireRelationship; @@ -258,6 +258,27 @@ public function getValueFromField(Field $field, NovaInlineRelationshipRequest $r return $temp->{$attribute} ?? null; } + /** + * Serialize options for the field. + * + * @param bool $searchable + * @param mixed $optionsCallback + * + * @return array> + */ + public function serializeOptions($optionsCallback) + { + $options = value($optionsCallback); + + if (is_callable($options)) { + $options = $options(); + } + + return collect($options ?? [])->map(function ($label, $value) { + return is_array($label) ? $label + ['value' => $value] : ['label' => $label, 'value' => $value]; + })->values()->all(); + } + /** * Resolve the fields for the resource. * @@ -431,7 +452,7 @@ protected function getRelationshipRule($attribute, Collection $properties): Rela protected function getPropertiesFromResource($model, $attribute): Collection { $fields = $this->getFieldsFromResource($model, $attribute); - + return $this->getPropertiesFromFields($fields) ->keyBy('attribute'); } @@ -563,23 +584,4 @@ protected function setModelAttributeValue(Model $model, $attribute, array $value static::$observedModels[$modelClass][$attribute] = $this->isNullValue($value) ? null : $value; } - - /** - * Serialize options for the field. - * - * @param bool $searchable - * @return array> - */ - public function serializeOptions($optionsCallback) - { - $options = value($optionsCallback); - - if (is_callable($options)) { - $options = $options(); - } - - return collect($options ?? [])->map(function ($label, $value) { - return is_array($label) ? $label + ['value' => $value] : ['label' => $label, 'value' => $value]; - })->values()->all(); - } } diff --git a/src/NovaInlineRelationshipRequest.php b/src/NovaInlineRelationshipRequest.php index 2456500..d73bd7a 100644 --- a/src/NovaInlineRelationshipRequest.php +++ b/src/NovaInlineRelationshipRequest.php @@ -9,7 +9,6 @@ class NovaInlineRelationshipRequest extends NovaRequest { - /** * Update list of converted files * From 380e8d5281635bfe4ca1082fe3635f8a6cea8661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Dalmolin?= Date: Thu, 9 Feb 2023 14:12:57 -0300 Subject: [PATCH 06/26] Updated PHP version on CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80e654d..26ec7fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ jobs: phpunit: runs-on: ubuntu-latest container: - image: kirschbaumdevelopment/laravel-test-runner:7.3.0 + image: kirschbaumdevelopment/laravel-test-runner:8.0 services: mysql: From 78b168166a37c386c40b8ed19e996d348e1b42b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Dalmolin?= Date: Thu, 9 Feb 2023 14:57:44 -0300 Subject: [PATCH 07/26] Fixed composer nova config line --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26ec7fe..ece9f72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: Configure composer for Nova run: | - composer config "http-basic.nova.laravel.com" "${{ secrets.NOVA_USERNAME }}" "${{ secrets.NOVA_PASSWORD }}" + composer config 'http-basic.nova.laravel.com' '${{ secrets.NOVA_USERNAME }}' '${{ secrets.NOVA_PASSWORD }}' - name: Install composer dependencies run: | From f5231261763ead267b43d7958ad108a1c22c54c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Dalmolin?= Date: Thu, 9 Feb 2023 15:03:56 -0300 Subject: [PATCH 08/26] Using license key --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ece9f72..6f0fef7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,8 +23,7 @@ jobs: fetch-depth: 1 - name: Configure composer for Nova - run: | - composer config 'http-basic.nova.laravel.com' '${{ secrets.NOVA_USERNAME }}' '${{ secrets.NOVA_PASSWORD }}' + run: composer config 'http-basic.nova.laravel.com' '${{ secrets.NOVA_USERNAME }}' '${{ secrets.NOVA_LICENSE_KEY }}' - name: Install composer dependencies run: | From 631239e57688d9732abc3734374947d00e8176c9 Mon Sep 17 00:00:00 2001 From: Wilker Mesquita Date: Thu, 9 Feb 2023 15:42:27 -0300 Subject: [PATCH 09/26] Update PHPUnit files --- .gitignore | 1 + phpunit.xml.dist | 31 +++++++++++-------------------- phpunit.xml.dist.bak | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 phpunit.xml.dist.bak diff --git a/.gitignore b/.gitignore index e3493f6..ff38925 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ composer.phar composer.lock phpunit.xml .phpunit.result.cache +.php-cs-fixer.cache .DS_Store Thumbs.db .php_cs.cache diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a53649e..3c09220 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,13 @@ - - - - tests - - - - - src/ - - + + + + src/ + + + + + tests + + diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak new file mode 100644 index 0000000..a53649e --- /dev/null +++ b/phpunit.xml.dist.bak @@ -0,0 +1,22 @@ + + + + + tests + + + + + src/ + + + From 4464d7171537a0054354b829f7c72585cbba4799 Mon Sep 17 00:00:00 2001 From: Wilker Mesquita Date: Thu, 9 Feb 2023 15:42:36 -0300 Subject: [PATCH 10/26] Translation and plural changes --- resources/js/components/DetailField.vue | 2 +- resources/js/components/FormField.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/js/components/DetailField.vue b/resources/js/components/DetailField.vue index 6ba1c21..abb40d0 100644 --- a/resources/js/components/DetailField.vue +++ b/resources/js/components/DetailField.vue @@ -3,7 +3,7 @@