cube-js/cube

Set SQL value in Meta field of a Dimension

Open

#3143 aperta il 21 lug 2021

Vedi su GitHub
 (2 commenti) (2 reazioni) (0 assegnatari)Rust (1965 fork)batch import
help wanted

Metriche repository

Star
 (19.563 star)
Metriche merge PR
 (Merge medio 5g 16h) (138 PR mergiate in 30 g)

Descrizione

Is your feature request related to a problem? Please describe. I'd like to be able to display a link on the frontend of my application with the text being the name of the data I'm linking. For example I want to link to a resource like <a href={link}>{nameOfResource}</a>. This would be much easier if I could fetch both the name and the link at the same time as a singular dimension, rather than having to combine them on the front end.

Describe the solution you'd like I'd like something like this:

link: {
      sql: `CONCAT('http://www.example.com/',${CUBE.id},'/')`,
      type: `string`,
      format: `link`,
      meta: {
        name: {
             sql: `${CUBE.name}`
            }
      }
}

Or something similar. Basically here I want to fetch both the name and the link for the name at the same time. Describe alternatives you've considered Currently as a work around, I have to query for both CUBE.name and CUBE.link and then write some glue code on the front end to turn them into 1 dimension to render. This is okay, but definitely not ideal. Currently, with the existing link API you can only set static text for the dimension like in this example:

    crmLink: {
      sql: `'https://na1.salesforce.com/' || id`,
      type: `string`,
      format: {
        label: `View in Salesforce`,
        type: `link`,
      },
    },

But imagine you had tens or hundreds of links for various CRM entries, you wouldn't want to display View in Salesforce for ALL of them. You'd want an easier way to distinguish which one you're going to click.

Guida contributor