Skip to content

Commit

Permalink
Merge label finder implementations #92
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Oct 7, 2024
1 parent c9f1544 commit dc13ae8
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 122 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add concept hierarchy component [#18](https://github.com/archesproject/arches-lingo/issues/18)

### Fixed
- Merge language finder implementations [#92](https://github.com/archesproject/arches-lingo/issues/92)

### Deprecated

Expand Down
3 changes: 0 additions & 3 deletions arches_lingo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
Django settings for arches_lingo project.
"""

import json
import os
import sys
import arches
import inspect
import semantic_version
from datetime import datetime, timedelta
Expand Down
3 changes: 3 additions & 0 deletions arches_lingo/src/arches_lingo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
USER_KEY,
headerKey,
selectedLanguageKey,
systemLanguageKey,
} from "@/arches_lingo/constants.ts";
import { routeNames } from "@/arches_lingo/routes.ts";
Expand All @@ -33,6 +34,8 @@ provide(USER_KEY, { user, setUser });
const selectedLanguage: Ref<Language> = ref(ENGLISH);
provide(selectedLanguageKey, selectedLanguage);
const systemLanguage = ENGLISH; // TODO: get from settings
provide(systemLanguageKey, systemLanguage);
const router = useRouter();
const route = useRoute();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script setup lang="ts">
import { getItemLabel } from "@/arches_vue_utils/utils.ts";
import { ENGLISH } from "@/arches_lingo/constants.ts";
import type { SearchResultItem } from "@/arches_lingo/types.ts";
import { getItemLabel } from "@/arches_lingo/utils.ts";
defineProps({
searchResult: {
Expand All @@ -11,12 +13,17 @@ defineProps({
const getParentLabels = (
item: SearchResultItem,
preferredLanguage: string,
preferredLanguageCode: string,
systemLanguageCode: string,
): string => {
const arrowIcon = "";
return item.parents.reduce((acc, parent, index) => {
const label = getItemLabel(parent, preferredLanguage);
const label = getItemLabel(
parent,
preferredLanguageCode,
systemLanguageCode,
).value;
if (label) {
return acc + (index > 0 ? arrowIcon : "") + label;
}
Expand All @@ -33,11 +40,18 @@ const getParentLabels = (
<i class="pi pi-paperclip" />

<div style="margin: 0 0.5rem">
{{ getItemLabel(searchResult.option, "en-US") }}
{{
getItemLabel(searchResult.option, ENGLISH.code, ENGLISH.code)
.value
}}
</div>

<div class="search-result-hierarchy">
[ {{ getParentLabels(searchResult.option, "en-US") }} ]
[
{{
getParentLabels(searchResult.option, ENGLISH.code, ENGLISH.code)
}}
]
</div>
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { computed } from "vue";
import { dataIsScheme } from "@/arches_lingo/utils.ts";
import type { Labellable } from "@/arches_lingo/types";
import type { Concept, Scheme } from "@/arches_lingo/types";
const props = defineProps<{ labelled: Labellable }>();
const props = defineProps<{ labelled: Concept | Scheme }>();
const color = computed(() => {
if (dataIsScheme(props.labelled)) {
Expand Down
12 changes: 10 additions & 2 deletions arches_lingo/src/arches_lingo/components/tree/ConceptTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useGettext } from "vue3-gettext";
import { useToast } from "primevue/usetoast";
import Tree from "primevue/tree";
import { getItemLabel } from "@/arches_vue_utils/utils.ts";
import PresentationControls from "@/arches_references/components/tree/PresentationControls.vue";
import {
DEFAULT_ERROR_TOAST_LIFE,
Expand All @@ -16,8 +17,9 @@ import { fetchConcepts } from "@/arches_lingo/api.ts";
import {
displayedRowKey,
selectedLanguageKey,
systemLanguageKey,
} from "@/arches_lingo/constants.ts";
import { bestLabel, treeFromSchemes } from "@/arches_lingo/utils.ts";
import { treeFromSchemes } from "@/arches_lingo/utils.ts";
import { routeNames } from "@/arches_lingo/routes.ts";
import LetterCircle from "@/arches_lingo/components/misc/LetterCircle.vue";
import TreeRow from "@/arches_lingo/components/tree/TreeRow.vue";
Expand Down Expand Up @@ -51,6 +53,7 @@ const expandedKeys: Ref<TreeExpandedKeys> = ref({});
const filterValue = ref("");
const treeDOMRef: Ref<ComponentPublicInstance | null> = ref(null);
const selectedLanguage = inject(selectedLanguageKey) as Ref<Language>;
const systemLanguage = inject(systemLanguageKey) as Language;
const nextFilterChangeNeedsExpandAll = ref(false);
const expandedKeysSnapshotBeforeSearch = ref<TreeExpandedKeys>({});
const rerenderTree = ref(0);
Expand All @@ -62,6 +65,7 @@ const tree = computed(() =>
treeFromSchemes(
schemes.value,
selectedLanguage.value,
systemLanguage,
iconLabels,
focusedNode.value,
),
Expand Down Expand Up @@ -182,7 +186,11 @@ const snoopOnFilterValue = () => {
};
function lazyLabelLookup(node: TreeNode) {
return bestLabel(node.data, selectedLanguage.value.code).value;
return getItemLabel(
node.data,
selectedLanguage.value.code,
systemLanguage.code,
).value;
}
const updateSelectedAndExpanded = (node: TreeNode) => {
Expand Down
18 changes: 13 additions & 5 deletions arches_lingo/src/arches_lingo/components/tree/TreeRow.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
<script setup lang="ts">
import { inject } from "vue";
import { selectedLanguageKey } from "@/arches_references/constants.ts";
import { bestLabel } from "@/arches_lingo/utils.ts";
import { getItemLabel } from "@/arches_vue_utils/utils.ts";
import {
selectedLanguageKey,
systemLanguageKey,
} from "@/arches_lingo/constants.ts";
import type { Language } from "@/arches_vue_utils/types";
import type { Ref } from "vue";
import type { TreeNode } from "primevue/treenode";
import type { Labellable } from "@/arches_lingo/types";
import type { Concept, Scheme } from "@/arches_lingo/types";
const { node, focusLabel, unfocusLabel } = defineProps<{
node: TreeNode;
focusLabel: string;
unfocusLabel: string;
}>();
const selectedLanguage = inject(selectedLanguageKey) as Ref<Language>;
const systemLanguage = inject(systemLanguageKey) as Language;
const filterValue = defineModel<string>("filterValue");
const focusedNode = defineModel<TreeNode | null>("focusedNode");
const rowLabel = (data: Labellable) => {
const rowLabel = (data: Concept | Scheme) => {
if (!data) {
return "";
}
const unstyledLabel = bestLabel(data, selectedLanguage?.value?.code).value;
const unstyledLabel = getItemLabel(
data,
selectedLanguage?.value.code,
systemLanguage.code,
).value;
if (!filterValue.value) {
return unstyledLabel;
}
Expand Down
1 change: 1 addition & 0 deletions arches_lingo/src/arches_lingo/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const USER_KEY = Symbol() as InjectionKey<UserRefAndSetter>;
export const displayedRowKey = Symbol() as InjectionKey<Ref<Concept | null>>;
export const headerKey = Symbol() as InjectionKey<HeaderRefAndSetter>;
export const selectedLanguageKey = Symbol() as InjectionKey<Ref<Language>>;
export const systemLanguageKey = Symbol() as InjectionKey<Language>; // not reactive

export const ENGLISH = {
code: "en",
Expand Down
48 changes: 24 additions & 24 deletions arches_lingo/src/arches_lingo/fixtures/test_scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,49 @@
"id": "c9c8548f-6ecc-40d5-ad67-42e9a7e7242e",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Test Scheme",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"top_concepts": [
{
"id": "943a70f1-236e-4c28-b5ab-69a4b83a63e9",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 1",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": [
{
"id": "8f7a7ca8-8548-464b-8fb7-01b3cec6487d",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 3",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": [
{
"id": "15bb81ff-194e-4fea-b495-b222f431caee",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 4",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": [
{
"id": "edf8dd01-a3fe-445e-a330-dc3bd04c7302",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 5",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": []
Expand All @@ -59,39 +59,39 @@
"id": "53ee9df5-3fa8-4686-a25b-ea8034cc4a5c",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 2",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": [
{
"id": "8f7a7ca8-8548-464b-8fb7-01b3cec6487d",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 3",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": [
{
"id": "15bb81ff-194e-4fea-b495-b222f431caee",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 4",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": [
{
"id": "edf8dd01-a3fe-445e-a330-dc3bd04c7302",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 5",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": []
Expand All @@ -106,19 +106,19 @@
"id": "15bb81ff-194e-4fea-b495-b222f431caee",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 4",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": [
{
"id": "edf8dd01-a3fe-445e-a330-dc3bd04c7302",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 5",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": []
Expand All @@ -129,9 +129,9 @@
"id": "edf8dd01-a3fe-445e-a330-dc3bd04c7302",
"labels": [
{
"language": "en",
"language_id": "en",
"value": "Concept 5",
"valuetype": "prefLabel"
"valuetype_id": "prefLabel"
}
],
"narrower": []
Expand Down
Loading

0 comments on commit dc13ae8

Please sign in to comment.