Bug 38201: Load Cypress components - componentPath

(cherry picked from commit 0fc12a0b7875b4bf0b77c200946516c1bd2092e0)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2025-09-15 12:27:32 +02:00 committed by Lucas Gass
parent 70b7bb0f33
commit 8724b98c51
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
11 changed files with 53 additions and 22 deletions

View File

@ -298,7 +298,8 @@ export default {
name: "user_id",
type: "component",
label: $__("User"),
componentPath: "./PatronSearch.vue",
componentPath:
"@koha-vue/components/PatronSearch.vue",
required: true,
indexRequired: true,
componentProps: {
@ -398,7 +399,8 @@ export default {
name: "license_id",
type: "component",
label: $__("License"),
componentPath: "./InfiniteScrollSelect.vue",
componentPath:
"@koha-vue/components/InfiniteScrollSelect.vue",
required: true,
indexRequired: true,
componentProps: {
@ -468,7 +470,7 @@ export default {
hidden: agreement =>
!!agreement.agreement_relationships?.length,
componentPath:
"./ERM/AgreementRelationshipsDisplay.vue",
"@koha-vue/components/ERM/AgreementRelationshipsDisplay.vue",
componentProps: {
agreement: {
type: "resource",
@ -544,7 +546,8 @@ export default {
type: "component",
hidden: agreement =>
!!agreement.agreement_packages?.length,
componentPath: "./ERM/AgreementPackagesDisplay.vue",
componentPath:
"@koha-vue/components/ERM/AgreementPackagesDisplay.vue",
componentProps: {
agreement: {
type: "resource",
@ -562,7 +565,8 @@ export default {
type: "component",
label: $__("Agreement users"),
hidden: agreement => !!agreement.documents?.length,
componentPath: "./DocumentDisplay.vue",
componentPath:
"@koha-vue/components/DocumentDisplay.vue",
componentProps: {
resource: {
type: "resource",
@ -596,7 +600,8 @@ export default {
{
name: "document",
type: "component",
componentPath: "./DocumentSelect.vue",
componentPath:
"@koha-vue/components/DocumentSelect.vue",
label: $__("File"),
componentProps: {
counter: {

View File

@ -276,7 +276,8 @@ export default {
type: "component",
name: $__("Titles"),
hidden: erm_package => erm_package,
componentPath: "./RelationshipTableDisplay.vue",
componentPath:
"@koha-vue/components/RelationshipTableDisplay.vue",
componentProps: {
tableOptions: {
type: "object",

View File

@ -293,7 +293,8 @@ export default {
showElement: {
type: "component",
hidden: title => title.resources.length > 0,
componentPath: "./RelationshipTableDisplay.vue",
componentPath:
"@koha-vue/components/RelationshipTableDisplay.vue",
componentProps: {
tableOptions: {
type: "object",

View File

@ -171,7 +171,8 @@ export default {
name: "user_id",
type: "component",
label: $__("User"),
componentPath: "./PatronSearch.vue",
componentPath:
"@koha-vue/components/PatronSearch.vue",
required: true,
indexRequired: true,
componentProps: {
@ -211,7 +212,8 @@ export default {
showElement: {
type: "component",
hidden: license => !!license.documents?.length,
componentPath: "./DocumentDisplay.vue",
componentPath:
"@koha-vue/components/DocumentDisplay.vue",
componentProps: {
resource: {
type: "resource",
@ -245,7 +247,8 @@ export default {
{
name: "document",
type: "component",
componentPath: "./DocumentSelect.vue",
componentPath:
"@koha-vue/components/DocumentSelect.vue",
label: $__("File"),
componentProps: {
counter: {

View File

@ -205,6 +205,7 @@ import ToolTip from "./ToolTip.vue";
import InputRadio from "./Elements/InputRadio.vue";
import { useBaseElement } from "../composables/base-element.js";
import { computed, defineAsyncComponent, ref } from "vue";
import { loadComponent } from "@koha-vue/loaders/componentResolver";
export default {
props: {
@ -255,7 +256,7 @@ export default {
const importPath = baseElement.identifyAndImportComponent(
props.attr
);
return defineAsyncComponent(() => import(`${importPath}`));
return defineAsyncComponent(loadComponent(importPath));
});
const selectOptions = computed(() => {
if (props.attr.options) {

View File

@ -417,7 +417,8 @@ export default {
type: "component",
name: $__("Items"),
hidden: train => train.items.length,
componentPath: "./Preservation/TrainItemsTable.vue",
componentPath:
"@koha-vue/components/Preservation/TrainItemsTable.vue",
componentProps: {
train: {
type: "resource",

View File

@ -150,6 +150,8 @@ import AdditionalFieldsDisplay from "./AdditionalFieldsDisplay.vue";
import { useBaseElement } from "../composables/base-element.js";
import { computed, defineAsyncComponent } from "vue";
import { loadComponent } from "@koha-vue/loaders/componentResolver";
export default {
components: { LinkWrapper, AdditionalFieldsDisplay },
setup(props) {
@ -160,7 +162,7 @@ export default {
props.attr,
true
);
return defineAsyncComponent(() => import(`${importPath}`));
return defineAsyncComponent(loadComponent(importPath));
});
const attribute = computed(() => {
if (props.attr.showElement) {

View File

@ -407,7 +407,8 @@ export default {
},
{
type: "component",
componentPath: "./Vendors/VendorContacts.vue",
componentPath:
"@koha-vue/components/Vendors/VendorContacts.vue",
indexRequired: true,
componentProps: {
contact: {
@ -427,7 +428,8 @@ export default {
showElement: {
type: "component",
hidden: vendor => !!vendor.interfaces?.length,
componentPath: "./Vendors/VendorInterfaces.vue",
componentPath:
"@koha-vue/components/Vendors/VendorInterfaces.vue",
componentProps: {
vendor: {
type: "resource",
@ -840,7 +842,8 @@ export default {
type: "component",
name: $__("Contracts"),
hidden: vendor => vendor.contracts.length,
componentPath: "./RelationshipTableDisplay.vue",
componentPath:
"@koha-vue/components/RelationshipTableDisplay.vue",
componentProps: {
tableOptions: {
type: "object",
@ -949,7 +952,8 @@ export default {
type: "component",
name: $__("Subscription details"),
hidden: vendor => vendor.subscriptions_count,
componentPath: "./Vendors/VendorSubscriptions.vue",
componentPath:
"@koha-vue/components/Vendors/VendorSubscriptions.vue",
componentProps: {
vendor: {
type: "resource",

View File

@ -8,13 +8,13 @@ export function useBaseElement(instancedElement) {
*/
const identifyAndImportComponent = (attr, show = false) => {
if (attr.type === "date") {
attr.componentPath = "./FlatPickrWrapper.vue";
attr.componentPath = "@koha-vue/components/FlatPickrWrapper.vue";
}
if (attr.type === "vendor") {
attr.componentPath = "./FormSelectVendors.vue";
attr.componentPath = "@koha-vue/components/FormSelectVendors.vue";
}
if (attr.type === "relationshipWidget") {
attr.componentPath = "./RelationshipWidget.vue";
attr.componentPath = "@koha-vue/components/RelationshipWidget.vue";
}
const importPath = show
? attr.showElement?.componentPath

View File

@ -0,0 +1,13 @@
const businessContext = require.context("@koha-vue", true, /\.vue$/);
const cypressContext = require.context("@cypress", true, /\.vue$/);
export function loadComponent(path) {
if (path.startsWith("@koha-vue/")) {
return () => Promise.resolve(businessContext("." + path.slice(9)));
} else if (path.startsWith("@cypress/")) {
// FIXME should only be imported if we are not in production
return () => Promise.resolve(cypressContext("." + path.slice(8)));
} else {
return () => import(`${path}`);
}
}

View File

@ -227,7 +227,7 @@ describe("ShowElement", () => {
type: "component",
hidden: () => true,
componentPath:
"t/cypress/component/ShowElementComponentType.vue",
"@cypress/component/ShowElementComponentType.vue",
componentProps: {
testString: {
type: "string",