-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pci-block-storage): add deploy zone
ref: TAPC-2112 Signed-off-by: Simon Chaumet <[email protected]>
- Loading branch information
1 parent
a022a6f
commit 348b94f
Showing
31 changed files
with
719 additions
and
503 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
36 changes: 0 additions & 36 deletions
36
packages/manager/apps/pci-block-storage/src/api/data/availableVolumes.ts
This file was deleted.
Oops, something went wrong.
100 changes: 73 additions & 27 deletions
100
packages/manager/apps/pci-block-storage/src/api/data/catalog.ts
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 |
---|---|---|
@@ -1,28 +1,74 @@ | ||
export type TPricing = { | ||
capacities: string[]; | ||
mode: string; | ||
phase: number; | ||
commitment: number; | ||
description: string; | ||
price: { | ||
currencyCode: string; | ||
text: string; | ||
value: number; | ||
}; | ||
tax: number; | ||
interval: number; | ||
intervalUnit: string; | ||
quantity: { | ||
max?: number; | ||
min?: number; | ||
}; | ||
repeat: { | ||
max?: number; | ||
min?: number; | ||
}; | ||
strategy: string; | ||
mustBeCompleted: boolean; | ||
type: string; | ||
promotions: unknown[]; | ||
engagementConfiguration?: unknown; | ||
import { TAddon } from '@ovh-ux/manager-pci-common'; | ||
import { v6 } from '@ovh-ux/manager-core-api'; | ||
import { TRegion } from '@/api/data/regions'; | ||
|
||
export type TCatalogGroup = { | ||
name: string; | ||
tags: string[]; | ||
}; | ||
|
||
export type TVolumePricing = Pick<TAddon['pricings'][number], 'price'> & { | ||
regions: TRegion['name'][]; | ||
showAvailabilityZones: boolean; | ||
interval: 'day' | 'hour' | 'month' | 'none'; | ||
specs: TAddon['blobs']['technical']; | ||
}; | ||
|
||
export type TVolumeCatalogFilter = { | ||
[key in 'deployment' | 'region']: TCatalogGroup[]; | ||
}; | ||
|
||
export type TVolumeCatalogElementFilter = { | ||
[Property in keyof TVolumeCatalogFilter]?: TVolumeCatalogFilter[Property][number]['name'][]; | ||
}; | ||
|
||
export type TVolumeAddon = { | ||
name: string; | ||
tags: string[]; | ||
filters: TVolumeCatalogElementFilter; | ||
pricings: TVolumePricing[]; | ||
}; | ||
|
||
export type TVolumeCatalog = { | ||
filters: TVolumeCatalogFilter; | ||
regions: TRegion[]; | ||
models: TVolumeAddon[]; | ||
}; | ||
|
||
export const getVolumeCatalog = async ( | ||
projectId: string, | ||
): Promise<TVolumeCatalog> => | ||
(await v6.get<TVolumeCatalog>(`/cloud/project/${projectId}/catalog/volume`)) | ||
.data; | ||
|
||
export function getLeastPrice(pricings: TVolumePricing[]) { | ||
return pricings.reduce<number | null>( | ||
(leastPrice, p) => | ||
leastPrice === null ? p.price : Math.min(p.price, leastPrice), | ||
null, | ||
); | ||
} | ||
|
||
export function getGroupLeastPrice( | ||
group: TCatalogGroup, | ||
regions: TRegion[], | ||
models: TVolumeAddon[], | ||
): number | null { | ||
const groupRegions = regions | ||
.filter((r) => r.type === group.name) | ||
.map((r) => r.name); | ||
|
||
const hasGroupRegions = (p: TVolumePricing) => | ||
p.regions.some(groupRegions.includes); | ||
|
||
return models | ||
.map((m) => getLeastPrice(m.pricings.filter(hasGroupRegions))) | ||
.filter((p) => p !== null) | ||
.reduce<number | null>( | ||
(leastPrice, modelLeastPrice) => | ||
leastPrice === null | ||
? modelLeastPrice | ||
: Math.min(modelLeastPrice, leastPrice), | ||
null, | ||
); | ||
} |
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
29 changes: 11 additions & 18 deletions
29
packages/manager/apps/pci-block-storage/src/api/data/regions.ts
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 |
---|---|---|
@@ -1,23 +1,16 @@ | ||
import { fetchIcebergV6 } from '@ovh-ux/manager-core-api'; | ||
import { TVolumeCatalogElementFilter } from '@/api/data/catalog'; | ||
|
||
export type TRegion = { | ||
name: string; | ||
type: string; | ||
status: string; | ||
continentCode: string; | ||
services: { | ||
name: string; | ||
status: string; | ||
endpoint: string; | ||
}[]; | ||
datacenterLocation: string; | ||
type: 'region-3-az' | 'region' | 'localzone'; | ||
availabilityZones: string[]; | ||
isInMaintenance: boolean; | ||
isActivated: boolean; | ||
country: string; | ||
filters: TVolumeCatalogElementFilter; | ||
datacenter: string; | ||
}; | ||
|
||
export const getProjectRegions = async ( | ||
projectId: string, | ||
): Promise<TRegion[]> => { | ||
const { data } = await fetchIcebergV6<TRegion>({ | ||
route: `/cloud/project/${projectId}/region`, | ||
}); | ||
return data; | ||
}; | ||
export function isRegionWith3AZ(region: Pick<TRegion, 'type'>) { | ||
return region.type === 'region-3-az'; | ||
} |
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
10 changes: 10 additions & 0 deletions
10
packages/manager/apps/pci-block-storage/src/api/hooks/useCatalog.ts
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 |
---|---|---|
@@ -1,16 +1,26 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useMe } from '@ovh-ux/manager-react-components'; | ||
import { getCatalog } from '@ovh-ux/manager-pci-common'; | ||
import { getVolumeCatalog } from '@/api/data/catalog'; | ||
|
||
export const getCatalogQuery = (ovhSubsidiary: string) => ({ | ||
queryKey: ['catalog'], | ||
queryFn: () => getCatalog(ovhSubsidiary), | ||
}); | ||
|
||
/** | ||
* @deprecated use {@link useVolumeCatalog} instead | ||
*/ | ||
export const useCatalog = () => { | ||
const { me } = useMe(); | ||
return useQuery({ | ||
...getCatalogQuery(me?.ovhSubsidiary), | ||
enabled: !!me, | ||
}); | ||
}; | ||
|
||
export const useVolumeCatalog = (projectId: string) => | ||
useQuery({ | ||
queryKey: ['projects', projectId, 'catalog', 'volume'], | ||
queryFn: () => getVolumeCatalog(projectId), | ||
}); |
47 changes: 0 additions & 47 deletions
47
packages/manager/apps/pci-block-storage/src/api/hooks/useConsumptionVolumesAddon.ts
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
packages/manager/apps/pci-block-storage/src/api/hooks/useHas3AZRegion.ts
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,13 @@ | ||
import { useVolumeCatalog } from '@/api/hooks/useCatalog'; | ||
|
||
export const useHas3AZRegion = (projectId: string) => { | ||
const { data: volumeCatalog, isPending } = useVolumeCatalog(projectId); | ||
|
||
return { | ||
has3AZ: | ||
volumeCatalog?.models.some((m) => | ||
m.filters.deployment.includes('region-3-az'), | ||
) || false, | ||
isPending, | ||
}; | ||
}; |
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
19 changes: 0 additions & 19 deletions
19
packages/manager/apps/pci-block-storage/src/api/hooks/useProjectsAvailableVolumes.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.