Skip to content

Commit

Permalink
further design polish #209
Browse files Browse the repository at this point in the history
  • Loading branch information
chrabyrd committed Feb 22, 2025
1 parent aeba0fe commit 4b0c413
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,7 @@ async function deleteSectionValue(tileId: string) {
await deleteLingoTile(props.graphSlug, props.nodeAlias, tileId);
forceSectionRefresh!(props.componentName);
} catch (error) {
// toast.add({
// severity: ERROR,
// summary: $gettext("Error"),
// detail:
// error instanceof Error
// ? error.message
// : $gettext("Could not delete selected label"),
// });
console.error(error);
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useGettext } from "vue3-gettext";
import { useRoute } from "vue-router";
import { useToast } from "primevue/usetoast";
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, NEW, VIEW } from "@/arches_lingo/constants.ts";
import { EDIT, VIEW } from "@/arches_lingo/constants.ts";
import { fetchLingoResourcePartial } from "@/arches_lingo/api.ts";
Expand All @@ -26,19 +22,18 @@ defineOptions({
const props = defineProps<{
mode: DataComponentMode;
tileId?: string | null;
graphSlug: string;
nodeGroupAlias: string;
resourceInstanceId: string | undefined;
}>();
const { $gettext } = useGettext();
const toast = useToast();
const route = useRoute();
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.resourceInstanceId) return;
if (props.mode === VIEW || !shouldCreateNewTile) {
const sectionValue = await getSectionValue();
Expand All @@ -58,19 +53,12 @@ async function getSectionValue() {
try {
return await fetchLingoResourcePartial(
"scheme",
route.params.id as string,
"appellative_status",
props.graphSlug,
props.resourceInstanceId,
props.nodeGroupAlias,
);
} catch (error) {
toast.add({
severity: ERROR,
summary: $gettext("Error"),
detail:
error instanceof Error
? error.message
: $gettext("Could not fetch the labels for the resource"),
});
console.error(error);
} finally {
isLoading.value = false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,224 +1,99 @@
<script setup lang="ts">
import { computed, ref, useTemplateRef } from "vue";
import { useGettext } from "vue3-gettext";
import { useRoute, useRouter } from "vue-router";
import { Form } from "@primevue/forms";
import Button from "primevue/button";
import NonLocalizedStringWidget from "@/arches_component_lab/widgets/NonLocalizedStringWidget/NonLocalizedStringWidget.vue";
import ReferenceSelectWidget from "@/arches_controlled_lists/widgets/ReferenceSelectWidget/ReferenceSelectWidget.vue";
import ResourceInstanceMultiSelectWidget from "@/arches_component_lab/widgets/ResourceInstanceMultiSelectWidget/ResourceInstanceMultiSelectWidget.vue";
import DateWidget from "@/arches_component_lab/widgets/DateWidget/DateWidget.vue";
import { createScheme, upsertLingoTile } from "@/arches_lingo/api.ts";
import { EDIT, NEW } from "@/arches_lingo/constants.ts";
import { EDIT } 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<{
schemeLabel: AppellativeStatus | undefined;
}>();
// this is to compensate for the lack of a Form type in the primevue/forms module
interface FormInstance {
fields: Record<
string,
{
options: { name: string };
states: { value: unknown };
}
>;
}
const formRef = useTemplateRef<FormInstance>("formRef");
const formKey = ref(0);
import { inject } from "vue";
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;
return Object.values(formRef.value.fields).some((fieldData) => {
return !checkDeepEquality(
props.schemeLabel![
fieldData.options.name as keyof AppellativeStatus
],
fieldData.states.value,
);
});
});
async function save(e: FormSubmitEvent) {
try {
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;
},
{},
),
},
],
});
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);
}
}
function reset() {
formKey.value += 1;
}
</script>

<template>
<Form
ref="formRef"
:key="formKey"
@submit="save"
@reset="reset"
>
<NonLocalizedStringWidget
graph-slug="scheme"
node-alias="appellative_status_ascribed_name_content"
:initial-value="
props.schemeLabel?.appellative_status_ascribed_name_content
"
:mode="EDIT"
/>
<DateWidget
graph-slug="scheme"
node-alias="appellative_status_timespan_begin_of_the_begin"
:initial-value="
props.schemeLabel
?.appellative_status_timespan_begin_of_the_begin
"
:mode="EDIT"
/>
<DateWidget
graph-slug="scheme"
node-alias="appellative_status_timespan_end_of_the_end"
:initial-value="
props.schemeLabel?.appellative_status_timespan_end_of_the_end
"
:mode="EDIT"
/>

<ResourceInstanceMultiSelectWidget
graph-slug="scheme"
node-alias="appellative_status_data_assignment_actor"
:initial-value="
props.schemeLabel?.appellative_status_data_assignment_actor
"
:mode="EDIT"
/>
<ResourceInstanceMultiSelectWidget
graph-slug="scheme"
node-alias="appellative_status_data_assignment_object_used"
:initial-value="
props.schemeLabel
?.appellative_status_data_assignment_object_used
"
:mode="EDIT"
/>

<ReferenceSelectWidget
graph-slug="scheme"
node-alias="appellative_status_ascribed_name_language"
:initial-value="
props.schemeLabel?.appellative_status_ascribed_name_language
"
:mode="EDIT"
/>
<ReferenceSelectWidget
graph-slug="scheme"
node-alias="appellative_status_ascribed_relation"
:initial-value="
props.schemeLabel?.appellative_status_ascribed_relation
"
:mode="EDIT"
/>
<ReferenceSelectWidget
graph-slug="scheme"
node-alias="appellative_status_status"
:initial-value="props.schemeLabel?.appellative_status_status"
:mode="EDIT"
/>
<ReferenceSelectWidget
graph-slug="scheme"
node-alias="appellative_status_status_metatype"
:initial-value="
props.schemeLabel?.appellative_status_status_metatype
"
:mode="EDIT"
/>
<ReferenceSelectWidget
graph-slug="scheme"
node-alias="appellative_status_data_assignment_type"
:initial-value="
props.schemeLabel?.appellative_status_data_assignment_type
"
:mode="EDIT"
/>

<div style="display: flex">
<Button
:label="$gettext('Update')"
type="submit"
/>
<Button
:label="$gettext('Reset')"
type="reset"
/>
</div>
</Form>
<h4>{{ $gettext("Scheme Label") }}</h4>

<NonLocalizedStringWidget
graph-slug="scheme"
node-alias="appellative_status_ascribed_name_content"
:initial-value="
props.schemeLabel?.appellative_status_ascribed_name_content
"
:mode="EDIT"
/>
<DateWidget
graph-slug="scheme"
node-alias="appellative_status_timespan_begin_of_the_begin"
:initial-value="
props.schemeLabel?.appellative_status_timespan_begin_of_the_begin
"
:mode="EDIT"
/>
<DateWidget
graph-slug="scheme"
node-alias="appellative_status_timespan_end_of_the_end"
:initial-value="
props.schemeLabel?.appellative_status_timespan_end_of_the_end
"
:mode="EDIT"
/>

<ResourceInstanceMultiSelectWidget
graph-slug="scheme"
node-alias="appellative_status_data_assignment_actor"
:initial-value="
props.schemeLabel?.appellative_status_data_assignment_actor
"
:mode="EDIT"
/>
<ResourceInstanceMultiSelectWidget
graph-slug="scheme"
node-alias="appellative_status_data_assignment_object_used"
:initial-value="
props.schemeLabel?.appellative_status_data_assignment_object_used
"
:mode="EDIT"
/>

<ReferenceSelectWidget
graph-slug="scheme"
node-alias="appellative_status_ascribed_name_language"
:initial-value="
props.schemeLabel?.appellative_status_ascribed_name_language
"
:mode="EDIT"
/>
<ReferenceSelectWidget
graph-slug="scheme"
node-alias="appellative_status_ascribed_relation"
:initial-value="props.schemeLabel?.appellative_status_ascribed_relation"
:mode="EDIT"
/>
<ReferenceSelectWidget
graph-slug="scheme"
node-alias="appellative_status_status"
:initial-value="props.schemeLabel?.appellative_status_status"
:mode="EDIT"
/>
<ReferenceSelectWidget
graph-slug="scheme"
node-alias="appellative_status_status_metatype"
:initial-value="props.schemeLabel?.appellative_status_status_metatype"
:mode="EDIT"
/>
<ReferenceSelectWidget
graph-slug="scheme"
node-alias="appellative_status_data_assignment_type"
:initial-value="
props.schemeLabel?.appellative_status_data_assignment_type
"
:mode="EDIT"
/>
</template>
Loading

0 comments on commit 4b0c413

Please sign in to comment.