Skip to content

Commit

Permalink
nit re #10541, clarify label/new label types
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Apr 25, 2024
1 parent 7255261 commit 64cf2c6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
19 changes: 12 additions & 7 deletions arches/app/src/components/ControlledListManager/AddLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
ControlledListItem,
Label,
LanguageMap,
NewLabel,
ValueType,
} from "@/types/ControlledListManager";
Expand All @@ -24,6 +25,16 @@ const visible = ref(false);
const { $gettext } = useGettext();
const slateBlue = "#2d3c4b"; // todo: import from theme somewhere
const newLabel: NewLabel = computed(() => {
return {
id: null,
valuetype: props.type,
language: arches.activeLanguage,
value: '',
item_id: props.item.id,
};
});
const buttonLabel = computed(() => {
switch (props.type) {
case "prefLabel":
Expand Down Expand Up @@ -51,15 +62,9 @@ const buttonLabel = computed(() => {
</button>
<EditLabel
v-model="visible"
:item
:header="buttonLabel"
:language-map
:label="{
id: null,
valuetype: props.type,
language: arches.activeLanguage,
value: '',
}"
:label="newLabel"
:on-insert
/>
</template>
Expand Down
15 changes: 7 additions & 8 deletions arches/app/src/components/ControlledListManager/EditLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ import { useToast } from "primevue/usetoast";
import { upsertLabel } from "@/components/ControlledListManager/api.ts";
import type {
ControlledListItem,
Label,
LanguageMap,
NewLabel,
} from "@/types/ControlledListManager";
const props: {
item: ControlledListItem;
header: string;
label: Label | NewLabel;
languageMap: LanguageMap;
label: Label;
// updates don't need an insert callback
onInsert: null | ((label: Label) => Promise<Label>);
} = defineProps(["item", "header", "languageMap", "label", "onInsert"]);
} = defineProps(["header", "label", "languageMap", "onInsert"]);
const value = ref(props.label.value);
const language = ref(props.label.language);
Expand All @@ -51,20 +50,20 @@ const staticItemLabel = $gettext("Item Label");
const staticLanguageLabel = $gettext("Language");
const onSave = async () => {
const upsertedLabel = await upsertLabel(
const upsertedLabel: Label = await upsertLabel(
{
id: props.label.id,
value: value.value,
language: language.value,
valuetype: props.label.valuetype,
itemId: props.item.id,
item_id: props.label.item_id,
},
toast,
$gettext,
);
if (upsertedLabel) {
if (props.onInsert !== null) {
if (props.onInsert) {
props.onInsert(upsertedLabel);
value.value = "";
} else {
Expand Down Expand Up @@ -126,7 +125,7 @@ const onSave = async () => {
<Button
type="button"
:label="arches.translations.cancelEdit"
@click="visible = false"
@click="visible = false; value = props.label.value"
/>
</div>
</Dialog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const onDelete = async (label: Label) => {
class="label-box"
>
<LabelRow
:item
:label
:language-map
:on-delete="() => { onDelete(label) }"
Expand Down
6 changes: 2 additions & 4 deletions arches/app/src/components/ControlledListManager/LabelRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import { useGettext } from "vue3-gettext";
import EditLabel from "@/components/ControlledListManager/EditLabel.vue";
import type { ControlledListItem, Label, LanguageMap } from "@/types/ControlledListManager";
import type { Label, LanguageMap } from "@/types/ControlledListManager";
const props: {
item: ControlledListItem,
label: Label,
languageMap: LanguageMap,
onDelete: (labelId: Label) => Promise<void>,
} = defineProps(["item", "label", "languageMap", "onDelete"]);
} = defineProps(["label", "languageMap", "onDelete"]);
const visible = ref(false);
Expand Down Expand Up @@ -46,7 +45,6 @@ const header = computed(() => {
</div>
<EditLabel
v-model="visible"
:item
:header
:language-map
:label
Expand Down
5 changes: 3 additions & 2 deletions arches/app/src/types/controlledListManager.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
export type Label = {
id: string | null,
id: string,
valuetype: string,
language: string,
value: string,
item_id: string,
}

export type NewLabel = {
id: null,
valuetype: string,
language: string,
value: string,
itemId: string,
item_id: string,
}

export type ValueType = "prefLabel" | "altLabel";
Expand Down
4 changes: 3 additions & 1 deletion arches/app/views/controlled_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def serialize(obj, depth_map=None):
"valuetype": obj.value_type_id,
"language": obj.language_id,
"value": obj.value,
"item_id": obj.item_id,
}


Expand Down Expand Up @@ -90,6 +91,7 @@ def handle_items(itemDicts):
for label in labels:
label["language_id"] = label.pop("language")
label["value_type_id"] = label.pop("valuetype")
label.pop("item_id") # trust the item, not the label
labels_to_save.append(
ControlledListItemLabel(item_id=item_to_save.id, **label)
)
Expand Down Expand Up @@ -268,7 +270,7 @@ def add_new_label(self, request):
data = JSONDeserializer().deserialize(request.body)

label = ControlledListItemLabel(
item_id=data["itemId"],
item_id=data["item_id"],
value_type_id=data["valuetype"],
language=Language.objects.get(code=data["language"]),
value=data["value"],
Expand Down

0 comments on commit 64cf2c6

Please sign in to comment.