Skip to content

Commit

Permalink
Upgrades an app to the latest version available in the app catalog. C…
Browse files Browse the repository at this point in the history
…loses: #351 (#357)

## 🎯 Aim

Upgrades an app to the latest version available in the app catalog for the specified site

## 📷 Result

![image](https://github.com/user-attachments/assets/3c9255b0-28de-4365-9bce-d12452c611be)


## ✅ What was done

- [X] New action to upgrade an app in the specified site.
- [X] Prompt for the site URL only when upgrading tenant app catalog
apps. For site collection app catalog apps, it uses the site collection
app catalog URL and scope.

## 🔗 Related issue

Closes: #351
  • Loading branch information
Saurabh7019 authored Nov 23, 2024
1 parent 2d9f263 commit 2ed802e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ After successful sign in, an additional view is presented that shows a list of l
- **Remove**: Removes the app from the app catalog.
- **Enable**: Allows end users to add the solution to their SharePoint sites.
- **Disable**: Hides the solution from end users, preventing them from adding it to sites.
- **Upgrade**: Upgrades the solution to the latest version available in the app catalog for the specified site.

Additionally, it will show you all tenant-wide extensions installed on your tenant.

Expand Down
1 change: 1 addition & 0 deletions assets/walkthrough/tenant-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ After successful sign in, an additional view is presented that shows a list of l
- **Remove**: Removes the app from the app catalog.
- **Enable**: Allows end users to add the solution to their SharePoint sites.
- **Disable**: Hides the solution from end users, preventing them from adding it to sites.
- **Upgrade**: Upgrades the solution to the latest version available in the app catalog for the specified site.

Additionally, it will show you all tenant-wide extensions installed on your tenant.

Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@
"category": "SharePoint Framework Toolkit",
"icon": "$(circle-slash)"
},
{
"command": "spfx-toolkit.upgradeAppCatalogApp",
"title": "Upgrade",
"category": "SharePoint Framework Toolkit",
"icon": "$(sync)"
},
{
"command": "spfx-toolkit.showMoreActions",
"title": "...",
Expand Down Expand Up @@ -531,6 +537,10 @@
{
"command": "spfx-toolkit.disableAppCatalogApp",
"group": "actions.more@4"
},
{
"command": "spfx-toolkit.upgradeAppCatalogApp",
"group": "actions.more@5"
}
],
"explorer/context": [
Expand Down
1 change: 1 addition & 0 deletions src/constants/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ export const Commands = {
removeAppCatalogApp: `${EXTENSION_NAME}.removeAppCatalogApp`,
enableAppCatalogApp: `${EXTENSION_NAME}.enableAppCatalogApp`,
disableAppCatalogApp: `${EXTENSION_NAME}.disableAppCatalogApp`,
upgradeAppCatalogApp: `${EXTENSION_NAME}.upgradeAppCatalogApp`,
showMoreActions: `${EXTENSION_NAME}.showMoreActions`
};
3 changes: 2 additions & 1 deletion src/constants/ContextKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const ContextKeys = {
retractApp: 'pnp.etv.app.retract',
removeApp: 'pnp.etv.app.remove',
enableApp: 'pnp.etv.app.enable',
disableApp: 'pnp.etv.app.disable'
disableApp: 'pnp.etv.app.disable',
upgradeApp: 'pnp.etv.app.upgrade'
};
6 changes: 4 additions & 2 deletions src/panels/CommandPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ export class CommandPanel {
new ActionTreeItem('Retract', '', undefined, undefined, Commands.retractAppCatalogApp, [app.ID, app.Title, undefined, app.Deployed], ContextKeys.retractApp),
new ActionTreeItem('Remove', '', undefined, undefined, Commands.removeAppCatalogApp, [app.ID, app.Title], ContextKeys.removeApp),
new ActionTreeItem('Enable', '', undefined, undefined, Commands.enableAppCatalogApp, [app.Title, tenantAppCatalogUrl, app.Enabled], ContextKeys.enableApp),
new ActionTreeItem('Disable', '', undefined, undefined, Commands.disableAppCatalogApp, [app.Title, tenantAppCatalogUrl, app.Enabled], ContextKeys.disableApp)
new ActionTreeItem('Disable', '', undefined, undefined, Commands.disableAppCatalogApp, [app.Title, tenantAppCatalogUrl, app.Enabled], ContextKeys.disableApp),
new ActionTreeItem('Upgrade', '', undefined, undefined, Commands.upgradeAppCatalogApp, [app.ID, app.Title], ContextKeys.upgradeApp)
]
)
);
Expand Down Expand Up @@ -250,7 +251,8 @@ export class CommandPanel {
new ActionTreeItem('Retract', '', undefined, undefined, Commands.retractAppCatalogApp, [app.ID, app.Title, siteAppCatalogUrl, app.Deployed], ContextKeys.retractApp),
new ActionTreeItem('Remove', '', undefined, undefined, Commands.removeAppCatalogApp, [app.ID, app.Title, siteAppCatalogUrl], ContextKeys.removeApp),
new ActionTreeItem('Enable', '', undefined, undefined, Commands.enableAppCatalogApp, [app.Title, siteAppCatalogUrl, app.Enabled], ContextKeys.enableApp),
new ActionTreeItem('Disable', '', undefined, undefined, Commands.disableAppCatalogApp, [app.Title, siteAppCatalogUrl, app.Enabled], ContextKeys.disableApp)
new ActionTreeItem('Disable', '', undefined, undefined, Commands.disableAppCatalogApp, [app.Title, siteAppCatalogUrl, app.Enabled], ContextKeys.disableApp),
new ActionTreeItem('Upgrade', '', undefined, undefined, Commands.upgradeAppCatalogApp, [app.ID, app.Title, siteAppCatalogUrl], ContextKeys.upgradeApp)
]
)
);
Expand Down
50 changes: 50 additions & 0 deletions src/services/actions/CliActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export class CliActions {
CliActions.toggleAppEnabled(node, ContextKeys.disableApp, 'disable')
)
);
subscriptions.push(
commands.registerCommand(Commands.upgradeAppCatalogApp, CliActions.upgradeAppCatalogApp)
);
}

/**
Expand Down Expand Up @@ -224,6 +227,53 @@ export class CliActions {
}
}

/**
* Upgrades an app to a newer version available in the app catalog.
*
* @param node The tree item representing the app to be upgraded.
*/
public static async upgradeAppCatalogApp(node: ActionTreeItem) {
try {
const actionNode = node.children?.find(child => child.contextValue === ContextKeys.upgradeApp);

if (!actionNode?.command?.arguments) {
Notifications.error('Failed to retrieve app details for upgrade.');
return;
}

const [appID, appTitle, appCatalogUrl] = actionNode.command.arguments;

const siteUrl = appCatalogUrl?.trim() || await window.showInputBox({
prompt: 'Enter the URL of the site to upgrade the app in',
placeHolder: 'https://contoso.sharepoint.com/sites/sales',
validateInput: (input) => (input.trim() ? undefined : 'Site URL cannot be empty')
});

if (!siteUrl) {
Notifications.warning('No site URL provided. App upgrade aborted.');
return;
}

const commandOptions: any = {
id: appID,
...(appCatalogUrl?.trim()
? { appCatalogScope: 'sitecollection', siteUrl, }
: { siteUrl })
};

await CliExecuter.execute('spo app upgrade', 'json', commandOptions);

Notifications.info(`App '${appTitle}' has been successfully upgraded.`);

// refresh the environmentTreeView
await commands.executeCommand('spfx-toolkit.refreshAppCatalogTreeView');

} catch (e: any) {
const message = e?.message || 'An unexpected error occurred during the app upgrade.';
Notifications.error(message);
}
}

/**
* Enables or disables the app in the tenant or site app catalog.
*
Expand Down

0 comments on commit 2ed802e

Please sign in to comment.