Skip to content
Merged
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
20 changes: 16 additions & 4 deletions src/lib/stores/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ export const backupsBannerId = 'banner:databaseBackups';

export const showPolicyAlert = writable<boolean>(false);

type SubNavigationEntity = {
$id: string;
name: string;
};

type SubNavigationEvent =
| {
type: 'entity-created';
entity: SubNavigationEntity;
}
| undefined;

export async function checkForDatabaseBackupPolicies(
region: string,
projectId: string,
Expand Down Expand Up @@ -50,17 +62,17 @@ export async function checkForDatabaseBackupPolicies(
}

function createSubNavigationTrigger() {
const subscribers = new Set<() => void>();
const subscribers = new Set<(event?: SubNavigationEvent) => void>();

return {
subscribe: (callback: () => void) => {
subscribe: (callback: (event?: SubNavigationEvent) => void) => {
subscribers.add(callback);
return () => {
subscribers.delete(callback);
};
},
update: () => {
subscribers.forEach((callback) => callback());
update: (event?: SubNavigationEvent) => {
subscribers.forEach((callback) => callback(event));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
async function createEntity() {
error = null;
creatingEntity = true;
let createdEntity = false;
try {
const finalId = id || ID.unique();

Expand All @@ -67,6 +68,7 @@

// create entity.
await onCreateEntity(finalId, name, isVectorsDb ? dimension : undefined);
createdEntity = true;

// cleanup
updateAndCleanup();
Expand All @@ -75,7 +77,10 @@
trackError(e, analyticsCreateSubmit);
} finally {
creatingEntity = false;
resetSampleFieldsConfig();

if (!createdEntity || !$entityColumnSuggestions.enabled) {
resetSampleFieldsConfig();
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
}
}

Expand Down Expand Up @@ -103,7 +108,7 @@

$effect(() => {
// reset is OK here, we don't have to check for entity type!
if (show && isOnEntitiesPage && $entityColumnSuggestions.entity) {
if (show && !creatingEntity && isOnEntitiesPage && $entityColumnSuggestions.entity) {
entityColumnSuggestions.update((store) => ({
...store,
entity: null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import { onMount } from 'svelte';
import { isCloud } from '$lib/system';
import IconAI from './icon/ai.svelte';
import { slide } from 'svelte/transition';
Expand All @@ -21,12 +20,6 @@
showSampleCountPicker?: boolean;
} = $props();

onMount(() => {
if (featureActive) {
$entityColumnSuggestions.enabled = true;
}
});

const featureActive = $derived(isCloud);
const { terminology } = getTerminologies();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import type { Snippet } from 'svelte';
import { Input as SuggestionsInput } from '$database/(suggestions)/index';
import { Modal } from '$lib/components';
import { subNavigation } from '$lib/stores/database';

let {
children
Expand All @@ -43,6 +44,7 @@
$registerSearchers(tablesSearcher);

async function createEntity(entityId: string, name: string, dimension?: number) {
const shouldSuggestColumns = $entityColumnSuggestions.enabled;
const entity = await databaseSdk.createEntity({
databaseId,
entityId,
Expand All @@ -51,6 +53,7 @@
});

await invalidate(Dependencies.DATABASE);
await invalidate(Dependencies.TABLES);
await goto(
withPath(
resolveRoute(
Expand All @@ -61,12 +64,26 @@
)
);

if ($entityColumnSuggestions.enabled) {
$randomDataModalState.columns = true;
await $randomDataModalState.onSubmit?.();
}
subNavigation.update({
type: 'entity-created',
entity: {
$id: entity.$id,
name: entity.name
}
});

resetSampleFieldsConfig();
if (shouldSuggestColumns) {
entityColumnSuggestions.update((store) => ({
...store,
enabled: true,
thinking: true,
force: true,
entity: {
id: entity.$id,
name: entity.name
}
}));
}
}

$effect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,21 @@

onMount(() => {
loadEntities();
return subNavigation.subscribe(loadEntities);
return subNavigation.subscribe(async (event) => {
if (event?.type === 'entity-created') {
if (!entities.entities.some((entity: Entity) => entity.$id === event.entity.$id)) {
entities = {
total: entities.total + 1,
entities: [...entities.entities, event.entity as Entity]
};
}

loading = false;
return;
}

await loadEntities();
});
});

function onResize() {
Expand Down
Loading