Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow duplicate slice names #532

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions backend/zeno_backend/database/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/metadata/Slices.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
{#each $folders as folder}
<FolderCell {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)}
<SliceCell compare={$page.url.href.includes('compare')} slice={s} />
{/each}
</div>
21 changes: 2 additions & 19 deletions frontend/src/lib/components/popups/SlicePopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
let error: string | undefined = undefined;

// Track original settings when editing.
let originalName = '';
let originalPredicates;

$: isValidPredicates = checkValidPredicates(predicateGroup.predicates);
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -217,32 +215,17 @@
<FilterGroupEntry index={-1} deletePredicate={() => deletePredicate(-1)} bind:predicateGroup />
<div class="flex flex-row-reverse items-center">
{#if checkNominalSinglePredicateNoEntry(predicateGroup)}
<Button
variant="outlined"
on:click={createAllSlices}
disabled={$slices.some((slice) => slice.sliceName === sliceName)}
>
<Button variant="outlined" on:click={createAllSlices}>
{'Create Slices for all Values'}
</Button>
{:else}
<Button
variant="outlined"
on:click={saveSlice}
disabled={(!sliceToEdit && $slices.some((slice) => slice.sliceName === sliceName)) ||
(sliceToEdit &&
originalName !== sliceName &&
$slices.some((slice) => slice.sliceName === sliceName)) ||
!isValidPredicates}
>
<Button variant="outlined" on:click={saveSlice} disabled={!isValidPredicates}>
{sliceToEdit ? 'Update Slice' : 'Create Slice'}
</Button>
{/if}
<Button style="margin-right: 10px" variant="outlined" on:click={() => dispatch('close')}>
cancel
</Button>
{#if (!sliceToEdit && $slices.some((slice) => slice.sliceName === sliceName)) || (sliceToEdit && originalName !== sliceName && $slices.some((slice) => slice.sliceName === sliceName))}
<p style:margin-right="10px" style:color="red">slice already exists</p>
{/if}
</div>
{#if error}
<div class="flex flex-row-reverse items-center">
Expand Down
Loading