Skip to content

Commit

Permalink
Fix missing type breaking create corpus form
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Feb 20, 2024
1 parent 77a9066 commit 0e2863f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ As this project is a user-facing application, the places in the semantic version
- Extracted the concept of a Resource as a supertype of Corpus, in preparation for adding the Metadata resource type [#145](https://github.com/spraakbanken/mink-frontend/issues/145)
- Source text file content now look the same as log output

### Fixed

- Missing `type` in store caused new corpus form to crash

## [1.3.0] (2024-02-12)

### Added
Expand Down
3 changes: 2 additions & 1 deletion src/corpus/createCorpus.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default function useCreateCorpus() {
const corpusId = await mink.createCorpus().catch(alertError);
if (!corpusId) return undefined;

return await addNewResource(corpusId);
await addNewResource("corpus", corpusId);
return corpusId;
}

async function createFromUpload(files: FileList) {
Expand Down
2 changes: 1 addition & 1 deletion src/metadata/CreateMetadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function submit(fields: Form) {
.catch(alertError);
if (!resourceId) return;
await addNewResource(resourceId);
await addNewResource("metadata", resourceId);
router.push(`/library/metadata/${resourceId}`);
}
Expand Down
15 changes: 10 additions & 5 deletions src/resource/createResource.composable.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import type { ResourceType } from "@/api/api.types";
import { useAuth } from "@/auth/auth.composable";
import { useResourceStore } from "@/store/resource.store";

export default function useCreateResource() {
const { refreshJwt } = useAuth();
const resourceStore = useResourceStore();

async function addNewResource(resourceId: string) {
/**
* Register a newly created resource.
* @param type The type is necessary for the store's filter getters to include the new object.
* @param resourceId The resource id.
*/
async function addNewResource(type: ResourceType, resourceId: string) {
// Have the new corpus included in further API calls.
await refreshJwt();

// Adding the new id to store may trigger API calls, so do it after updating the JWT.
resourceStore.resources[resourceId] =
resourceStore.resources[resourceId] || {};

return resourceId;
if (!(resourceId in resourceStore.resources)) {
resourceStore.resources[resourceId] = { type };
}
}

return {
Expand Down

0 comments on commit 0e2863f

Please sign in to comment.