dimanche 28 novembre 2021

Find-by with multiple attribute in Ember.js Octane

I have a route with RSVP that load several models (categories with items, treatments, prices) which return in JsON API Forrmat and want to show them in a table:

Item Name Treatment Name 1 Treatment Name N
Category 1
Item 1 in Cat 1 Price item 1 in Cat 1 for Treatment 1 Setup Price
Item 2 in Cat 1 Setup Price Price item 2 in Cat 1 for Treatment N
Category 2
Item 1 in Cat 2 Price item 1 in Cat 2 for Treatment 1 Price item 1 in Cat 2 for Treatment N

Setup Price only show if there isn't any price found, so the user can setup the price for the item in that treatment

I already can iterate the categories, items and treatment; but still do not know how to configure to show the correct price.

How can I find the correct prices by 2 attributes? I tried using find-by helper in the template:


  

, but it seems it only support 1 attributes.

Well, if in SQL it would be something like:

select * from prices where item.id = [currentItemId] and treatment.id = [currentTreatmentId]

but I want it to search in the already loaded price model...

Any help ? thank you...




jeudi 25 novembre 2021

Ember Upgrade from 3.23 to 3.24 failing at build

Was planning to migrate ember application from 3.23 to 3.24. During ember serve the following error is coming:

I have tried upgrading broccoli and babels libs to the latest version. Still the issue persists.

ERROR Summary:

  - broccoliBuilderErrorStack: TypeError: /home/abc/dev/sample-ui/ngcoreui/@ember/test-helpers/-internal/debug-info.js: path.isStaticBlock is not a function
    at PluginPass.ClassBody (/home/abc/dev/sample-ui/node_modules/@babel/plugin-proposal-class-static-block/lib/index.js:56:21)
    at newFn (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/visitors.js:177:21)
    at NodePath._call (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/path/context.js:100:31)
    at TraversalContext.visitQueue (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/context.js:103:16)
    at TraversalContext.visitSingle (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/context.js:77:19)
    at TraversalContext.visit (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/context.js:131:19)
    at Function.traverse.node (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/index.js:82:17)
    at NodePath.visit (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/path/context.js:108:18)
  - code: [undefined]
  - codeFrame: /home/abc/dev/sample-ui/ngcoreui/@ember/test-helpers/-internal/debug-info.js: path.isStaticBlock is not a function
  - errorMessage: @ember/test-helpers/-internal/debug-info.js: /home/abc/dev/sample-ui/ngcoreui/@ember/test-helpers/-internal/debug-info.js: path.isStaticBlock is not a function
        in /home/abc/dev/sample-ui/node_modules/@ember/test-helpers/addon-test-support
        at broccoli-persistent-filter:Babel > [Babel: @ember/test-helpers] (Babel: @ember/test-helpers)
  - errorType: Build Error
  - location:
    - column: [undefined]
    - file: @ember/test-helpers/-internal/debug-info.js
    - line: [undefined]
    - treeDir: /home/abc/dev/sample-ui/node_modules/@ember/test-helpers/addon-test-support
  - message: @ember/test-helpers/-internal/debug-info.js: /home/abc/dev/sample-ui/ngcoreui/@ember/test-helpers/-internal/debug-info.js: path.isStaticBlock is not a function
        in /home/abc/dev/sample-ui/node_modules/@ember/test-helpers/addon-test-support
        at broccoli-persistent-filter:Babel > [Babel: @ember/test-helpers] (Babel: @ember/test-helpers)
  - name: Error
  - nodeAnnotation: Babel: @ember/test-helpers
  - nodeName: broccoli-persistent-filter:Babel > [Babel: @ember/test-helpers]
  - originalErrorMessage: /home/abc/dev/sample-ui/ngcoreui/@ember/test-helpers/-internal/debug-info.js: path.isStaticBlock is not a function
  - stack: TypeError: /home/abc/dev/sample-ui/ngcoreui/@ember/test-helpers/-internal/debug-info.js: path.isStaticBlock is not a function
    at PluginPass.ClassBody (/home/abc/dev/sample-ui/node_modules/@babel/plugin-proposal-class-static-block/lib/index.js:56:21)
    at newFn (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/visitors.js:177:21)
    at NodePath._call (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/path/context.js:100:31)
    at TraversalContext.visitQueue (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/context.js:103:16)
    at TraversalContext.visitSingle (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/context.js:77:19)
    at TraversalContext.visit (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/context.js:131:19)
    at Function.traverse.node (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/index.js:82:17)
    at NodePath.visit (/home/abc/dev/sample-ui/node_modules/@babel/traverse/lib/path/context.js:108:18)



How to add swipe event in ember JS 3.27

I want some actions to be done when the screen is swiped down and I'm using ember version 3.27. Is this possible?




mardi 23 novembre 2021

How to do polling in Ember js component?

In ember js 3.24 LTS, I can create a component that receive data from an API call inside a route. The data from the API is an activity logs. The complexity arrives when I try to keep updating the logs with the latest logs, I need to keep polling the API every few seconds and I need to keep updating the data that being displayed inside the component.

  • How do I keep reloading the API call every few seconds and then update the display of the component?
  • I can use the ember later to keep looping/requery the API ever 2 seconds or 2000 ms, but then how do I tell my component to update the display?

This component gets data from an API call which is in the routes.

// addon/routes/single-scan/index.js 
import { later } from '@ember/runloop';
...
  async model() {
    let phaseActivityLog = await this.pollTestActivity(testId);
    return { phaseActivityLog };
  }

  async pollTestActivity(testId) {
    later(
      this,
      function () {
        this.pollTestActivity(testId);
      },
      2000
    );
    let phaseActivityLog = await this.store.query('phase-activity-log', testId, { reload: true }); // poll this
    return phaseActivityLog;
  }

And my component hbs

// components/single-scan/phase-activity-log.hbs


   -  - 




lundi 22 novembre 2021

Open one component instance at a time in Ember Octane

Let's say we have component answer that has isOpen property. By default isOpen is false and when the user is clicking on the answer we are changing the isOpen to true.

We are showing the list of answers. How can we close the first answer when the user clicks on second answer?

I was thinking about creating a service answersSync with globalIsOpen = false.




samedi 20 novembre 2021

DEPRECATION: Versions of modifier manager capabilities prior to 3.22 have been deprecated. You must update to the 3.22 capabilities

I got this warning on my Ember App :

DEPRECATION: Versions of modifier manager capabilities prior to 3.22 have been deprecated. You must update to the 3.22 capabilities. [deprecation id: manager-capabilities.modifiers-3-13] See https://deprecations.emberjs.com/v3.x#toc_manager-capabilities-modifiers-3-13 for more details. at logDeprecationStackTrace (http://localhost:4200/assets/vendor.js:36552:21) at HANDLERS. (http://localhost:4200/assets/vendor.js:36685:9) at raiseOnDeprecation (http://localhost:4200/assets/vendor.js:36579:9) at HANDLERS. (http://localhost:4200/assets/vendor.js:36685:9) at invoke (http://localhost:4200/assets/vendor.js:36697:9) at deprecate (http://localhost:4200/assets/vendor.js:36653:28) at modifierCapabilities$1 (http://localhost:4200/assets/vendor.js:11678:62) at http://localhost:4200/assets/vendor.js:99939:46 at CustomModifierManager.getDelegateFor (http://localhost:4200/assets/vendor.js:44817:20)

I visited the link https://deprecations.emberjs.com/ recommended for updating, I didn't really understand how to make this update, any help please .




mercredi 17 novembre 2021

Dynamically determine existence of template only Ember glimmer component?

I know that to dynamically determine the existence of a component on Ember we can use the solutions explained here or here.

We have a helper that uses .hasRegistration('component:${component}')

This also works for Glimmer components as long as there is a .js file defined, but it doesn't work for template-only Glimmer components. The component doesn't seem to be registered in that case.

Does anyone know a solution that would work for template-only glimmer components too?