Skip to content

Commit

Permalink
Remove tileId param from upsertLingoTile #218
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Feb 20, 2025
1 parent 02e1f9d commit 96c19a3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
11 changes: 5 additions & 6 deletions arches_lingo/src/arches_lingo/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import arches from "arches";
import Cookies from "js-cookie";

import type { SchemeInstance, SchemeTile } from "@/arches_lingo/types";
import type { SchemeInstance, TileData } from "@/arches_lingo/types";

function getToken() {
const token = Cookies.get("csrftoken");
Expand Down Expand Up @@ -99,14 +99,13 @@ export const updateLingoResource = async (
export const upsertLingoTile = async (
graphSlug: string,
nodegroupAlias: string,
tileData: SchemeTile, // TODO: generalize type
tileId: string | undefined,
tileData: TileData,
) => {
const url = tileId
const url = tileData.tileid
? arches.urls.api_lingo_tile
: arches.urls.api_lingo_tiles;
const response = await fetch(url(graphSlug, nodegroupAlias, tileId), {
method: tileId ? "PATCH" : "POST",
const response = await fetch(url(graphSlug, nodegroupAlias, tileData.tileid), {
method: tileData.tileid ? "PATCH" : "POST",
headers: {
"X-CSRFTOKEN": getToken(),
"Content-Type": "application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ async function save() {
"appellative_status",
{
resourceinstance: route.params.id as string,
...formValue.value,
...formValue.value, // includes tileid
},
formValue.value.tileid,
);
newTileId = updated.tileid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ async function save() {
"statement",
{
resourceinstance: route.params.id as string,
...formValue.value,
...formValue.value, // includes tileid
},
formValue.value.tileid,
);
newTileId = updated.tileid;
}
Expand Down
30 changes: 9 additions & 21 deletions arches_lingo/src/arches_lingo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ export interface MetaStringText {
noRecords: string;
}

export interface AppellativeStatus {
export interface TileData {
resourceinstance?: string;
tileid?: string;
}

export interface AppellativeStatus extends TileData {
appellative_status_ascribed_name_content: string;
appellative_status_ascribed_name_language?: ControlledListItem[];
appellative_status_ascribed_relation?: ControlledListItem[];
Expand All @@ -129,9 +132,7 @@ export interface AppellativeStatus {
appellative_status_timespan_end_of_the_end: string;
}

export interface SchemeStatement {
resourceinstance?: string;
tileid?: string;
export interface SchemeStatement extends TileData {
statement_content_n1: string;
statement_language_n1?: ControlledListItem[];
statement_type_n1?: ControlledListItem[];
Expand All @@ -143,42 +144,29 @@ export interface SchemeStatement {
statement_data_assignment_timespan_end_of_the_end: string;
}

export interface SchemeRights {
tileid?: string;
export interface SchemeRights extends TileData {
right_holder?: ResourceInstanceReference[];
right_type?: ControlledListItem[];
right_statement?: SchemeRightStatement;
}

export interface SchemeRightStatement {
tileid?: string;
export interface SchemeRightStatement extends TileData {
right_statement_content?: string;
right_statement_label?: string;
right_statement_language?: ControlledListItem[];
right_statement_type?: ControlledListItem[];
right_statement_type_metatype?: ControlledListItem[];
}

export interface SchemeNamespace {
resourceinstance?: string;
tileid?: string;
export interface SchemeNamespace extends TileData {
namespace_name: string;
namespace_type: ControlledListItem[];
}

export interface SchemeCreation {
resourceinstance?: string;
tileid?: string;
export interface SchemeCreation extends TileData {
creation_sources: ResourceInstanceReference[];
}

export type SchemeTile =
| AppellativeStatus
| SchemeStatement
| SchemeNamespace
| SchemeCreation
| SchemeRights;

export interface SchemeInstance {
namespace?: SchemeNamespace;
creation?: SchemeCreation;
Expand Down

0 comments on commit 96c19a3

Please sign in to comment.