Plugins: Show update buttons when instance version is different (#85486)

This commit is contained in:
Hugo Kiyodi Oshiro 2024-04-09 10:32:34 +02:00 committed by GitHub
parent 0bdb96552a
commit b200156a01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -136,6 +136,35 @@ describe('Plugins/Helpers', () => {
config.featureToggles.managedPluginsInstall = oldFeatureTogglesManagedPluginsInstall;
config.pluginAdminExternalManageEnabled = oldPluginAdminExternalManageEnabled;
});
test('plugins should have update when instance version is different from remote version', () => {
const oldFeatureTogglesManagedPluginsInstall = config.featureToggles.managedPluginsInstall;
const oldPluginAdminExternalManageEnabled = config.pluginAdminExternalManageEnabled;
config.featureToggles.managedPluginsInstall = true;
config.pluginAdminExternalManageEnabled = true;
const pluginId = 'plugin-1';
const remotePlugin = getRemotePluginMock({ slug: pluginId, version: '1.0.0' });
const instancePlugin = {
pluginSlug: pluginId,
version: '0.0.9',
};
const merged = mergeLocalsAndRemotes({
local: [],
remote: [remotePlugin],
instance: [instancePlugin],
});
const findMerged = (mergedId: string) => merged.find(({ id }) => id === mergedId);
expect(merged).toHaveLength(1);
expect(findMerged(pluginId)).not.toBeUndefined();
expect(findMerged(pluginId)?.hasUpdate).toBe(true);
config.featureToggles.managedPluginsInstall = oldFeatureTogglesManagedPluginsInstall;
config.pluginAdminExternalManageEnabled = oldPluginAdminExternalManageEnabled;
});
});
describe('mergeLocalAndRemote()', () => {

View File

@ -76,6 +76,10 @@ export function mergeLocalsAndRemotes({
catalogPlugin.hasUpdate &&
catalogPlugin.installedVersion !== instancePlugin?.version;
if (instancePlugin?.version && instancePlugin?.version !== remotePlugin.version) {
catalogPlugin.hasUpdate = true;
}
catalogPlugin.isUninstallingFromInstance = Boolean(localCounterpart) && !instancesMap.has(remotePlugin.slug);
}