Skip to content

Commit

Permalink
build(pci-block-storage): add temporary pci-common lib
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Chaumet <[email protected]>
  • Loading branch information
SimonChaumet committed Jan 13, 2025
1 parent e50b1ec commit 7a0a15d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/manager/apps/pci-block-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@ovh-ux/manager-config": "^8.0.2",
"@ovh-ux/manager-core-api": "^0.9.0",
"@ovh-ux/manager-pci-common": "^0.14.2",
"@ovh-ux/manager-pci-common": "file:./ovh-ux-manager-pci-common-v0.14.5-3az.tgz",
"@ovh-ux/manager-react-components": "^1.43.0",
"@ovh-ux/manager-react-core-application": "^0.11.5",
"@ovh-ux/manager-react-shell-client": "^0.8.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type TAvailableVolumesResponse = {
regions: {
name: string;
enabled: boolean;
type: string;
}[];
}[];
};
Expand All @@ -22,7 +23,7 @@ export const getProjectsAvailableVolumes = async (
return data;
};

export function isRegionWith3AZ(region: TLocalisation) {
export function isRegionWith3AZ(region: Pick<TLocalisation, 'type'>) {
return region.type === 'region-3-az';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,33 @@ import {
useProject,
RegionSelector,
RegionSummary,
usePCICommonContextFactory,
PCICommonContext,
} from '@ovh-ux/manager-pci-common';
import { TLocalisation } from '@/api/hooks/useRegions';
import { StepState } from '@/pages/new/hooks/useStep';
import { useProjectsAvailableVolumes } from '@/api/hooks/useProjectsAvailableVolumes';
import { isRegionWith3AZ } from '@/api/data/availableVolumes';

interface LocationProps {
projectId: string;
step: StepState;
onSubmit: (region: TLocalisation) => void;
}

const useHas3AZRegion = (projectId: string) => {
const { data: availableVolumes, isPending } = useProjectsAvailableVolumes(
projectId,
);

return {
has3AZ:
availableVolumes?.plans.some((p) => p.regions.some(isRegionWith3AZ)) ||
false,
isPending,
};
};

export function LocationStep({
projectId,
step,
Expand All @@ -28,16 +45,21 @@ export function LocationStep({
const { data: project } = useProject();
const isDiscovery = isDiscoveryProject(project);
const hasRegion = !!region;

const { has3AZ } = useHas3AZRegion(projectId);
const pciCommonProperties = usePCICommonContextFactory({ has3AZ });

return (
<>
<PCICommonContext.Provider value={pciCommonProperties}>
{hasRegion && step.isLocked && <RegionSummary region={region} />}
{(!step.isLocked || isDiscovery) && (
<RegionSelector
projectId={projectId}
onSelectRegion={setRegion}
regionFilter={(r) =>
r.isMacro ||
r.services.some((s) => s.name === 'volume' && s.status === 'UP')
r.services.some((s) => s.name === 'volume' && s.status === 'UP') ||
r.type === 'region-3-az'
}
/>
)}
Expand All @@ -51,6 +73,6 @@ export function LocationStep({
{tStepper('common_stepper_next_button_label')}
</OsdsButton>
)}
</>
</PCICommonContext.Provider>
);
}

0 comments on commit 7a0a15d

Please sign in to comment.