adjustment: finalized InfisicalSecretInput

This commit is contained in:
Sheen Capadngan
2024-04-23 22:49:00 +08:00
parent 9b7ef55ad7
commit b135ba263c
2 changed files with 19 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
/* eslint-disable react/no-danger */
import React, { forwardRef, TextareaHTMLAttributes, useRef, useState } from "react";
import React, { forwardRef, TextareaHTMLAttributes, useEffect, useRef, useState } from "react";
import { twMerge } from "tailwind-merge";
import {
@@ -97,15 +97,23 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(
const [referenceKey, setReferenceKey] = useState<string>();
const [lastCaretPos, setLastCaretPos] = useState<number>(0);
const isCaretInsideReference = (str: string, start: number) => {
const match = [...str.matchAll(REGEX_SECRET_REFERENCE_FIND)].find(
(entry) =>
typeof entry?.index !== "undefined" &&
entry.index <= start &&
start < entry.index + entry[0].length
);
useEffect(() => {
setValue(propValue as string);
}, [propValue]);
return match || null;
const isCaretInsideReference = (str: string, start: number) => {
if (str) {
const match = [...str.matchAll(REGEX_SECRET_REFERENCE_FIND)].find(
(entry) =>
typeof entry?.index !== "undefined" &&
entry.index <= start &&
start < entry.index + entry[0].length
);
return match || null;
}
return null;
};
const setCaretPos = (caretPos: number) => {
@@ -299,7 +307,7 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(
if (!showReferencePopup) setIsSecretFocused.off();
}}
{...props}
value={value}
value={value || ""}
readOnly={isReadOnly}
/>
</div>

View File

@@ -100,6 +100,7 @@ export const SecretEditRow = ({
<InfisicalSecretInput
{...field}
value={field.value as string}
key="secret-input"
isVisible={isVisible}
secretPath={secretPath}
environment={environment}