mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-03 18:26:04 +00:00
refactor: take into account other delimiters
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
/** Extracts the key and value from a passed in env string based on the provided delimiters. */
|
||||||
|
export const getKeyValue = (pastedContent: string, delimiters: string[]) => {
|
||||||
|
let splitIndex = -1
|
||||||
|
let key = ""
|
||||||
|
let value = ""
|
||||||
|
|
||||||
|
for (const delimiter of delimiters) {
|
||||||
|
const idx = pastedContent.indexOf(delimiter)
|
||||||
|
|
||||||
|
if (idx !== -1) {
|
||||||
|
splitIndex = idx
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if only key is pasted
|
||||||
|
if (splitIndex === -1) {
|
||||||
|
key = pastedContent.trim()
|
||||||
|
return { key, value: "" }
|
||||||
|
}
|
||||||
|
|
||||||
|
key = pastedContent.slice(0, splitIndex).trim()
|
||||||
|
value = pastedContent.slice(splitIndex + 1).trim()
|
||||||
|
|
||||||
|
return { key, value }
|
||||||
|
};
|
||||||
@@ -8,6 +8,7 @@ import { Button, FormControl, Input, Modal, ModalContent } from "@app/components
|
|||||||
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
||||||
import { useCreateSecretV3 } from "@app/hooks/api";
|
import { useCreateSecretV3 } from "@app/hooks/api";
|
||||||
import { SecretType } from "@app/hooks/api/types";
|
import { SecretType } from "@app/hooks/api/types";
|
||||||
|
import { getKeyValue } from '@app/helpers/parseEnvVar';
|
||||||
|
|
||||||
import { PopUpNames, usePopUpAction, usePopUpState } from "../../SecretMainPage.store";
|
import { PopUpNames, usePopUpAction, usePopUpState } from "../../SecretMainPage.store";
|
||||||
|
|
||||||
@@ -77,16 +78,12 @@ export const CreateSecretForm = ({
|
|||||||
|
|
||||||
const handlePaste = (e: ClipboardEvent<HTMLInputElement>) => {
|
const handlePaste = (e: ClipboardEvent<HTMLInputElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const pastedContent = e.clipboardData.getData('text');
|
const delimitters = [":", "="];
|
||||||
const splitIndex = pastedContent.indexOf("=");
|
const pastedContent = e.clipboardData.getData("text");
|
||||||
|
const { key, value } = getKeyValue(pastedContent, delimitters);
|
||||||
|
|
||||||
if (splitIndex === -1) return
|
setValue("key", key);
|
||||||
|
setValue("value", value);
|
||||||
const key = pastedContent.slice(0, splitIndex)
|
|
||||||
const value = pastedContent.slice(splitIndex + 1);
|
|
||||||
|
|
||||||
setValue('key', key);
|
|
||||||
setValue('value', value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+6
-9
@@ -20,6 +20,7 @@ import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
|||||||
import { useWorkspace } from "@app/context";
|
import { useWorkspace } from "@app/context";
|
||||||
import { useCreateFolder, useCreateSecretV3, useUpdateSecretV3 } from "@app/hooks/api";
|
import { useCreateFolder, useCreateSecretV3, useUpdateSecretV3 } from "@app/hooks/api";
|
||||||
import { SecretType,SecretV3RawSanitized } from "@app/hooks/api/types";
|
import { SecretType,SecretV3RawSanitized } from "@app/hooks/api/types";
|
||||||
|
import { getKeyValue } from '@app/helpers/parseEnvVar';
|
||||||
|
|
||||||
const typeSchema = z
|
const typeSchema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -138,16 +139,12 @@ export const CreateSecretForm = ({
|
|||||||
|
|
||||||
const handlePaste = (e: ClipboardEvent<HTMLInputElement>) => {
|
const handlePaste = (e: ClipboardEvent<HTMLInputElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const pastedContent = e.clipboardData.getData('text');
|
const delimitters = [":", "="];
|
||||||
const splitIndex = pastedContent.indexOf("=");
|
const pastedContent = e.clipboardData.getData("text");
|
||||||
|
const { key, value } = getKeyValue(pastedContent, delimitters);
|
||||||
|
|
||||||
if (splitIndex === -1) return
|
setValue("key", key);
|
||||||
|
setValue("value", value);
|
||||||
const key = pastedContent.slice(0, splitIndex)
|
|
||||||
const value = pastedContent.slice(splitIndex + 1);
|
|
||||||
|
|
||||||
setValue('key', key);
|
|
||||||
setValue('value', value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user