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