Overview

The original scope of this issue was folded into #3521002, see #3521002-20: [META] Maintainable client-side data model + internal HTTP API.

Per @balintbrews' request in #5 and #8, do:

diff --git a/src/Entity/JavaScriptComponent.php b/src/Entity/JavaScriptComponent.php
index 86e66995..062e5f63 100644
--- a/src/Entity/JavaScriptComponent.php
+++ b/src/Entity/JavaScriptComponent.php
@@ -99,10 +99,10 @@ final class JavaScriptComponent extends ConfigEntityBase implements XbHttpApiEli
         'props' => $this->props,
         'required' => $this->required,
         'slots' => $this->slots,
-        'source_code_js' => $this->js['original'] ?? '',
-        'source_code_css' => $this->css['original'] ?? '',
-        'compiled_js' => $this->js['compiled'] ?? '',
-        'compiled_css' => $this->css['compiled'] ?? '',
+        'sourceCodeJs' => $this->js['original'] ?? '',
+        'sourceCodeCss' => $this->css['original'] ?? '',
+        'compiledJs' => $this->js['compiled'] ?? '',
+        'compiledCss' => $this->css['compiled'] ?? '',
       ],
       preview: [
         '#markup' => '@todo Make something 🆒 in https://www.drupal.org/project/experience_builder/issues/3498889',
@@ -128,12 +128,12 @@ final class JavaScriptComponent extends ConfigEntityBase implements XbHttpApiEli
       'props' => $data['props'] ?? [],
       'slots' => $data['slots'] ?? [],
       'js' => [
-        'original' => $data['source_code_js'] ?? '',
-        'compiled' => $data['compiled_js'] ?? '',
+        'original' => $data['sourceCodeJs'] ?? '',
+        'compiled' => $data['compiledJs'] ?? '',
       ],
       'css' => [
-        'original' => $data['source_code_css'] ?? '',
-        'compiled' => $data['compiled_css'] ?? '',
+        'original' => $data['sourceCodeCss'] ?? '',
+        'compiled' => $data['compiledCss'] ?? '',
       ],
     ];
   }

(plus equivalent search+replace in \Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testJavaScriptComponent().)

Proposed resolution

Do the above, and make tests pass.

User interface changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

larowlan created an issue. See original summary.

wim leers’s picture

Assigned: Unassigned » longwave
Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

FYI: \Drupal\experience_builder\Entity\JavaScriptComponent::$machineName was specifically chosen to match SDC's core/assets/schemas/v1/metadata-full.schema.json#properties.machineName

As documented in config schema:

    # See core/assets/schemas/v1/metadata-full.schema.json#properties.machineName
    machineName:
      type: machine_name
      label: 'Machine Name'
      constraints:
        Regex:
          pattern: '/^[a-z]([a-zA-Z0-9_-]*[a-zA-Z0-9])*$/'
          message: 'The %value machine name is not valid.'
longwave’s picture

I get that we are following SDC, but we also use snake case for all other config entity properties. Not sure what is best here.

wim leers’s picture

Status: Postponed (maintainer needs more info) » Active

I don't feel strongly, I was just explaining the rationale!

If you got confused by it, and it sounds like #2 does not convince you.

So: you decide! 😄 What did you expect? What would've caused the least friction for you? Name it so! 👍

balintbrews’s picture

FWIW, I thought not using snake case for the property name was an oversight when I reviewed the code for #3499931: HTTP API for code component config entities, and saw all the other properties.

balintbrews’s picture

I realized I was looking for #3503272: JavaScriptComponent config entities should have mutable machineNames when I found this issue. Should we close this in favor of #3503272: JavaScriptComponent config entities should have mutable machineNames and handle the renaming there?

wim leers’s picture

Assigned: longwave » balintbrews
Status: Active » Postponed (maintainer needs more info)
Related issues: +#3503272: JavaScriptComponent config entities should have mutable machineNames

#6: yes, please.

Except … maybe we wanna repurpose this issue to tackle #5?

This is basically all you need for that:

diff --git a/src/Entity/JavaScriptComponent.php b/src/Entity/JavaScriptComponent.php
index 86e66995..062e5f63 100644
--- a/src/Entity/JavaScriptComponent.php
+++ b/src/Entity/JavaScriptComponent.php
@@ -99,10 +99,10 @@ final class JavaScriptComponent extends ConfigEntityBase implements XbHttpApiEli
         'props' => $this->props,
         'required' => $this->required,
         'slots' => $this->slots,
-        'source_code_js' => $this->js['original'] ?? '',
-        'source_code_css' => $this->css['original'] ?? '',
-        'compiled_js' => $this->js['compiled'] ?? '',
-        'compiled_css' => $this->css['compiled'] ?? '',
+        'sourceCodeJs' => $this->js['original'] ?? '',
+        'sourceCodeCss' => $this->css['original'] ?? '',
+        'compiledJs' => $this->js['compiled'] ?? '',
+        'compiledCss' => $this->css['compiled'] ?? '',
       ],
       preview: [
         '#markup' => '@todo Make something 🆒 in https://www.drupal.org/project/experience_builder/issues/3498889',
@@ -128,12 +128,12 @@ final class JavaScriptComponent extends ConfigEntityBase implements XbHttpApiEli
       'props' => $data['props'] ?? [],
       'slots' => $data['slots'] ?? [],
       'js' => [
-        'original' => $data['source_code_js'] ?? '',
-        'compiled' => $data['compiled_js'] ?? '',
+        'original' => $data['sourceCodeJs'] ?? '',
+        'compiled' => $data['compiledJs'] ?? '',
       ],
       'css' => [
-        'original' => $data['source_code_css'] ?? '',
-        'compiled' => $data['compiled_css'] ?? '',
+        'original' => $data['sourceCodeCss'] ?? '',
+        'compiled' => $data['compiledCss'] ?? '',
       ],
     ];
   }

(plus equivalent search+replace in \Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testJavaScriptComponent().)


The point is: it's easy for the server to generate the representation you prefer 😊

balintbrews’s picture

Assigned: balintbrews » Unassigned
Status: Postponed (maintainer needs more info) » Active

#7: Yes, please, let's 🐪Case! (Just like in #3501847: Send entity keys to the editor from the mount controller.)

wim leers’s picture

Title: Consider renaming javascript component ID to 'id' rather than machineName » Camelcase the client-side representation of code components
Component: Config management » Internal HTTP API
Parent issue: » #3521002: [META] Maintainable client-side data model + internal HTTP API

Re-scoping to #7 per @balintbrews in #8.

wim leers’s picture

Priority: Normal » Minor
Issue summary: View changes
Issue tags: +Novice

libbna made their first commit to this issue’s fork.

libbna’s picture

Hey, I have updated the code in the JavaScriptComponent.php file as per the discussion and created a merge request for the changes. Please review and let me know if anything further is required. Thanks.

wim leers’s picture

Status: Active » Needs work

Thanks! I'm afraid there's lots of out-of-scope code reformatting, even causing the phpcs CI job to fail 😇

Besides that, the other next step: update the UI :)

libbna’s picture

Hi @wim leers, could you please clarify what you mean by “update the UI”? Additionally, could you outline the next steps required for this issue so I can proceed accordingly? Thank you!

thoward216’s picture

Hi @libbna, I think I can help here.

I would first take a look at the pipeline for the MR and you'll see a number of PHPCS issues, which is due to the reformatting @wimleers mentioned.

In terms of the UI, it is currently still expecting `source_code_js` to be valid, if you search the code base for `source_code_js` you'll see it is referenced in a number of the UI React files, these will also need updating.

Hopefully that makes sense and you can proceed.

libbna’s picture

Assigned: Unassigned » libbna

Hi @thoward216 thank you so much for clarifications.

Assigning the issue to myself to continue working on it as mentioned.

libbna’s picture

In progress with rest of the code updation.

libbna’s picture

Status: Needs work » Needs review

I have updated the code. Please review and let me know if anything is missed.

libbna’s picture

Assigned: libbna » Unassigned
omkar-pd’s picture

Status: Needs review » Needs work

eslint failed

libbna’s picture

Status: Needs work » Needs review
thoward216’s picture

Status: Needs review » Needs work

Moving back to needs work as theres a PHP unit test failing.

hooroomoo’s picture

Assigned: Unassigned » hooroomoo

Gonna push this to the finish line since its close, would like this changes in for CLI tool work

hooroomoo’s picture

Assigned: hooroomoo » Unassigned
Status: Needs work » Needs review
wim leers’s picture

Assigned: Unassigned » wim leers
Status: Needs review » Reviewed & tested by the community

Gonna push this to the finish line since its close, would like this changes in for CLI tool work

❤️ — thanks! 🙏

Conflicted (trivially) with #3526297. Resolved those conflicts.

wim leers’s picture

Looks like #3525583: CLI command to download code components already landed, 1 day after @hooroomoo pushed this forward.

Worryingly, the CLI tests are not failing … because they're not running! This means its tests are not running when underlying infra changes; only when CLI code itself changes. Fixing…

wim leers’s picture

Assigned: wim leers » hooroomoo
Issue tags: +Needs followup

Updated logic + test expectations for the following that landed since June 12, thanks to test coverage:

I think this is ready, but the CLI test coverage seems to lack integration/functional tests 😱 Which is why the CLI vitest CI job passed when it clearly cannot work 😅
We clearly shouldn't fix that here, but #3525571: [Meta] CLI tool for code components needs a child issue for creating such test coverage.

wim leers’s picture

Issue tags: -Needs followup

Removing Needs followup tag here because I posted this at #3525571-5: [Meta] CLI tool for code components, which is the more appropriate place. It's really no fallout of this issue.

wim leers’s picture

hooroomoo’s picture

there's 1 phpunit test failing that i'm stumped on

wim leers’s picture

Assigned: hooroomoo » wim leers

Thanks for updating all others, I’ll take care of that last straggler! 😄

Glad to see this MR’s work coming to fruition rather than waste 👍

wim leers’s picture

Odd … passes locally? 🤔

wim leers’s picture

Too fiddly to merge today. Enjoying the sun 😎

  • wim leers committed 2ada51aa on 0.x authored by libbna
    Issue #3502640 by hooroomoo, wim leers, balintbrews, larowlan,...
wim leers’s picture

Assigned: wim leers » Unassigned
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.