diff --git a/src/components/renderer/form-empty-table.vue b/src/components/renderer/form-empty-table.vue index 1796536d..6d8db6b1 100644 --- a/src/components/renderer/form-empty-table.vue +++ b/src/components/renderer/form-empty-table.vue @@ -21,6 +21,9 @@ export default { }, methods: { openLink() { + if (!this.url) { + return; + } window.open(this.url, "_blank"); } } diff --git a/src/components/renderer/form-list-table.vue b/src/components/renderer/form-list-table.vue index b7a9a32c..1d940b20 100755 --- a/src/components/renderer/form-list-table.vue +++ b/src/components/renderer/form-list-table.vue @@ -184,7 +184,11 @@ export default { this.dataControl = data.dataControls; }, openExternalLink() { - window.open(this.dataControl.url, "_blank"); + const url = this.dataControl?.url; + if (!url) { + return; + } + window.open(url, "_blank"); }, handleDropdownSelection(listType, valueSelected) { const combinedFilter = []; diff --git a/src/components/renderer/form-requests.vue b/src/components/renderer/form-requests.vue index 8939f645..1f24c9e3 100755 --- a/src/components/renderer/form-requests.vue +++ b/src/components/renderer/form-requests.vue @@ -107,17 +107,42 @@ export default { }, computed: { noDataUrl() { - return `${window.ProcessMaker?.app?.url}/cases`; + return `${window.ProcessMaker?.app?.url || ""}/cases`; + }, + currentUser() { + return { + ...(window.Processmaker?.user || {}), + ...(window.ProcessMaker?.user || {}) + }; } }, mounted() { this.setupColumns(); - this.pmql = `requester = "${Processmaker.user.username}"`; - this.fetch(); + const username = this.currentUser.username; + if (username) { + this.pmql = `requester = "${username}"`; + this.fetch(); + } else { + this.showTable = false; + this.emitDataControls(0); + } this.$root.$on("dropdownSelectionRequest", this.fetchData); this.$root.$on("searchRequest", this.fetchSearch); }, methods: { + emitDataControls(count = 0) { + const dataControls = { + count: `${count}`, + showControl: true, + showAvatar: true, + variant: "primary", + textColor: "text-primary", + colorText: "color: #1572C2", + url: "/cases", + dropdownShow: "requests" + }; + this.$emit("requestsCount", { dataControls, tasksDropdown: [] }); + }, fetch() { Vue.nextTick(() => { let pmql = ""; @@ -169,21 +194,12 @@ export default { } this.tableData = response.data; this.countResponse = this.tableData.meta.total; - const dataControls = { - count: `${this.countResponse}`, - showControl: true, - showAvatar: true, - variant: "primary", - textColor: "text-primary", - colorText: "color: #1572C2", - url: "/cases", - dropdownShow: "requests" - }; - const tasksDropdown = []; - this.$emit("requestsCount", { dataControls, tasksDropdown }); + this.emitDataControls(this.countResponse); }) .catch(() => { this.tableData = []; + this.showTable = false; + this.emitDataControls(0); }); }); }, @@ -239,17 +255,23 @@ export default { : "text-dark"; }, fetchData(selectedOptions) { + const { id: userId, username } = this.currentUser; + if (!userId && !username) { + this.showTable = false; + this.emitDataControls(0); + return; + } if (selectedOptions[0] === "by_me" && selectedOptions[1] !== "View All") { - this.pmql = `(user_id = ${ProcessMaker.user.id}) AND (status = "${selectedOptions[1]}")`; + this.pmql = `(user_id = ${userId}) AND (status = "${selectedOptions[1]}")`; } if ( selectedOptions[0] === "as_participant" && selectedOptions[1] !== "View All" ) { - this.pmql = `(status = "${selectedOptions[1]}") AND (participant = "${Processmaker.user.username}")`; + this.pmql = `(status = "${selectedOptions[1]}") AND (participant = "${username}")`; } if (selectedOptions[1] === "View All") { - this.pmql = `(user_id = ${ProcessMaker.user.id}) AND ((status = "In Progress") OR (status = "Completed"))`; + this.pmql = `(user_id = ${userId}) AND ((status = "In Progress") OR (status = "Completed"))`; } this.fetch(); }, diff --git a/tests/unit/FormListTablePreview.spec.js b/tests/unit/FormListTablePreview.spec.js new file mode 100644 index 00000000..7567d2d5 --- /dev/null +++ b/tests/unit/FormListTablePreview.spec.js @@ -0,0 +1,182 @@ +const fs = require("fs"); +const path = require("path"); +const vm = require("vm"); + +function loadComponentOptions(relativePath, { processMakerUser = {}, processmakerUser = {} } = {}) { + const componentPath = path.join(process.cwd(), relativePath); + const source = fs.readFileSync(componentPath, "utf8"); + const scriptMatch = source.match(/