Merge pull request #1282 from Infisical/patch-railway

Fix client-side railway integration issue
This commit is contained in:
BlackMagiq
2024-01-06 16:14:16 +01:00
committed by GitHub
2 changed files with 27 additions and 12 deletions
@@ -297,6 +297,7 @@ const fetchIntegrationAuthRailwayEnvironments = async ({
integrationAuthId: string; integrationAuthId: string;
appId: string; appId: string;
}) => { }) => {
if (appId === "none") return [];
const { const {
data: { environments } data: { environments }
} = await apiRequest.get<{ environments: Environment[] }>( } = await apiRequest.get<{ environments: Environment[] }>(
@@ -318,6 +319,7 @@ const fetchIntegrationAuthRailwayServices = async ({
integrationAuthId: string; integrationAuthId: string;
appId: string; appId: string;
}) => { }) => {
if (appId === "none") return [];
const { const {
data: { services } data: { services }
} = await apiRequest.get<{ services: Service[] }>( } = await apiRequest.get<{ services: Service[] }>(
@@ -76,10 +76,15 @@ export default function RailwayCreateIntegrationPage() {
} }
}, [targetEnvironments]); }, [targetEnvironments]);
const filteredServices = targetServices?.concat({ useEffect(() => {
name: "", if (targetServices) {
serviceId: "" if (targetServices.length > 0) {
}); setTargetServiceId(targetServices[0].serviceId);
} else {
setTargetServiceId("none");
}
}
}, [targetServices]);
const handleButtonClick = async () => { const handleButtonClick = async () => {
try { try {
@@ -125,7 +130,7 @@ export default function RailwayCreateIntegrationPage() {
selectedSourceEnvironment && selectedSourceEnvironment &&
integrationAuthApps && integrationAuthApps &&
targetEnvironments && targetEnvironments &&
filteredServices ? ( targetServices ? (
<div className="flex h-full w-full items-center justify-center"> <div className="flex h-full w-full items-center justify-center">
<Card className="max-w-md rounded-md p-8"> <Card className="max-w-md rounded-md p-8">
<CardTitle className="text-center">Railway Integration</CardTitle> <CardTitle className="text-center">Railway Integration</CardTitle>
@@ -180,6 +185,7 @@ export default function RailwayCreateIntegrationPage() {
value={targetEnvironmentId} value={targetEnvironmentId}
onValueChange={(val) => setTargetEnvironmentId(val)} onValueChange={(val) => setTargetEnvironmentId(val)}
className="w-full border border-mineshaft-500" className="w-full border border-mineshaft-500"
isDisabled={targetEnvironments.length === 0}
> >
{targetEnvironments.length > 0 ? ( {targetEnvironments.length > 0 ? (
targetEnvironments.map((targetEnvironment) => ( targetEnvironments.map((targetEnvironment) => (
@@ -202,15 +208,22 @@ export default function RailwayCreateIntegrationPage() {
value={targetServiceId} value={targetServiceId}
onValueChange={(val) => setTargetServiceId(val)} onValueChange={(val) => setTargetServiceId(val)}
className="w-full border border-mineshaft-500" className="w-full border border-mineshaft-500"
isDisabled={targetServices.length === 0}
> >
{filteredServices.map((targetService) => ( {targetServices.length > 0 ? (
<SelectItem targetServices.map((targetService) => (
value={targetService.serviceId as string} <SelectItem
key={`target-service-${targetService.serviceId as string}`} value={targetService.serviceId as string}
> key={`target-service-${targetService.serviceId as string}`}
{targetService.name} >
{targetService.name}
</SelectItem>
))
) : (
<SelectItem value="none" key="target-service-none">
No services found
</SelectItem> </SelectItem>
))} )}
</Select> </Select>
</FormControl> </FormControl>
<Button <Button