fix: retrieval of valid_labels from API to populate the TEXT_LABEL_FLAGS in FlaggableElements.tsx

This commit is contained in:
James Melvin
2023-01-09 22:31:44 +05:30
parent 66891dd690
commit 420b3739eb
5 changed files with 79 additions and 49 deletions
+33
View File
@@ -48,6 +48,33 @@ export class OasstApiClient {
return await resp.json();
}
private async get(path: string): Promise<any> {
const resp = await fetch(`${this.oasstApiUrl}${path}`, {
method: "GET",
headers: {
"X-API-Key": this.oasstApiKey,
"Content-Type": "application/json",
},
});
if (resp.status == 204) {
return null;
}
if (resp.status >= 300) {
const errorText = await resp.text();
let error: any;
try {
error = JSON.parse(errorText);
} catch (e) {
throw new OasstError(errorText, 0, resp.status);
}
throw new OasstError(error.message ?? error, error.error_code, resp.status);
}
return await resp.json();
}
// TODO return a strongly typed Task?
// This method is used to store a task in RegisteredTask.task.
// This is a raw Json type, so we can't use it to strongly type the task.
@@ -96,6 +123,12 @@ export class OasstApiClient {
...content,
});
}
//Fetch valid labels. This is called every task. though the call may be redundant
//keeping this for future where the valid labels may change per task
async fetch_valid_text(): Promise<void> {
return this.get(`/api/v1/text_labels/valid_labels`);
}
}
export const oasstApiClient =