Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement views for expression metadata #975

Merged
merged 22 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
462799c
WIP(expression-metadata): Implement views for expression metadata
hamo225 Feb 4, 2025
91b9698
Updated API docs
VictorDelCampo Feb 5, 2025
98f93c2
refactor(routes): update route structure and eli handling
hamo225 Feb 6, 2025
c9c40ed
refactor(routes): update expression views
hamo225 Feb 6, 2025
f016798
fix: fix routing for the tree nodes
hamo225 Feb 7, 2025
3769cb3
Backend big refactor done (TOC endpoint missing)
VictorDelCampo Feb 9, 2025
3d0e194
Fix java docs
VictorDelCampo Feb 9, 2025
a6dc967
refactor(tree): remove unused expressionEli from route params
hamo225 Feb 9, 2025
1830d57
test(proprietaryService): update tests to remove atDate dependency
hamo225 Feb 9, 2025
0ca85e3
fix(tree): replace <span> with <button> for improved accessibility an…
hamo225 Feb 10, 2025
a4a28fd
test(e2e): update tests to reflect removal of atDate parameter
hamo225 Feb 10, 2025
9a2be69
TOC endpoint with expression eli
VictorDelCampo Feb 10, 2025
552c41d
feat: add service function for getting table of contents
hamo225 Feb 10, 2025
08c1535
feat(tests): add unit test for useGetNormTableOfContents service func…
hamo225 Feb 11, 2025
45bfb10
feat: Connect new TOC endpoint
hamo225 Feb 11, 2025
c96ac13
fix: align TreeNode type with PrimeVue definition
hamo225 Feb 11, 2025
b5fe44a
Comment back in playright projects
hamo225 Feb 11, 2025
29dccee
fix(tree): preserve selection and expand parents on refresh
hamo225 Feb 11, 2025
604bc4a
fix(tree): fix sonarcube error
hamo225 Feb 11, 2025
aa1cedb
feat(toc): persist selection and expansion on reload
hamo225 Feb 11, 2025
b9e4fd3
fix(e2e): skip failing e2e test to be removed later
hamo225 Feb 12, 2025
b8c70ec
chore: removes old amending law metadata editor views and e2e tests
hamo225 Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(routes): update expression views
- use `createEliPathParameter()` in route
- refactored metadata-editor
- Renamed `expressionEli` to `dokumentExpressionEli` for consistency.
- Removed `affectedDocumentEli` as a separate variable.
-Refactor proprietary metadata fetching

RISDEV-6266.
  • Loading branch information
hamo225 committed Feb 12, 2025
commit c9c40ed8289267cd73afe03d1073fd16f282237c
2 changes: 1 addition & 1 deletion frontend/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const routes: readonly RouteRecordRaw[] = [
redirect: { name: "AmendingLaws" },
},
{
path: "/eli/:eli",
path: `/${createEliPathParameter()}`,
name: "ExpressionMetadataEditor",
component: () =>
import(
Expand Down
37 changes: 6 additions & 31 deletions frontend/src/services/proprietaryService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ElementProprietary, RahmenProprietary } from "@/types/proprietary"
import { UseFetchOptions, UseFetchReturn } from "@vueuse/core"
import dayjs from "dayjs"
import { MaybeRefOrGetter, computed, toValue } from "vue"
import { INVALID_URL, useApiFetch } from "./apiService"

Expand All @@ -27,34 +26,18 @@ export function useProprietaryService(
* accident.
*/
eid: MaybeRefOrGetter<string | undefined> | null

/**
* If set, returns the state of the metadata at that date. Otherwise the
* metadata of the current version will be returned.
*/
atDate: MaybeRefOrGetter<string | Date | undefined>
},
fetchOptions: UseFetchOptions = {},
): UseFetchReturn<RahmenProprietary | ElementProprietary> {
const dateAsString = computed(() => {
const atDateVal = toValue(options?.atDate)

if (!atDateVal) return undefined

return typeof atDateVal === "string"
? atDateVal
: dayjs(atDateVal).format("YYYY-MM-DD")
})

const url = computed(() => {
const eliVal = toValue(eli)
const eidVal = toValue(options.eid)

if (!eliVal || !dateAsString.value || (eidVal !== null && !eidVal)) {
if (!eliVal || (eidVal !== null && !eidVal)) {
return INVALID_URL
}

return `/norms/${eliVal}/proprietary/${eidVal ? eidVal + "/" : ""}${dateAsString.value}`
return `/norms/${eliVal}/proprietary${eidVal ? `/${eidVal}` : ""}`
})

return useApiFetch<RahmenProprietary>(url, fetchOptions)
Expand All @@ -65,18 +48,16 @@ export function useProprietaryService(
* configuration for getting JSON data of the frame ("Rahmen", i.e. whole norm).
*
* @param eli ELI of the norm
* @param options Optional additional filters and queries
* @param [fetchOptions={}] Optional configuration for fetch behavior
* @returns Reactive fetch wrapper
*/
export function useGetRahmenProprietary(
eli: Parameters<typeof useProprietaryService>["0"],
options: Omit<Parameters<typeof useProprietaryService>["1"], "eid">,
fetchOptions?: Parameters<typeof useProprietaryService>["2"],
): UseFetchReturn<RahmenProprietary> {
return useProprietaryService(
eli,
{ ...options, eid: null },
{ eid: null },
{ refetch: true, ...fetchOptions },
).json()
}
Expand All @@ -87,19 +68,17 @@ export function useGetRahmenProprietary(
*
* @param updateData The new proprietary data
* @param eli ELI of the norm
* @param options Optional additional filters and queries
* @param [fetchOptions={}] Optional configuration for fetch behavior
* @returns Reactive fetch wrapper
*/
export function usePutRahmenProprietary(
updateData: MaybeRefOrGetter<RahmenProprietary | null>,
eli: Parameters<typeof useProprietaryService>["0"],
options: Omit<Parameters<typeof useProprietaryService>["1"], "eid">,
fetchOptions?: Parameters<typeof useProprietaryService>["2"],
): UseFetchReturn<RahmenProprietary> {
return useProprietaryService(
eli,
{ ...options, eid: null },
{ eid: null },
{ immediate: false, ...fetchOptions },
)
.json()
Expand All @@ -112,19 +91,17 @@ export function usePutRahmenProprietary(
*
* @param eli ELI of the norm
* @param eid eId of the element
* @param options Optional additional filters and queries
* @param [fetchOptions={}] Optional configuration for fetch behavior
* @returns Reactive fetch wrapper
*/
export function useGetElementProprietary(
eli: Parameters<typeof useProprietaryService>["0"],
eid: Parameters<typeof useProprietaryService>["1"]["eid"],
options: Omit<Parameters<typeof useProprietaryService>["1"], "eid">,
fetchOptions?: Parameters<typeof useProprietaryService>["2"],
): UseFetchReturn<ElementProprietary> {
return useProprietaryService(
eli,
{ ...options, eid },
{ eid },
{ refetch: true, ...fetchOptions },
).json()
}
Expand All @@ -136,20 +113,18 @@ export function useGetElementProprietary(
* @param updateData The new proprietary data
* @param eli ELI of the norm
* @param eid eId of the element
* @param options Optional additional filters and queries
* @param [fetchOptions={}] Optional configuration for fetch behavior
* @returns Reactive fetch wrapper
*/
export function usePutElementProprietary(
updateData: MaybeRefOrGetter<ElementProprietary | null>,
eli: Parameters<typeof useProprietaryService>["0"],
eid: Parameters<typeof useProprietaryService>["1"]["eid"],
options: Omit<Parameters<typeof useProprietaryService>["1"], "eid">,
fetchOptions?: Parameters<typeof useProprietaryService>["2"],
): UseFetchReturn<ElementProprietary> {
return useProprietaryService(
eli,
{ ...options, eid },
{ eid },
{ immediate: false, ...fetchOptions },
)
.json()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import RisHeader from "@/components/controls/RisHeader.vue"
import RisLoadingSpinner from "@/components/controls/RisLoadingSpinner.vue"
import { useEliPathParameter } from "@/composables/useEliPathParameter"
import { useGetElements } from "@/services/elementService"
import { computed, ref } from "vue"
import { ComputedRef, computed, ref } from "vue"
import RisErrorCallout from "@/components/controls/RisErrorCallout.vue"
import Tree from "primevue/tree"

Expand All @@ -29,74 +29,47 @@ const {
])

const expandedKeys = ref<Record<string, boolean>>({})
if (!expandedKeys.value) {
expandedKeys.value = {}
}

const selectionKeys = ref<Record<string, boolean>>({})

const elementData = computed(
const elementLinks = computed(
() =>
elements.value ?? [
{ eid: "1", title: "Kapitel 1", type: "article" },
{ eid: "2", title: "Kapitel 2", type: "book" },
{ eid: "3", title: "Annex 1", type: "annex" },
{ eid: "4", title: "Appendix A", type: "appendix" },
],
)

const elementLinks = computed(() => {
const items = elements.value ?? [
{ eid: "1", title: "Kapitel 1", type: "article" },
{ eid: "2", title: "Kapitel 2", type: "book" },
]

return items.map((el) => ({
eid: el.eid,
title: el.title,
type: el.type,
route: {
name:
el.type === "article" ||
el.type === "conclusions" ||
el.type === "preamble" ||
el.type === "preface"
elements.value?.map((el) => ({
eid: el.eid,
title: el.title,
type: el.type,
route: {
name: ["article", "conclusions", "preamble", "preface"].includes(
el.type,
)
? "ExpressionMetadataEditorElement"
: "ExpressionMetadataEditorOutlineElement",
params: {
eli: expressionEli.value,
eid: expressionEli.eid,
params: { eid: el.eid },
},
},
}))
})
})) ?? [],
)

const treeNodes = computed<TreeNode[]>(() => {
if (!elementLinks.value) return []
interface TreeNode {
key: string
label: string
route?: { name: string; params: { expressionEli: string; eid: string } }
children?: TreeNode[]
}

const treeNodes: ComputedRef<TreeNode[]> = computed(() => {
return elementLinks.value.map((el) => ({
key: el.eid,
label: el.title,
route: el.route
? {
name: el.route.name,
params: {
eli: eli.value ?? "default-eli", // Ensure eli is never undefined
expressionEli: expressionEli.value,
eid: el.eid,
},
}
: undefined,
children: el.children ?? [],
}))
})

interface TreeNode {
key: string
label: string
route?: { name: string; params: Record<string, string | number> }
secondaryLabel?: string
children?: TreeNode[]
}
</script>

<template>
Expand Down Expand Up @@ -134,7 +107,7 @@ interface TreeNode {
/>

<RisEmptyState
v-else-if="!elementData.length"
v-else-if="!elements || !elements.length"
text-content="Keine Artikel gefunden."
class="mx-16"
variant="simple"
Expand Down
Loading