Skip to content

Commit

Permalink
Merge pull request #126 from netervati/fix/model-persistence
Browse files Browse the repository at this point in the history
Ensure model list changes when switching apps
  • Loading branch information
netervati authored Nov 20, 2023
2 parents dec89a2 + 486faa8 commit e9a8580
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
10 changes: 2 additions & 8 deletions composables/useAppRefKey.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
export default function (): string {
const route = useRoute();

if (typeof route.params.urlpath === 'string') {
return route.params.urlpath;
}

return '';
export default function (): Ref<string> {
return useState('app_api_key');
}
15 changes: 15 additions & 0 deletions middleware/setAppRefKey.global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default defineNuxtRouteMiddleware((to, _from) => {
let updated;

if (['/', '/dashboard', '/docs', '/login'].includes(to.path)) {
return;
}

if (typeof to.params.urlpath === 'string') {
updated = to.params.urlpath;
} else {
updated = '';
}

useAppRefKey().value = updated;
});
6 changes: 3 additions & 3 deletions pages/dashboard/app/[url-path]/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
form.setValues({
description: app.target?.description,
title: app.target?.title,
apiKey,
apiKey: apiKey.value,
});
const querySecretKey = useRoute().query?.secret_key;
Expand All @@ -44,13 +44,13 @@
await app.refresh();
app.target = app.list.filter(
(proj) => proj.app_keys[0]?.api_key === apiKey
(proj) => proj.app_keys[0]?.api_key === apiKey.value
)[0];
form.setValues({
description: app.target?.description,
title: app.target?.title,
apiKey,
apiKey: apiKey.value,
});
},
}
Expand Down
2 changes: 1 addition & 1 deletion stores/useApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default defineStore('apps', () => {
body: {
description: payload.description,
title: payload.title,
apiKey: useAppRefKey(),
apiKey: useAppRefKey().value,
},
async onResponse({ response }) {
if (response.status === 200) {
Expand Down
2 changes: 1 addition & 1 deletion stores/useAppKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineStore('appKeys', (): AppKeyStore => {
await $fetch(`/apps/${id}/generate-secret-key`, {
method: 'POST',
body: {
appKey: useAppRefKey(),
appKey: useAppRefKey().value,
},
onResponse({ response }) {
if (response.status === 200) {
Expand Down
15 changes: 11 additions & 4 deletions stores/useModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ export default defineStore('models', () => {
}
);

const list = computed(() => data.value || []);
const list = computed(() => {
if (pending.value) {
return [];
}

return data.value || [];
});

const isDisabled = computed(() => list.value.length === 10 || pending.value);

const setTarget = (md: NormalizedModel) => {
Expand All @@ -47,7 +54,7 @@ export default defineStore('models', () => {
await $fetch('/models', {
method: 'POST',
body: {
apiKey,
apiKey: apiKey.value,
name: body.name,
schema: body.schema,
},
Expand All @@ -72,7 +79,7 @@ export default defineStore('models', () => {
const del = async (id: string): Promise<void> => {
await $fetch(`/models/${id}`, {
method: 'DELETE',
query: { apiKey },
query: { apiKey: apiKey.value },
async onResponse({ response }) {
if (response.status === 200) {
toast.success('Deleted the model!');
Expand All @@ -89,7 +96,7 @@ export default defineStore('models', () => {
name?: string;
schema: Schema;
} = {
apiKey,
apiKey: apiKey.value,
schema: body.schema,
};

Expand Down
4 changes: 2 additions & 2 deletions stores/useModelData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default defineStore('model-data', () => {
const bulkDelete = async (ids: string): Promise<void> => {
await $fetch(`/models/${modelId.value}/model-data`, {
method: 'DELETE',
query: { ids, apiKey },
query: { ids, apiKey: apiKey.value },
async onResponse({ response }) {
if (response.status === 200) {
toast.success('Deleted the model data!');
Expand All @@ -66,7 +66,7 @@ export default defineStore('model-data', () => {
await $fetch(`/models/${modelId.value}/model-data`, {
method: 'POST',
body: {
apiKey,
apiKey: apiKey.value,
increase: body.increase,
schema: body.schema,
},
Expand Down

1 comment on commit e9a8580

@vercel
Copy link

@vercel vercel bot commented on e9a8580 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.