Merge branch 'main' into auto-capitalization-toggle

This commit is contained in:
mv-turtle
2023-02-07 21:32:29 -08:00
committed by GitHub
4 changed files with 87 additions and 5 deletions
+42 -3
View File
@@ -24,6 +24,7 @@ import Button from '@app/components/basic/buttons/Button';
import ListBox from '@app/components/basic/Listbox';
import BottonRightPopup from '@app/components/basic/popups/BottomRightPopup';
import { useNotificationContext } from '@app/components/context/Notifications/NotificationProvider';
import ConfirmEnvOverwriteModal from '@app/components/dashboard/ConfirmEnvOverwriteModal';
import DownloadSecretMenu from '@app/components/dashboard/DownloadSecretsMenu';
import DropZone from '@app/components/dashboard/DropZone';
import KeyPair from '@app/components/dashboard/KeyPair';
@@ -132,6 +133,7 @@ export default function Dashboard() {
const [numSnapshots, setNumSnapshots] = useState<number>();
const [saveLoading, setSaveLoading] = useState(false);
const [autoCapitalization, setAutoCapitalization] = useState(false);
const [dropZoneData, setDropZoneData] = useState<SecretDataProps[]>();
const [projectTags, setProjectTags] = useState<Tag[]>([]);
const { t } = useTranslation();
@@ -548,11 +550,33 @@ export default function Dashboard() {
return undefined;
};
const addData = (newData: SecretDataProps[]) => {
setData(data!.concat(newData));
const addDataWithMerge = (newData: SecretDataProps[], preserve?: 'old' | 'new') => {
setData((oldData) => {
let filteredOldData = oldData!;
let filteredNewData = newData;
if (preserve === 'new')
filteredOldData = oldData!.filter(
(oldDataPoint) => !newData.find((newDataPoint) => newDataPoint.key === oldDataPoint.key)
);
if (preserve === 'old')
filteredNewData = newData.filter(
(newDataPoint) => !oldData?.find((oldDataPoint) => oldDataPoint.key === newDataPoint.key)
);
return filteredOldData.concat(filteredNewData);
});
setButtonReady(true);
};
const addData = (newData: SecretDataProps[]) => {
if (
newData.some((newDataPoint) => data?.find((dataPoint) => dataPoint.key === newDataPoint.key)) // if newData contains duplicates
) {
setDropZoneData(newData);
return;
}
addDataWithMerge(newData);
};
const changeBlurred = () => {
setBlurred(!blurred);
};
@@ -570,7 +594,22 @@ export default function Dashboard() {
<meta property="og:title" content={String(t('dashboard:og-title'))} />
<meta name="og:description" content={String(t('dashboard:og-description'))} />
</Head>
<div className="flex flex-row h-full dark:[color-scheme:dark]">
<div className="flex flex-row h-full">
<ConfirmEnvOverwriteModal
isOpen={!!dropZoneData}
onClose={() => setDropZoneData(undefined)}
onOverwriteConfirm={(preserve) => {
addDataWithMerge(dropZoneData!, preserve);
setDropZoneData(undefined);
}}
duplicateKeys={
dropZoneData
?.filter((newDataPoint) =>
data?.find((dataPoint) => dataPoint.key === newDataPoint.key)
)
.map((duplicate) => duplicate.key) ?? []
}
/>
<div className="w-full max-h-96 pb-2 dark:[color-scheme:dark]">
<NavHeader pageName={t('dashboard:title')} isProjectRelated />
{checkDocsPopUpVisible && (