diff --git a/backend/zeno_backend/database/insert.py b/backend/zeno_backend/database/insert.py index 7190cc52..d10e6868 100644 --- a/backend/zeno_backend/database/insert.py +++ b/backend/zeno_backend/database/insert.py @@ -316,31 +316,40 @@ def system( db.commit() -def folder(project: str, name: str): +def folder(project: str, name: str) -> int | None: """Adding a folder to an existing project. Args: project (str): the project the user is currently working with. name (str): name of the folder to be added. + + + Returns: + int | None: the id of the newly created folder. """ db = Database() - db.connect_execute( - "INSERT INTO folders (name, project_uuid) VALUES (%s,%s);", + id = db.connect_execute_return( + "INSERT INTO folders (name, project_uuid) VALUES (%s,%s) RETURNING id;", [name, project], ) + if id is not None and len(id) > 0: + return id[0][0] -def slice(project: str, req: Slice): +def slice(project: str, req: Slice) -> int | None: """Add a slice to an existing project. Args: project (str): the project the user is currently working with. req (Slice): the slice to be added to the project. + + Returns: + int | None: the id of the newly created slice. """ db = Database() - db.connect_execute( + ids = db.connect_execute_return( "INSERT INTO slices (name, folder_id, filter, project_uuid) " - "VALUES (%s,%s,%s,%s);", + "VALUES (%s,%s,%s,%s) RETURNING id;", [ req.slice_name, req.folder_id, @@ -348,19 +357,27 @@ def slice(project: str, req: Slice): project, ], ) + if ids is not None: + return ids[0][0] + else: + return None -def chart(project: str, chart: Chart): +def chart(project: str, chart: Chart) -> int | None: """Add a chart to an existing project. Args: project (str): the project the user is currently working with. chart (Chart): the chart to be added to the project. + + + Returns: + int | None: the id of the newly created chart. """ db = Database() - db.connect_execute( + id = db.connect_execute_return( "INSERT INTO charts (name, type, parameters, project_uuid) " - "VALUES (%s,%s,%s,%s);", + "VALUES (%s,%s,%s,%s) RETURNING id;", [ chart.name, chart.type, @@ -368,14 +385,19 @@ def chart(project: str, chart: Chart): project, ], ) + if id is not None and len(id) > 0: + return id[0][0] -def tag(project: str, tag: Tag): +def tag(project: str, tag: Tag) -> int | None: """Add a tag to an existing project. Args: project (str): the project the user is currently working with. tag (Tag): the tag to be added to the project. + + Returns: + int | None: the id of the newly created tag. """ with Database() as db: id = db.execute_return( @@ -383,16 +405,17 @@ def tag(project: str, tag: Tag): "RETURNING id;", [tag.tag_name, tag.folder_id, project], ) - if id is None: + if id is None or len(id) == 0: return for datapoint in tag.data_ids: db.execute( sql.SQL("INSERT INTO {} (tag_id, data_id) VALUES (%s,%s);").format( sql.Identifier(f"{project}_tags_datapoints") ), - [id[0], datapoint], + [id[0][0], datapoint], ) db.commit() + return id[0][0] def user(user: User): diff --git a/backend/zeno_backend/database/select.py b/backend/zeno_backend/database/select.py index 70174e26..12a57a8b 100644 --- a/backend/zeno_backend/database/select.py +++ b/backend/zeno_backend/database/select.py @@ -832,7 +832,7 @@ def tags(project: str) -> list[Tag]: folder_id=tag_result[2], data_ids=[] if len(data_results) == 0 - else list(map(lambda d: d[0], data_results[0])), + else [d[0] for d in data_results], ) ) return tags diff --git a/backend/zeno_backend/database/update.py b/backend/zeno_backend/database/update.py index ffbe264e..2fe1fbfd 100644 --- a/backend/zeno_backend/database/update.py +++ b/backend/zeno_backend/database/update.py @@ -95,7 +95,7 @@ def tag(tag: Tag, project: str): tag.id, ], ) - if len(data_ids_result) == 0: + if data_ids_result is None: return existing_data = set(map(lambda d: d[0], data_ids_result)) diff --git a/backend/zeno_backend/server.py b/backend/zeno_backend/server.py index a39f2f45..3e454266 100644 --- a/backend/zeno_backend/server.py +++ b/backend/zeno_backend/server.py @@ -248,7 +248,7 @@ def get_filtered_table(req: TableRequest, project_uuid: str, request: Request): # Prepend the DATA_URL to the data column if it exists project = select.project_from_uuid(project_uuid) if project and project.data_url: - filt_df["data_id"] = project.data_url + filt_df["data_id"] + filt_df["data"] = project.data_url + filt_df["data"] if req.diff_column_1 and req.diff_column_2: filt_df = generate_diff_cols( @@ -455,21 +455,65 @@ def login(name: str): else: return fetched_user - @api_app.post("/folder/{project}", tags=["zeno"], dependencies=[Depends(auth)]) + @api_app.post( + "/folder/{project}", + response_model=int, + tags=["zeno"], + dependencies=[Depends(auth)], + ) def add_folder(project: str, name: str): - insert.folder(project, name) + id = insert.folder(project, name) + if id is None: + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, + detail="Failed to insert folder", + ) + return id - @api_app.post("/slice/{project}", tags=["zeno"], dependencies=[Depends(auth)]) + @api_app.post( + "/slice/{project}", + response_model=int, + tags=["zeno"], + dependencies=[Depends(auth)], + ) def add_slice(project: str, req: Slice): - insert.slice(project, req) + id = insert.slice(project, req) + if id is None: + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, + detail="Failed to insert slice", + ) + return id - @api_app.post("/chart/{project}", tags=["zeno"], dependencies=[Depends(auth)]) + @api_app.post( + "/chart/{project}", + response_model=int, + tags=["zeno"], + dependencies=[Depends(auth)], + ) def add_chart(project: str, chart: Chart): - insert.chart(project, chart) + id = insert.chart(project, chart) + if id is None: + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, + detail="Failed to insert chart", + ) + return id - @api_app.post("/tag/{project}", tags=["zeno"], dependencies=[Depends(auth)]) + @api_app.post( + "/tag/{project}", + response_model=int, + tags=["zeno"], + dependencies=[Depends(auth)], + ) def add_tag(tag: Tag, project: str): - insert.tag(project, tag) + id = insert.tag(project, tag) + if id is None: + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, + detail="Failed to insert tag", + ) + return id @api_app.post("/add-organization", tags=["zeno"], dependencies=[Depends(auth)]) def add_organization(user: User, organization: Organization): diff --git a/frontend/src/lib/components/chart/ChartHomeBlock.svelte b/frontend/src/lib/components/chart/ChartHomeBlock.svelte index aa3e387a..98234388 100644 --- a/frontend/src/lib/components/chart/ChartHomeBlock.svelte +++ b/frontend/src/lib/components/chart/ChartHomeBlock.svelte @@ -9,7 +9,7 @@ mdiViewGrid } from '@mdi/js'; - import { goto } from '$app/navigation'; + import { goto, invalidateAll } from '$app/navigation'; import { page } from '$app/stores'; import { charts, project } from '$lib/stores'; import { clickOutside } from '$lib/util/clickOutside'; @@ -69,10 +69,17 @@ name: 'Copy of ' + chart.name, type: chart.type, parameters: chart.parameters - }).then(() => { - ZenoService.getCharts($project ? $project.uuid : '').then((fetchedCharts) => - charts.set(fetchedCharts) - ); + }).then((res) => { + invalidateAll(); + charts.update((c) => { + c.push({ + id: res, + name: 'Copy of ' + chart.name, + type: chart.type, + parameters: chart.parameters + }); + return c; + }); }); }} > @@ -86,9 +93,8 @@ e.stopPropagation(); showOptions = false; ZenoService.deleteChart(chart).then(() => { - ZenoService.getCharts($project ? $project.uuid : '').then((fetchedCharts) => - charts.set(fetchedCharts) - ); + invalidateAll(); + charts.update((c) => c.filter((c) => c.id != chart.id)); }); }} > diff --git a/frontend/src/lib/components/instance-views/ComparisonView.svelte b/frontend/src/lib/components/instance-views/ComparisonView.svelte index 2b343bc0..689bc5d2 100644 --- a/frontend/src/lib/components/instance-views/ComparisonView.svelte +++ b/frontend/src/lib/components/instance-views/ComparisonView.svelte @@ -87,7 +87,7 @@ updateTable(); } - comparisonColumn.subscribe((_) => { + comparisonColumn.subscribe(() => { table = undefined; compareSort.set([undefined, true]); }); diff --git a/frontend/src/lib/components/instance-views/InstanceView.svelte b/frontend/src/lib/components/instance-views/InstanceView.svelte index 733d4ed9..8dc8609c 100644 --- a/frontend/src/lib/components/instance-views/InstanceView.svelte +++ b/frontend/src/lib/components/instance-views/InstanceView.svelte @@ -54,7 +54,6 @@ onMount(() => { if ($project === undefined || $project.view === '') { selected = 'table'; - return; } }); diff --git a/frontend/src/lib/components/instance-views/views/views/AudioTranscription.svelte b/frontend/src/lib/components/instance-views/views/views/AudioTranscription.svelte index 51edb04c..310d2356 100644 --- a/frontend/src/lib/components/instance-views/views/views/AudioTranscription.svelte +++ b/frontend/src/lib/components/instance-views/views/views/AudioTranscription.svelte @@ -2,7 +2,7 @@ export let entry: Record; export let modelColumn: string; - $: audioURL = entry['data_id'] as string; + $: audioURL = entry['data'] as string;
diff --git a/frontend/src/lib/components/metadata/MetadataHeader.svelte b/frontend/src/lib/components/metadata/MetadataHeader.svelte index 2e6186be..d8c55ed6 100644 --- a/frontend/src/lib/components/metadata/MetadataHeader.svelte +++ b/frontend/src/lib/components/metadata/MetadataHeader.svelte @@ -15,12 +15,6 @@ let comparisonColumnOptions: ZenoColumn[] = []; onMount(() => { - if ($model === undefined && $models.length > 0) { - model.set($models[0]); - } - if ($metric === undefined && $metrics.length > 0) { - metric.set($metrics[0]); - } comparisonColumnOptions = $columns.filter((c) => c.model === $model); comparisonColumn.set(comparisonColumnOptions[0]); }); diff --git a/frontend/src/lib/components/metadata/Slices.svelte b/frontend/src/lib/components/metadata/Slices.svelte index 90e8492a..dfed1f6f 100644 --- a/frontend/src/lib/components/metadata/Slices.svelte +++ b/frontend/src/lib/components/metadata/Slices.svelte @@ -59,7 +59,7 @@ {#each $folders as folder} {/each} - {#each $slices.filter((s) => s.folderId === null && s.sliceName !== 'All Instances') as s (s.sliceName)} + {#each $slices.filter((s) => s.folderId === null || s.folderId === undefined) as s (s.sliceName)} {/each}
diff --git a/frontend/src/lib/components/metadata/Tags.svelte b/frontend/src/lib/components/metadata/Tags.svelte index 6251057a..a66b3f9c 100644 --- a/frontend/src/lib/components/metadata/Tags.svelte +++ b/frontend/src/lib/components/metadata/Tags.svelte @@ -1,4 +1,5 @@ @@ -79,13 +86,15 @@ {#each [...$tags.values()] as t} {#if $editTag !== undefined && $editTag.id === t.id}
-
+
+ Done +
{:else} diff --git a/frontend/src/lib/components/metadata/cells/FolderCell.svelte b/frontend/src/lib/components/metadata/cells/FolderCell.svelte index 573cb5db..658ffdbf 100644 --- a/frontend/src/lib/components/metadata/cells/FolderCell.svelte +++ b/frontend/src/lib/components/metadata/cells/FolderCell.svelte @@ -1,4 +1,5 @@
- {tagId} + {$tags.find((tag) => tag.id === tagId)?.tagName} cancel
diff --git a/frontend/src/lib/components/popups/FolderPopup.svelte b/frontend/src/lib/components/popups/FolderPopup.svelte index 38431113..d76ddd58 100644 --- a/frontend/src/lib/components/popups/FolderPopup.svelte +++ b/frontend/src/lib/components/popups/FolderPopup.svelte @@ -1,4 +1,5 @@ diff --git a/frontend/src/routes/(app)/project/[owner]/[project]/chart/+page.svelte b/frontend/src/routes/(app)/project/[owner]/[project]/chart/+page.svelte index 3f816c62..b9746b55 100644 --- a/frontend/src/routes/(app)/project/[owner]/[project]/chart/+page.svelte +++ b/frontend/src/routes/(app)/project/[owner]/[project]/chart/+page.svelte @@ -1,5 +1,5 @@