Skip to content

Commit d43dc69

Browse files
committed
Add validation to check if packages are installed
1 parent 1022975 commit d43dc69

2 files changed

Lines changed: 109 additions & 35 deletions

File tree

resources/js/admin/logs/components/Logs/Sidebar/Sidebar.vue

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
Logs
66
</div>
77
<nav class="tw-mt-1">
8-
<!-- Email Category -->
9-
<div class="tw-mt-3">
8+
<!-- Email Category - Only show if email package is installed -->
9+
<div
10+
v-if="hasEmailPackage"
11+
class="tw-mt-3"
12+
>
1013
<button
1114
v-b-toggle.collapse-email
1215
class="
@@ -54,15 +57,18 @@
5457
tw-text-base
5558
tw-cursor-pointer
5659
"
57-
:class="isEmailActive ? 'tw-bg-blue-50 tw-font-semibold tw-text-blue-500' : 'tw-font-medium tw-text-zinc-700 hover:tw-bg-zinc-50'"
60+
:class="emailLinkClasses"
5861
>
5962
<span class="tw-inline-flex tw-items-center tw-gap-2">Email Start Event</span>
6063
</RouterLink>
6164
</b-collapse>
6265
</div>
6366

64-
<!-- Agents Category -->
65-
<div class="tw-mt-3">
67+
<!-- Agents Category - Only show if AI package is installed -->
68+
<div
69+
v-if="hasAiPackage"
70+
class="tw-mt-3"
71+
>
6672
<button
6773
v-b-toggle.collapse-agents
6874
class="
@@ -110,7 +116,7 @@
110116
tw-text-base
111117
tw-cursor-pointer
112118
"
113-
:class="isAgentsActive ? 'tw-bg-blue-50 tw-font-semibold tw-text-blue-500' : 'tw-font-medium tw-text-zinc-700 hover:tw-bg-zinc-50'"
119+
:class="agentsLinkClasses"
114120
>
115121
<span class="tw-inline-flex tw-items-center tw-gap-2">FlowGenie Agents logs</span>
116122
</RouterLink>
@@ -122,52 +128,69 @@
122128
</template>
123129

124130
<script>
131+
import { hasEmailPackage, hasAiPackage } from "../routes";
132+
125133
export default {
126-
name: 'LogsSidebar',
134+
name: "LogsSidebar",
127135
data() {
128136
return {
129137
collapseStates: {
130-
email: this.$route.path.startsWith('/email'),
131-
agents: this.$route.path.startsWith('/agents'),
138+
email: this.$route.path.startsWith("/email"),
139+
agents: this.$route.path.startsWith("/agents"),
132140
},
133141
};
134142
},
135143
computed: {
144+
hasEmailPackage() {
145+
return hasEmailPackage();
146+
},
147+
hasAiPackage() {
148+
return hasAiPackage();
149+
},
136150
isEmailActive() {
137-
return this.$route.path.startsWith('/email');
151+
return this.$route.path.startsWith("/email");
138152
},
139153
isAgentsActive() {
140-
return this.$route.path.startsWith('/agents');
154+
return this.$route.path.startsWith("/agents");
155+
},
156+
emailLinkClasses() {
157+
return this.isEmailActive
158+
? "tw-bg-blue-50 tw-font-semibold tw-text-blue-500"
159+
: "tw-font-medium tw-text-zinc-700 hover:tw-bg-zinc-50";
160+
},
161+
agentsLinkClasses() {
162+
return this.isAgentsActive
163+
? "tw-bg-blue-50 tw-font-semibold tw-text-blue-500"
164+
: "tw-font-medium tw-text-zinc-700 hover:tw-bg-zinc-50";
141165
},
142166
},
143167
watch: {
144168
// Auto-expand the category when navigating to it
145-
'$route.path': {
169+
"$route.path": {
146170
handler(path) {
147-
if (path.startsWith('/agents') && !this.collapseStates.agents) {
148-
this.$root.$emit('bv::toggle::collapse', 'collapse-agents');
171+
if (path.startsWith("/agents") && !this.collapseStates.agents) {
172+
this.$root.$emit("bv::toggle::collapse", "collapse-agents");
149173
}
150-
if (path.startsWith('/email') && !this.collapseStates.email) {
151-
this.$root.$emit('bv::toggle::collapse', 'collapse-email');
174+
if (path.startsWith("/email") && !this.collapseStates.email) {
175+
this.$root.$emit("bv::toggle::collapse", "collapse-email");
152176
}
153177
},
154178
immediate: true,
155179
},
156180
},
157181
mounted() {
158182
// Listen for collapse events to update icon rotation
159-
this.$root.$on('bv::collapse::state', (id, state) => {
160-
if (id === 'collapse-email') {
183+
this.$root.$on("bv::collapse::state", (id, state) => {
184+
if (id === "collapse-email") {
161185
this.collapseStates.email = state;
162-
} else if (id === 'collapse-agents') {
186+
} else if (id === "collapse-agents") {
163187
this.collapseStates.agents = state;
164188
}
165189
});
166190
},
167191
beforeDestroy() {
168192
// Clean up event listener
169-
this.$root.$off('bv::collapse::state');
193+
this.$root.$off("bv::collapse::state");
170194
},
171195
};
172196
</script>
173-

resources/js/admin/logs/components/Logs/routes.js

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,92 @@
1-
import { LogTable } from './LogTable';
1+
import { LogTable } from "./LogTable";
22

33
export default {};
44

5+
/**
6+
* Check if a package is installed
7+
* @param {string} packageName - The package name to check
8+
* @returns {boolean}
9+
*/
10+
const isPackageInstalled = (packageName) => window.ProcessMaker?.packages?.includes(packageName);
11+
12+
/**
13+
* Check if email start event package is installed
14+
* @returns {boolean}
15+
*/
16+
export const hasEmailPackage = () => isPackageInstalled("package-email-start-event");
17+
18+
/**
19+
* Check if AI package is installed
20+
* @returns {boolean}
21+
*/
22+
export const hasAiPackage = () => isPackageInstalled("package-ai");
23+
24+
/**
25+
* Determine the default redirect path based on installed packages
26+
* @returns {string}
27+
*/
28+
const getDefaultRedirectPath = () => {
29+
if (hasEmailPackage()) {
30+
return "/email/errors";
31+
}
32+
if (hasAiPackage()) {
33+
return "/agents/design";
34+
}
35+
// Fallback - shouldn't happen if menu visibility is correct
36+
return "/email/errors";
37+
};
38+
539
export const routes = [
640
{
7-
name: 'logs.index',
8-
path: '/',
9-
redirect: '/email/errors',
41+
name: "logs.index",
42+
path: "/",
43+
beforeEnter: (to, from, next) => {
44+
next(getDefaultRedirectPath());
45+
},
1046
},
1147
// Email logs routes
1248
{
13-
name: 'logs.email',
14-
path: '/email/:logType',
49+
name: "logs.email",
50+
path: "/email/:logType",
1551
component: LogTable,
1652
props(route) {
1753
return {
18-
category: 'email',
54+
category: "email",
1955
logType: route.params.logType,
2056
};
2157
},
58+
beforeEnter: (to, from, next) => {
59+
if (!hasEmailPackage()) {
60+
// Redirect to agents if email package not installed
61+
next(hasAiPackage() ? "/agents/design" : "/");
62+
} else {
63+
next();
64+
}
65+
},
2266
},
2367
// FlowGenie Agents logs routes
2468
{
25-
name: 'logs.agents.redirect',
26-
path: '/agents',
27-
redirect: '/agents/design',
69+
name: "logs.agents.redirect",
70+
path: "/agents",
71+
redirect: "/agents/design",
2872
},
2973
{
30-
name: 'logs.agents',
31-
path: '/agents/:logType',
74+
name: "logs.agents",
75+
path: "/agents/:logType",
3276
component: LogTable,
3377
props(route) {
3478
return {
35-
category: 'agents',
79+
category: "agents",
3680
logType: route.params.logType,
3781
};
3882
},
83+
beforeEnter: (to, from, next) => {
84+
if (!hasAiPackage()) {
85+
// Redirect to email if AI package not installed
86+
next(hasEmailPackage() ? "/email/errors" : "/");
87+
} else {
88+
next();
89+
}
90+
},
3991
},
4092
];
41-

0 commit comments

Comments
 (0)