Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Plugins: Fix plugin id mismatch #834

Closed
wants to merge 3 commits into from

Conversation

oshirohugo
Copy link
Contributor

@oshirohugo oshirohugo commented Mar 21, 2024

What this PR does / why we need it:

There was some mismatching in the pluginId created in the templates, this PR fix it.

Which issue(s) this PR fixes:

Fixes #758

Special notes for your reviewer:

To test this, I create projects using the old version and the new version for all plugin types: app, datasource, panel and scenesapp (with all the options on). I compared the results, and they were the same for app, datasource and panel. For scenesapp the fixes made all the pluginIds to be the same and the export path new has the -app sufix instead of -scenesapp

📦 Published PR as canary version: Canary Versions

✨ Test out this PR locally via:

npm install @grafana/create-plugin@4.2.6-canary.834.966fae0.0
# or 
yarn add @grafana/create-plugin@4.2.6-canary.834.966fae0.0

@oshirohugo oshirohugo requested a review from a team as a code owner March 21, 2024 15:33
@oshirohugo oshirohugo requested review from jackw and removed request for a team March 21, 2024 15:33
Copy link

github-actions bot commented Mar 21, 2024

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged and will trigger a new patch release.
NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

@oshirohugo oshirohugo added release Create a release when this pr is merged patch Increment the patch version when merged create-plugin related to the create-plugin tool labels Mar 21, 2024
@oshirohugo oshirohugo self-assigned this Mar 22, 2024
Copy link
Collaborator

@leventebalogh leventebalogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup, mostly looks good to me 👏

One thing though: unfortunately we also need to update the getTemplateData() function in utils.templates.ts to make sure that the update and generate flows are the same.

(@Ukochka's PR for refactoring the template-data generation should make these updates and fixes simpler in the future.)

@@ -25,7 +25,9 @@ export const normalizeId = (pluginName: string, orgName: string, type: PLUGIN_TY

const newPluginName = pluginName.replace(re, '').replace(nameRegex, '');
const newOrgName = orgName.replace(nameRegex, '');
return newOrgName.toLowerCase() + '-' + newPluginName.toLowerCase() + `-${type}`;
const newType = type === PLUGIN_TYPES.scenes ? PLUGIN_TYPES.app : type;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! (Maybe it would be nice in the future to define an explicit mapping between these two different "types", e.g. in the constants.)

@oshirohugo oshirohugo changed the title Create Plugins: Fix plugin add mismatch Create Plugins: Fix plugin id mismatch Mar 25, 2024
@@ -2,7 +2,7 @@
"$schema": "https://raw.githubusercontent.com/grafana/grafana/main/docs/sources/developers/plugins/plugin.schema.json",
"type": "app",
"name": "{{ titleCase pluginName }}",
"id": "{{ normalize_id pluginName orgName 'app' }}",
"id": "{{ pluginId }}",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If pluginId is now the source of truth for all templates probably best if we remove the handlebars normalize_id helper registration in utils.handlesbars.ts to prevent someone introducing its usage again in a template in the future.

@oshirohugo
Copy link
Contributor Author

oshirohugo commented Apr 2, 2024

@leventebalogh regarding your suggestion:

One thing though: unfortunately we also need to update the getTemplateData() function in utils.templates.ts to make sure that the update and generate flows are the same.

Do you mean doing something like:

    pluginId: normalizeId(pluginJson.name, pluginJson.org, pluginJson.type),

?

If that's the case, couldn't it be an issue, since the plugin id will change? E.g. all the old scenesapp type plugins that have id with suffix -scenesapp will have its id changed to an id with suffix -app. If it's an update maybe the plugin is already in our catalog and the id is already in our database, so the update will introduce a breaking change.

Copy link
Collaborator

@leventebalogh leventebalogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was wrong @oshirohugo. You are right, during updates the pluginId should come from the plugin.json. Changes look good to me 👍

@oshirohugo
Copy link
Contributor Author

Closing PR in favor of #837

@Ukochka merge this branch into hers.

@oshirohugo oshirohugo closed this Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-plugin related to the create-plugin tool patch Increment the patch version when merged release Create a release when this pr is merged
Projects
Development

Successfully merging this pull request may close these issues.

Bug: scenesapp backend created with different plugin-id
3 participants