Skip to content

Commit 4669070

Browse files
treangenerall
andauthored
Check the version before displaying datasets (#245)
* check version before displaying datasets * format * using version from the top level * add move checks --------- Co-authored-by: generall <[email protected]>
1 parent 8763731 commit 4669070

File tree

4 files changed

+83
-13
lines changed

4 files changed

+83
-13
lines changed

src/lib/common-helpers.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,27 @@ export const resizeObserverWithCallback = (callback) => {
77
}
88
});
99
};
10+
11+
/**
12+
* Compare two semver strings.
13+
* @param {string} version1 - The first version string.
14+
* @param {string} version2 - The second version string.
15+
* @return {number} - Returns 0 if the versions are equal, 1 if version1 is greater, and -1 if version2 is greater.
16+
*/
17+
export const compareSemver = function (version1, version2) {
18+
const parseVersion = (version) => version.split('.').map(Number);
19+
20+
const [major1, minor1, patch1] = parseVersion(version1);
21+
const [major2, minor2, patch2] = parseVersion(version2);
22+
23+
if (major1 !== major2) {
24+
return major1 > major2 ? 1 : -1;
25+
}
26+
if (minor1 !== minor2) {
27+
return minor1 > minor2 ? 1 : -1;
28+
}
29+
if (patch1 !== patch2) {
30+
return patch1 > patch2 ? 1 : -1;
31+
}
32+
return 0;
33+
};

src/lib/tests/common-helpers.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { compareSemver } from '../common-helpers';
3+
4+
describe('compareSemver', () => {
5+
it('should return 0 if the versions are equal', () => {
6+
const version1 = '1.0.0';
7+
const version2 = '1.0.0';
8+
const result = compareSemver(version1, version2);
9+
expect(result).toEqual(0);
10+
});
11+
12+
it('should return 1 if version1 is greater', () => {
13+
const version1 = '1.0.1';
14+
const version2 = '1.0.0';
15+
const result = compareSemver(version1, version2);
16+
expect(result).toEqual(1);
17+
});
18+
19+
it('should return -1 if version2 is greater', () => {
20+
const version1 = '1.0.0';
21+
const version2 = '1.0.1';
22+
const result = compareSemver(version1, version2);
23+
expect(result).toEqual(-1);
24+
});
25+
});

src/pages/Datasets.jsx

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,52 @@ import { DatasetsTableRow } from '../components/Datasets/DatasetsTableRow';
77
import { useClient } from '../context/client-context';
88
import { useSnackbar } from 'notistack';
99
import { getSnackbarOptions } from '../components/Common/utils/snackbarOptions';
10+
import { compareSemver } from '../lib/common-helpers';
11+
import { useOutletContext } from 'react-router-dom';
1012

1113
function Datasets() {
1214
const [datasets, setDatasets] = useState([]);
1315
const { client: qdrantClient } = useClient();
1416
const [isLoading, setIsLoading] = useState(false);
1517
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
1618
const errorSnackbarOptions = getSnackbarOptions('error', closeSnackbar);
19+
const { version } = useOutletContext();
1720

1821
useEffect(() => {
1922
const fetchData = async () => {
2023
setIsLoading(true);
2124
try {
2225
const response = await fetch('https://snapshots.qdrant.io/manifest.json');
2326
const responseJson = await response.json();
24-
const datasets = responseJson.map((dataset) => {
25-
return {
26-
name: dataset.name,
27-
fileName: dataset.file_name,
28-
size: dataset.size,
29-
vectors: dataset.vectors,
30-
vectorCount: dataset.vector_count,
31-
description: dataset.description,
32-
};
33-
});
27+
const datasets = responseJson
28+
.filter((dataset) => {
29+
if (dataset.version === undefined) {
30+
return true;
31+
}
32+
// There are a few exceptions:
33+
// - dev version is always allowed, it includes `dev` as a substring
34+
// - `???` means we can't display the version, so we only allow unversioned datasets
35+
// - empty or underfined means the same as `???`
36+
37+
if (version || version === '???') {
38+
return false;
39+
}
40+
41+
if (version.includes('dev')) {
42+
return true;
43+
}
44+
return compareSemver(version, dataset.version) >= 0;
45+
})
46+
.map((dataset) => {
47+
return {
48+
name: dataset.name,
49+
fileName: dataset.file_name,
50+
size: dataset.size,
51+
vectors: dataset.vectors,
52+
vectorCount: dataset.vector_count,
53+
description: dataset.description,
54+
};
55+
});
3456
setDatasets(datasets);
3557
} catch (error) {
3658
enqueueSnackbar(error.message, errorSnackbarOptions);
@@ -52,10 +74,9 @@ function Datasets() {
5274
setImporting(true);
5375

5476
try {
55-
const response = await qdrantClient.recoverSnapshot(collectionName, {
77+
await qdrantClient.recoverSnapshot(collectionName, {
5678
location: `https://snapshots.qdrant.io/${fileName}`,
5779
});
58-
console.log(response);
5980
enqueueSnackbar('Snapshot successfully imported', getSnackbarOptions('success', closeSnackbar, 2000));
6081
} catch (e) {
6182
enqueueSnackbar(e.message, errorSnackbarOptions);

src/pages/Home.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default function MiniDrawer() {
106106
<Sidebar open={open} version={version} jwtEnabled={jwtEnabled} jwtVisible={jwtVisible} />
107107
<Box component="main" sx={{ flexGrow: 1, overflow: 'hidden' }}>
108108
<DrawerHeader />
109-
<Outlet />
109+
<Outlet context={{ version }} />
110110
</Box>
111111
<ApiKeyDialog open={apiKeyDialogOpen} setOpen={setApiKeyDialogOpen} onApply={OnApyKeyApply} />
112112
</Box>

0 commit comments

Comments
 (0)