-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '3916-upgrade-plugin-button-updated' into develop
- Loading branch information
Showing
8 changed files
with
171 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ey/monkey_island/cc/next_ui/src/app/(protected)/plugins/installed/PluginUpgradeButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { GridActionsCellItem } from '@mui/x-data-grid'; | ||
import FileDownloadIcon from '@mui/icons-material/FileDownload'; | ||
import React from 'react'; | ||
import { | ||
useGetLatestPluginVersionQuery, | ||
useInstallPluginMutation | ||
} from '@/redux/features/api/agentPlugins/agentPluginEndpoints'; | ||
import MonkeyLoadingIcon from '@/_components/icons/MonkeyLoadingIcon'; | ||
import DownloadDoneIcon from '@mui/icons-material/DownloadDone'; | ||
import { PluginId, PluginInfo } from '@/redux/features/api/agentPlugins/types'; | ||
|
||
const PluginUpgradeButton = (props: PluginInfo) => { | ||
const { pluginType, pluginName, pluginVersion, pluginId } = props; | ||
|
||
const [ | ||
upgradePlugin, | ||
{ | ||
isLoading: isUpgrading, | ||
isSuccess: isUpgradeSuccessful, | ||
reset: resetUpgradePlugin | ||
} | ||
] = useInstallPluginMutation({ fixedCacheKey: pluginName + pluginType }); | ||
const { data: latestPluginVersion, isLoading: isLoadingLatestVersion } = | ||
useGetLatestPluginVersionQuery({ | ||
pluginType: pluginType, | ||
pluginName: pluginName | ||
}); | ||
|
||
const isUpgradable = React.useMemo(() => { | ||
if (!latestPluginVersion) { | ||
return false; | ||
} | ||
const upgradeAvailable = latestPluginVersion !== pluginVersion; | ||
upgradeAvailable && isUpgradeSuccessful && resetUpgradePlugin(); | ||
return upgradeAvailable; | ||
}, [latestPluginVersion, pluginVersion]); | ||
|
||
const onUpgradeClick = () => { | ||
upgradePlugin({ | ||
pluginVersion: String(latestPluginVersion), | ||
pluginName: pluginName, | ||
pluginType: pluginType, | ||
pluginId: pluginId | ||
}); | ||
}; | ||
|
||
if (isUpgrading) { | ||
return UpgradeInProgressButton(pluginId); | ||
} else if (isUpgradeSuccessful) { | ||
return UpgradeDoneButton(pluginId); | ||
} else if (isLoadingLatestVersion || !isUpgradable) { | ||
return; | ||
} else { | ||
return UpgradeButton(pluginId, onUpgradeClick); | ||
} | ||
}; | ||
|
||
const UpgradeButton = (pluginId: PluginId, onUpgradeClick: () => void) => { | ||
return ( | ||
<GridActionsCellItem | ||
key={pluginId} | ||
icon={<FileDownloadIcon />} | ||
label="Download" | ||
onClick={onUpgradeClick} | ||
/> | ||
); | ||
}; | ||
|
||
const UpgradeInProgressButton = (pluginId: PluginId) => { | ||
return ( | ||
<GridActionsCellItem | ||
key={pluginId} | ||
icon={<MonkeyLoadingIcon />} | ||
label="Upgrading" | ||
/> | ||
); | ||
}; | ||
|
||
const UpgradeDoneButton = (pluginId: PluginId) => { | ||
return ( | ||
<GridActionsCellItem | ||
key={pluginId} | ||
icon={<DownloadDoneIcon />} | ||
label="Upgrade Complete" | ||
/> | ||
); | ||
}; | ||
|
||
export default PluginUpgradeButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters