-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Statically Cache Marketplace Apps (#9732)
* initial POC * use `placeholderData` insted of `initalData` * clean up and approve * revert regions so unit tests don't fail * fix flags import * add changeset --------- Co-authored-by: Banks Nussman <banks@nussman.us>
- Loading branch information
1 parent
ebec3e3
commit a617735
Showing
7 changed files
with
100 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Added | ||
--- | ||
|
||
Statically Cache Marketplace Apps ([#9732](https://github.com/linode/manager/pull/9732)) |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,54 @@ | ||
import { StackScript } from '@linode/api-v4'; | ||
import React from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
|
||
import { baseApps } from 'src/features/StackScripts/stackScriptUtils'; | ||
import { useFlags } from 'src/hooks/useFlags'; | ||
import { useStackScriptsOCA } from 'src/queries/stackscripts'; | ||
import { getQueryParamFromQueryString } from 'src/utilities/queryParams'; | ||
|
||
const trimOneClickFromLabel = (script: StackScript) => { | ||
return { | ||
...script, | ||
label: script.label.replace('One-Click', ''), | ||
}; | ||
}; | ||
|
||
export interface WithMarketplaceAppsProps { | ||
appInstances: StackScript[] | undefined; | ||
appInstancesError: string | undefined; | ||
appInstancesLoading: boolean; | ||
} | ||
|
||
export const withMarketplaceApps = <Props>( | ||
Component: React.ComponentType<Props & WithMarketplaceAppsProps> | ||
) => (props: Props) => { | ||
const location = useLocation(); | ||
const flags = useFlags(); | ||
|
||
const type = getQueryParamFromQueryString(location.search, 'type'); | ||
|
||
// Only enable the query when the user is on the Marketplace page | ||
const enabled = type === 'One-Click'; | ||
|
||
const { data, error, isLoading } = useStackScriptsOCA(enabled); | ||
|
||
const newApps = flags.oneClickApps || []; | ||
const allowedApps = Object.keys({ ...baseApps, ...newApps }); | ||
|
||
const filteredApps = (data ?? []).filter((script) => { | ||
return ( | ||
!script.label.match(/helpers/i) && allowedApps.includes(String(script.id)) | ||
); | ||
}); | ||
const trimmedApps = filteredApps.map((stackscript) => | ||
trimOneClickFromLabel(stackscript) | ||
); | ||
|
||
return React.createElement(Component, { | ||
...props, | ||
appInstances: trimmedApps, | ||
appInstancesError: error?.[0]?.reason, | ||
appInstancesLoading: isLoading, | ||
}); | ||
}; |
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