Skip to content

Commit

Permalink
Store resource owner, fix #156
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Mar 18, 2024
1 parent 7188930 commit 422f472
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/api/api.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ByLang } from "@/util.types";
import type { ByLang, SweEng } from "@/util.types";
import type { AxiosProgressEvent } from "axios";

/** Properties common to most backend responses */
Expand Down Expand Up @@ -61,10 +61,19 @@ export type ResourceInfoOneData = ResourceInfo;

/** Data about a resource and its job status */
export type ResourceInfo = {
owner?: UserData;
resource: ResourceData;
job: CorpusStatus;
};

/** Data about a Mink user */
export type UserData = {
id: string;
name: string;
email: string;
ui_language: SweEng;
};

/** Basic data about a resource */
export type ResourceData = {
type: ResourceType;
Expand Down
2 changes: 1 addition & 1 deletion src/library/AdminResourcesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function load(resourceId: string) {
<!-- Show a few selected details if loaded -->
<div class="ml-4">
<div v-if="'type' in resource" class="flex gap-4">
{{ $t(resource.type) }}
<span v-if="resource.owner">{{ resource.owner.name }}</span>
<span
v-if="
isCorpus(resource) &&
Expand Down
12 changes: 11 additions & 1 deletion src/store/resource.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import type { ConfigOptions } from "@/api/corpusConfig";
export type Resource = {
type: ResourceType;
name: ByLang;
owner?: User;
};

export type User = {
name: string;
id: string;
};

export type Corpus = Resource & {
Expand Down Expand Up @@ -41,7 +47,7 @@ export const useResourceStore = defineStore("resource", () => {
// current date (YYMMDD) if the state shape is changed, to make the browser
// forget the old state. The actual number doesn't really matter, as long as
// it's a new one.
const resourcesRef = useStorage("mink@230208.resources", {});
const resourcesRef = useStorage("mink@240318.resources", {});
const resources: Record<string, {} | Resource> = reactive(resourcesRef.value);

const corpora = computed<Record<string, Partial<Corpus>>>(() =>
Expand Down Expand Up @@ -83,6 +89,9 @@ export const useResourceStore = defineStore("resource", () => {
const resource = {
type: info.resource.type,
name: info.resource.name,
owner: info.owner
? { name: info.owner.name, id: info.owner.id }
: undefined,
};

if (isCorpus(resource)) {
Expand All @@ -91,6 +100,7 @@ export const useResourceStore = defineStore("resource", () => {
}

if (isMetadata(resource)) {
resource.owner = info.owner;
resource.publicId = info.resource.public_id;
}

Expand Down

0 comments on commit 422f472

Please sign in to comment.