mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 15:27:46 +00:00
Rename things and fix bug in error checking
This commit is contained in:
@@ -101,14 +101,14 @@ export const reorderWorkspaceEnvironments = async (
|
|||||||
// atomic update the env to avoid conflict
|
// atomic update the env to avoid conflict
|
||||||
const workspace = await Workspace.findById(workspaceId).exec();
|
const workspace = await Workspace.findById(workspaceId).exec();
|
||||||
if (!workspace) {
|
if (!workspace) {
|
||||||
throw new Error("Failed to create workspace environment");
|
throw BadRequestError({message: "Couldn't load workspace"});
|
||||||
}
|
}
|
||||||
|
|
||||||
const environmentIndex = workspace.environments.findIndex((env) => env.name === environmentName && env.slug === environmentSlug)
|
const environmentIndex = workspace.environments.findIndex((env) => env.name === environmentName && env.slug === environmentSlug)
|
||||||
const otherEnvironmentIndex = workspace.environments.findIndex((env) => env.name === otherEnvironmentName && env.slug === otherEnvironmentSlug)
|
const otherEnvironmentIndex = workspace.environments.findIndex((env) => env.name === otherEnvironmentName && env.slug === otherEnvironmentSlug)
|
||||||
|
|
||||||
if (environmentIndex === undefined || otherEnvironmentIndex === undefined) {
|
if (environmentIndex === -1 || otherEnvironmentIndex === -1) {
|
||||||
throw new Error("environment or otherEnvironment couldn't be found")
|
throw BadRequestError({message: "environment or otherEnvironment couldn't be found"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// swap the order of the environments
|
// swap the order of the environments
|
||||||
|
|||||||
+5
-5
@@ -38,18 +38,18 @@ export const EnvironmentTable = ({ handlePopUpOpen }: Props) => {
|
|||||||
const { createNotification } = useNotificationContext();
|
const { createNotification } = useNotificationContext();
|
||||||
const reorderWsEnvironment = useReorderWsEnvironment();
|
const reorderWsEnvironment = useReorderWsEnvironment();
|
||||||
|
|
||||||
const reorderEnvs = async (moveUp: boolean, name: string, slug: string) => {
|
const handleReorderEnv= async (shouldMoveUp: boolean, name: string, slug: string) => {
|
||||||
try {
|
try {
|
||||||
if (!currentWorkspace?._id) return;
|
if (!currentWorkspace?._id) return;
|
||||||
|
|
||||||
const indexOfEnv = currentWorkspace.environments.findIndex((env) => env.name === name && env.slug === slug);
|
const indexOfEnv = currentWorkspace.environments.findIndex((env) => env.name === name && env.slug === slug);
|
||||||
|
|
||||||
// check that this reordering is possible
|
// check that this reordering is possible
|
||||||
if (indexOfEnv === 0 && moveUp || indexOfEnv === currentWorkspace.environments.length - 1 && !moveUp) {
|
if (indexOfEnv === 0 && shouldMoveUp || indexOfEnv === currentWorkspace.environments.length - 1 && !shouldMoveUp) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexToSwap = moveUp ? indexOfEnv - 1 : indexOfEnv + 1
|
const indexToSwap = shouldMoveUp ? indexOfEnv - 1 : indexOfEnv + 1
|
||||||
|
|
||||||
await reorderWsEnvironment.mutateAsync({
|
await reorderWsEnvironment.mutateAsync({
|
||||||
workspaceID: currentWorkspace._id,
|
workspaceID: currentWorkspace._id,
|
||||||
@@ -94,7 +94,7 @@ export const EnvironmentTable = ({ handlePopUpOpen }: Props) => {
|
|||||||
<IconButton
|
<IconButton
|
||||||
className="mr-3 py-2"
|
className="mr-3 py-2"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
reorderEnvs(false, name, slug)
|
handleReorderEnv(false, name, slug)
|
||||||
}}
|
}}
|
||||||
colorSchema="primary"
|
colorSchema="primary"
|
||||||
variant="plain"
|
variant="plain"
|
||||||
@@ -106,7 +106,7 @@ export const EnvironmentTable = ({ handlePopUpOpen }: Props) => {
|
|||||||
<IconButton
|
<IconButton
|
||||||
className="mr-3 py-2"
|
className="mr-3 py-2"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
reorderEnvs(true, name, slug)
|
handleReorderEnv(true, name, slug)
|
||||||
}}
|
}}
|
||||||
colorSchema="primary"
|
colorSchema="primary"
|
||||||
variant="plain"
|
variant="plain"
|
||||||
|
|||||||
Reference in New Issue
Block a user