From 6dc08dcc06ec43c6d0807c52bdb2257d53bbdabb Mon Sep 17 00:00:00 2001 From: Zaid Sheikh Date: Wed, 6 Dec 2023 08:17:06 -0500 Subject: [PATCH 1/3] allow duplicate slice names --- backend/zeno_backend/database/insert.py | 29 +++++++------------ .../src/lib/components/metadata/Slices.svelte | 2 +- .../lib/components/popups/SlicePopup.svelte | 10 +------ 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/backend/zeno_backend/database/insert.py b/backend/zeno_backend/database/insert.py index b9f5c5c2..e5b534cf 100644 --- a/backend/zeno_backend/database/insert.py +++ b/backend/zeno_backend/database/insert.py @@ -640,25 +640,18 @@ async def all_slices_for_column( folder_id=None if folder_id is None else folder_id[0], ) await cur.execute( - sql.SQL( - "SELECT id FROM slices WHERE name={} AND project_uuid={};" - ).format(slice.slice_name, project) + "INSERT INTO slices (name, filter, project_uuid, folder_id) " + "VALUES (%s,%s,%s,%s) RETURNING id;", + [ + slice.slice_name, + json.dumps(slice.filter_predicates, cls=PredicatesEncoder), + project, + slice.folder_id, + ], ) - exists = await cur.fetchall() - if len(exists) == 0: - await cur.execute( - "INSERT INTO slices (name, filter, project_uuid, folder_id) " - "VALUES (%s,%s,%s,%s) RETURNING id;", - [ - slice.slice_name, - json.dumps(slice.filter_predicates, cls=PredicatesEncoder), - project, - slice.folder_id, - ], - ) - id = await cur.fetchone() - if id is not None: - ids.append(id[0]) + id = await cur.fetchone() + if id is not None: + ids.append(id[0]) return ids diff --git a/frontend/src/lib/components/metadata/Slices.svelte b/frontend/src/lib/components/metadata/Slices.svelte index ea61c785..400f7bf9 100644 --- a/frontend/src/lib/components/metadata/Slices.svelte +++ b/frontend/src/lib/components/metadata/Slices.svelte @@ -61,7 +61,7 @@ {#each $folders as folder} {/each} - {#each $slices.filter((s) => s.folderId === null || s.folderId === undefined) as s (s.sliceName)} + {#each $slices.filter((s) => s.folderId === null || s.folderId === undefined) as s (s.id)} {/each} diff --git a/frontend/src/lib/components/popups/SlicePopup.svelte b/frontend/src/lib/components/popups/SlicePopup.svelte index 40d8e03e..d1641c62 100644 --- a/frontend/src/lib/components/popups/SlicePopup.svelte +++ b/frontend/src/lib/components/popups/SlicePopup.svelte @@ -220,7 +220,6 @@ @@ -228,11 +227,7 @@ @@ -240,9 +235,6 @@ - {#if (!sliceToEdit && $slices.some((slice) => slice.sliceName === sliceName)) || (sliceToEdit && originalName !== sliceName && $slices.some((slice) => slice.sliceName === sliceName))} -

slice already exists

- {/if} {#if error}
From 5841eb0a84c53c6bfae5a4a579a15cd4fab211be Mon Sep 17 00:00:00 2001 From: Zaid Sheikh Date: Wed, 6 Dec 2023 09:36:33 -0500 Subject: [PATCH 2/3] fix: prettier style --- frontend/src/lib/components/popups/SlicePopup.svelte | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/frontend/src/lib/components/popups/SlicePopup.svelte b/frontend/src/lib/components/popups/SlicePopup.svelte index d1641c62..ba1e30d9 100644 --- a/frontend/src/lib/components/popups/SlicePopup.svelte +++ b/frontend/src/lib/components/popups/SlicePopup.svelte @@ -217,18 +217,11 @@ deletePredicate(-1)} bind:predicateGroup />
{#if checkNominalSinglePredicateNoEntry(predicateGroup)} - {:else} - {/if} From 0ac3487267be46c71f411bee8415ce87011ddf26 Mon Sep 17 00:00:00 2001 From: Zaid Sheikh Date: Wed, 6 Dec 2023 09:44:04 -0500 Subject: [PATCH 3/3] fix: remove unused var --- frontend/src/lib/components/popups/SlicePopup.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/src/lib/components/popups/SlicePopup.svelte b/frontend/src/lib/components/popups/SlicePopup.svelte index ba1e30d9..5285713d 100644 --- a/frontend/src/lib/components/popups/SlicePopup.svelte +++ b/frontend/src/lib/components/popups/SlicePopup.svelte @@ -30,7 +30,6 @@ let error: string | undefined = undefined; // Track original settings when editing. - let originalName = ''; let originalPredicates; $: isValidPredicates = checkValidPredicates(predicateGroup.predicates); @@ -81,7 +80,6 @@ sliceName = sliceToEdit.sliceName; predicateGroup = sliceToEdit.filterPredicates; folderId = sliceToEdit.folderId === null ? undefined : sliceToEdit.folderId; - originalName = sliceName; // deep copy of predicate group to avoid sharing nested objects originalPredicates = JSON.parse(JSON.stringify(predicateGroup));