| 240 | } |
| 241 | |
| 242 | const handleAction = (card: PluginCard) => { |
| 243 | if ( |
| 244 | card.actionType === 'requires-package' || |
| 245 | card.actionType === 'wrong-framework' || |
| 246 | card.actionType === 'already-installed' || |
| 247 | card.actionType === 'version-mismatch' |
| 248 | ) { |
| 249 | // Can't install devtools without the base package, wrong framework, already installed, or version mismatch |
| 250 | return |
| 251 | } |
| 252 | |
| 253 | // change state to installing of the plugin user clicked |
| 254 | setPluginSections((prevSections) => |
| 255 | prevSections.map((section) => ({ |
| 256 | ...section, |
| 257 | cards: section.cards.map((c) => |
| 258 | c.devtoolsPackage === card.devtoolsPackage |
| 259 | ? { ...c, status: 'installing' } |
| 260 | : c, |
| 261 | ), |
| 262 | })), |
| 263 | ) |
| 264 | |
| 265 | // Bump the version of the required package and then add to devtools |
| 266 | if (card.actionType === 'bump-version') { |
| 267 | // emits the event to vite plugin to bump the package version, this will add it to devtools after |
| 268 | devtoolsEventClient.emit('bump-package-version', { |
| 269 | packageName: card.requiredPackageName, |
| 270 | devtoolsPackage: card.devtoolsPackage, |
| 271 | pluginName: card.metadata?.title || card.devtoolsPackage, |
| 272 | minVersion: card.metadata?.requires?.minVersion, |
| 273 | pluginImport: card.metadata?.pluginImport, |
| 274 | }) |
| 275 | return |
| 276 | } |
| 277 | |
| 278 | if (card.actionType === 'add-to-devtools') { |
| 279 | // emits the event to vite plugin to add the plugin |
| 280 | devtoolsEventClient.emit('add-plugin-to-devtools', { |
| 281 | packageName: card.devtoolsPackage, |
| 282 | // should always be defined |
| 283 | pluginName: card.metadata?.title ?? card.devtoolsPackage, |
| 284 | pluginImport: card.metadata?.pluginImport, |
| 285 | }) |
| 286 | return |
| 287 | } |
| 288 | devtoolsEventClient.emit('install-devtools', { |
| 289 | packageName: card.devtoolsPackage, |
| 290 | // should always be defined |
| 291 | pluginName: card.metadata?.title ?? card.devtoolsPackage, |
| 292 | pluginImport: card.metadata?.pluginImport, |
| 293 | }) |
| 294 | } |
| 295 | |
| 296 | // Get all available tags from plugins (excluding active plugins) |
| 297 | const getAllTags = () => { |