Skip to content

Commit 51872be

Browse files
committed
feat: add function to map reserved platform names for validation
1 parent ba8828d commit 51872be

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Pages/GlobalConfigurations/BuildInfra/UseBuildInfraForm.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,18 @@ const useBuildInfraForm = ({
313313
}
314314
}, [profileResponse, isLoading])
315315

316+
const getReservedPlatformNameMap = (currentInputConfigurations: Record<string, unknown>): Record<string, true> => {
317+
const currentConfigPlatforms = Object.keys(currentInputConfigurations || {})
318+
const originalConfigPlatforms = Object.keys(profileResponse?.profile?.configurations || {})
319+
320+
return currentConfigPlatforms
321+
.concat(originalConfigPlatforms)
322+
.reduce<Record<string, true>>((acc, platformName) => {
323+
acc[platformName] = true
324+
return acc
325+
}, {})
326+
}
327+
316328
// NOTE: Currently sending and receiving values as string, but will parse it to number for payload
317329
const handleProfileInputChange = ({ action, data }: HandleProfileInputChangeType) => {
318330
const currentInput = structuredClone(profileInput)
@@ -437,7 +449,10 @@ const useBuildInfraForm = ({
437449
// If no target platform is given error will be '' so that we won;t show error but capture it
438450
currentInputErrors[BuildInfraProfileAdditionalErrorKeysType.TARGET_PLATFORM] = !targetPlatform
439451
? ''
440-
: validateTargetPlatformName(targetPlatform, currentInput.configurations).message
452+
: validateTargetPlatformName(
453+
targetPlatform,
454+
getReservedPlatformNameMap(currentInput.configurations),
455+
).message
441456

442457
currentInput.configurations[targetPlatform] =
443458
profileResponse.fallbackPlatformConfigurationMap[targetPlatform] ||
@@ -493,7 +508,10 @@ const useBuildInfraForm = ({
493508
}
494509

495510
currentInputErrors[BuildInfraProfileAdditionalErrorKeysType.TARGET_PLATFORM] =
496-
validateTargetPlatformName(newPlatformName, currentInput.configurations).message
511+
validateTargetPlatformName(
512+
newPlatformName,
513+
getReservedPlatformNameMap(currentInput.configurations),
514+
).message
497515

498516
const newPlatformFallbackConfig =
499517
profileResponse.fallbackPlatformConfigurationMap[newPlatformName] ||

0 commit comments

Comments
 (0)