Skip to content

Commit

Permalink
nit #209
Browse files Browse the repository at this point in the history
  • Loading branch information
chrabyrd committed Feb 21, 2025
1 parent cd4eebb commit aeba0fe
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ProgressSpinner from "primevue/progressspinner";
import SchemeLabelEditor from "@/arches_lingo/components/scheme/SchemeLabel/components/SchemeLabelEditor.vue";
import SchemeLabelViewer from "@/arches_lingo/components/scheme/SchemeLabel/components/SchemeLabelViewer.vue";
import { EDIT, ERROR, VIEW } from "@/arches_lingo/constants.ts";
import { EDIT, ERROR, NEW, VIEW } from "@/arches_lingo/constants.ts";
import { fetchLingoResourcePartial } from "@/arches_lingo/api.ts";
Expand All @@ -32,29 +32,30 @@ const { $gettext } = useGettext();
const toast = useToast();
const route = useRoute();
const isLoading = ref(true);
const isLoading = ref(false);
const schemeLabels = ref<AppellativeStatus[]>([]);
const shouldCreateNewTile = Boolean(props.mode === EDIT && !props.tileId);
onMounted(async () => {
if (route.params.id === NEW) return;
if (props.mode === VIEW || !shouldCreateNewTile) {
const sectionValue = await getSectionValue();
if (props.tileId) {
schemeLabels.value = sectionValue.appellative_status.filter(
(appellativeStatus: AppellativeStatus) =>
appellativeStatus.tileid === props.tileId,
(status: AppellativeStatus) => status.tileid === props.tileId,
);
} else {
schemeLabels.value = sectionValue.appellative_status;
}
}
isLoading.value = false;
});
async function getSectionValue() {
isLoading.value = true;
try {
return await fetchLingoResourcePartial(
"scheme",
Expand All @@ -70,6 +71,8 @@ async function getSectionValue() {
? error.message
: $gettext("Could not fetch the labels for the resource"),
});
} finally {
isLoading.value = false;
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { computed, ref, useTemplateRef } from "vue";
import { useGettext } from "vue3-gettext";
import { useRoute } from "vue-router";
import { useRoute, useRouter } from "vue-router";
import { Form } from "@primevue/forms";
import Button from "primevue/button";
Expand All @@ -12,16 +12,17 @@ import ReferenceSelectWidget from "@/arches_controlled_lists/widgets/ReferenceSe
import ResourceInstanceMultiSelectWidget from "@/arches_component_lab/widgets/ResourceInstanceMultiSelectWidget/ResourceInstanceMultiSelectWidget.vue";
import DateWidget from "@/arches_component_lab/widgets/DateWidget/DateWidget.vue";
import { upsertLingoTile } from "@/arches_lingo/api.ts";
import { createScheme, upsertLingoTile } from "@/arches_lingo/api.ts";
import { EDIT } from "@/arches_lingo/constants.ts";
import { EDIT, NEW } from "@/arches_lingo/constants.ts";
import { checkDeepEquality } from "@/arches_lingo/utils.ts";
import type { FormSubmitEvent } from "@primevue/forms";
import type { AppellativeStatus } from "@/arches_lingo/types.ts";
const route = useRoute();
const router = useRouter();
const { $gettext } = useGettext();
const props = defineProps<{
Expand All @@ -47,6 +48,9 @@ const forceSectionRefresh = inject<(componentName: string) => void>(
"forceSectionRefresh",
);
const openEditor =
inject<(componentName: string, tileid: string) => void>("openEditor");
const isFormDirty = computed(() => {
if (!formRef.value) return false;
if (!props.schemeLabel) return false;
Expand All @@ -63,24 +67,49 @@ const isFormDirty = computed(() => {
async function save(e: FormSubmitEvent) {
try {
await upsertLingoTile(
"scheme",
"appellative_status",
{
resourceinstance: route.params.id as string,
...Object.entries(e.states).reduce(
(acc, [key, state]) => {
acc[key] = state.value;
return acc;
if (route.params.id === NEW) {
const updated = await createScheme({
appellative_status: [
{
...Object.entries(e.states).reduce(
(acc, [key, state]) => {
acc[key] = state.value;
return acc;
},
{},
),
},
{} as Record<string, unknown>,
),
tileid: props.schemeLabel?.tileid,
},
props.schemeLabel?.tileid,
);
forceSectionRefresh!("SchemeLabel");
],
});
await router.push({
name: "scheme",
params: { id: updated.resourceinstanceid },
});
forceSectionRefresh!("SchemeLabel");
// console.log(updated); // UPDATED DOES NOT RETURN A TILEID!
// openEditor!("SchemeLabel", updated.appellative_status[0].tileid);
} else {
await upsertLingoTile(
"scheme",
"appellative_status",
{
resourceinstance: route.params.id as string,
...Object.entries(e.states).reduce(
(acc, [key, state]) => {
acc[key] = state.value;
return acc;
},
{} as Record<string, unknown>,
),
tileid: props.schemeLabel?.tileid,
},
props.schemeLabel?.tileid,
);
forceSectionRefresh!("SchemeLabel");
}
} catch (error) {
console.error(error);
}
Expand Down

0 comments on commit aeba0fe

Please sign in to comment.