Fixed the sorting buf with version history

This commit is contained in:
Vladyslav Matsiiako
2023-01-02 18:53:56 -08:00
parent 6845e9129a
commit d0949b2e19
2 changed files with 42 additions and 26 deletions
@@ -18,6 +18,7 @@ import { SecretVersion } from '../../models';
secretVersions = await SecretVersion.find({ secretVersions = await SecretVersion.find({
secret: secretId secret: secretId
}) })
.sort({ createdAt: -1 })
.skip(offset) .skip(offset)
.limit(limit); .limit(limit);
+20 -5
View File
@@ -1,4 +1,5 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import Image from 'next/image';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { useTranslation } from "next-i18next"; import { useTranslation } from "next-i18next";
import { faCircle, faDotCircle } from '@fortawesome/free-solid-svg-icons'; import { faCircle, faDotCircle } from '@fortawesome/free-solid-svg-icons';
@@ -22,15 +23,18 @@ interface EncrypetedSecretVersionListProps {
/** /**
* @param {string} secretId - the id of a secret for which are querying version history
* @returns a list of versions for a specific secret * @returns a list of versions for a specific secret
*/ */
const SecretVersionList = ({ secretId }: { secretId: string; }) => { const SecretVersionList = ({ secretId }: { secretId: string; }) => {
const router = useRouter(); const router = useRouter();
const [isLoading, setIsLoading] = useState(false);
const { t } = useTranslation(); const { t } = useTranslation();
const [secretVersions, setSecretVersions] = useState<DecryptedSecretVersionListProps[]>([{createdAt: "123", value: "124"}]); const [secretVersions, setSecretVersions] = useState<DecryptedSecretVersionListProps[]>([]);
useEffect(() => { useEffect(() => {
const getSecretVersionHistory = async () => { const getSecretVersionHistory = async () => {
setIsLoading(true);
try { try {
const encryptedSecretVersions = await getSecretVersions({ secretId, offset: 0, limit: 10}); const encryptedSecretVersions = await getSecretVersions({ secretId, offset: 0, limit: 10});
const latestKey = await getLatestFileKey({ workspaceId: String(router.query.id) }) const latestKey = await getLatestFileKey({ workspaceId: String(router.query.id) })
@@ -61,16 +65,27 @@ const SecretVersionList = ({ secretId }: { secretId: string; }) => {
}) })
setSecretVersions(decryptedSecretVersions); setSecretVersions(decryptedSecretVersions);
setIsLoading(false);
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
}; };
getSecretVersionHistory(); getSecretVersionHistory();
}, []); }, [secretId]);
return <div className='w-full h-52 px-4 mt-4 text-sm text-bunker-300 overflow-x-none'> return <div className='w-full h-52 px-4 mt-4 text-sm text-bunker-300 overflow-x-none'>
<p className=''>{t("dashboard:sidebar.version-history")}</p> <p className=''>{t("dashboard:sidebar.version-history")}</p>
<div className='p-1 rounded-md bg-bunker-800 border border-mineshaft-500 overflow-x-none'> <div className='p-1 rounded-md bg-bunker-800 border border-mineshaft-500 overflow-x-none h-full'>
{isLoading ? (
<div className="flex items-center justify-center h-full">
<Image
src="/images/loading/loading.gif"
height={60}
width={100}
alt="infisical loading indicator"
></Image>
</div>
) : (
<div className='h-48 overflow-y-auto overflow-x-none'> <div className='h-48 overflow-y-auto overflow-x-none'>
{secretVersions?.sort((a, b) => b.createdAt.localeCompare(a.createdAt)) {secretVersions?.sort((a, b) => b.createdAt.localeCompare(a.createdAt))
.map((version: DecryptedSecretVersionListProps, index: number) => .map((version: DecryptedSecretVersionListProps, index: number) =>
@@ -91,13 +106,13 @@ const SecretVersionList = ({ secretId }: { secretId: string; }) => {
})} })}
</div> </div>
<div className=''><p className='break-words'><span className='py-0.5 px-1 rounded-md bg-primary-200/10 mr-1.5'>Value:</span>{version.value}</p></div> <div className=''><p className='break-words'><span className='py-0.5 px-1 rounded-md bg-primary-200/10 mr-1.5'>Value:</span>{version.value}</p></div>
{/* <div className=''><p className='break-words'><span className='py-0.5 px-1 rounded-md bg-primary-200/10 mr-1.5'>Updated by:</span>{version.user}</p></div> */}
</div> </div>
</div> </div>
)} )}
</div> </div>
)}
</div>
</div> </div>
</div>
}; };
export default SecretVersionList; export default SecretVersionList;