K-Phoen / backstage-plugin-grafana

Grafana plugin for Backstage
Apache License 2.0
53 stars 28 forks source link

isDashboardSelectorAvailable should be a boolean #69

Open clemcvlcs opened 1 year ago

clemcvlcs commented 1 year ago

I'd like to hide theEntityGrafanaDashboardsCard if the annotation is not defined for the entity. This is commonly done in other plugin with someting similar to:

    <EntitySwitch>
      <EntitySwitch.Case if={isDashboardSelectorAvailable}>
        <Grid item sm={6}>
          <EntityGrafanaDashboardsCard />
        </Grid>
      </EntitySwitch.Case>
    </EntitySwitch>

But here, the snippet does not work since isDashboardSelectorAvailable is not a boolean for some reasons. I believe we should have someting like

// src/components/grafanaData.ts
export const isDashboardSelectorAvailable = (entity: Entity) => Boolean(entity?.metadata.annotations?.[GRAFANA_ANNOTATION_DASHBOARD_SELECTOR] || entity?.metadata.annotations?.[GRAFANA_ANNOTATION_TAG_SELECTOR]);

instead of

// src/components/grafanaData.ts
export const isDashboardSelectorAvailable = (entity: Entity) => entity?.metadata.annotations?.[GRAFANA_ANNOTATION_DASHBOARD_SELECTOR] || entity?.metadata.annotations?.[GRAFANA_ANNOTATION_TAG_SELECTOR];

What do you think ? Please let me know if you want me to open a PR.

Thanks in advance

Vity01 commented 1 year ago

@K-Phoen could you please fix that?

Shandur commented 1 year ago

Agree on having some Boolean function, maybe a new one like isDashboardSelectorApplicable to avoid breaking changes. I workaround the issue in the following way:

<EntitySwitch.Case if={e => !!isDashboardSelectorAvailable(e)}>