Skip to content

Commit

Permalink
ui: refactor dashboard page when the user don't have namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonyRafael authored and gustavosbarreto committed Feb 17, 2023
1 parent 736b589 commit a8968f9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
1 change: 1 addition & 0 deletions ui/src/components/AppBar/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default defineComponent({
const logout = async () => {
try {
await store.dispatch("auth/logout");
await store.dispatch("stats/clear");
await store.dispatch("namespaces/clearNamespaceList");
await router.push({ name: "login" });
createNewClient();
Expand Down
4 changes: 4 additions & 0 deletions ui/src/store/modules/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ export const stats: Module<StatsState, State> = {
throw error;
}
},

async clear({ commit }) {
commit("clearListState");
},
},
};
76 changes: 40 additions & 36 deletions ui/src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,52 @@ export default defineComponent({
components: { Card },
setup() {
const store = useStore();
const items = ref<ItemCard[]>([]);
const hasStatus = ref(false);
const itemsStats = computed(() => store.getters["stats/stats"]);
const hasNamespace = computed(
() => store.getters["namespaces/getNumberNamespaces"] !== 0,
);
const items = computed(() => [
{
id: 1,
title: "Registered Devices",
fieldObject: "registered_devices",
content: "Registered devices into the tenancy account",
icon: "mdi-devices",
stats: itemsStats.value.registered_devices || 0,
buttonName: "Add Device",
pathName: "devices",
nameUseTest: "registeredDevices-btn",
},
{
id: 2,
title: "Online Devices",
fieldObject: "online_devices",
content: "Devices are online and ready for connecting",
icon: "mdi-devices",
stats: itemsStats.value.online_devices || 0,
buttonName: "View all Devices",
pathName: "devices",
nameUseTest: "viewOnlineDevices-btn",
},
{
id: 3,
title: "Active Sessions",
fieldObject: "active_sessions",
content: "Active SSH Sessions opened by users",
icon: "mdi-devices",
stats: itemsStats.value.active_sessions || 0,
buttonName: "View all Sessions",
pathName: "sessions",
nameUseTest: "viewActiveSession-btn",
},
] as ItemCard[]);
onMounted(async () => {
if (!hasNamespace.value) return;
try {
await store.dispatch("stats/get");
items.value = [
{
id: 1,
title: "Registered Devices",
fieldObject: "registered_devices",
content: "Registered devices into the tenancy account",
icon: "mdi-devices",
stats: itemsStats.value.registered_devices ?? 0,
buttonName: "Add Device",
pathName: "devices",
nameUseTest: "registeredDevices-btn",
},
{
id: 2,
title: "Online Devices",
fieldObject: "online_devices",
content: "Devices are online and ready for connecting",
icon: "mdi-devices",
stats: itemsStats.value.online_devices ?? 0,
buttonName: "View all Devices",
pathName: "devices",
nameUseTest: "viewOnlineDevices-btn",
},
{
id: 3,
title: "Active Sessions",
fieldObject: "active_sessions",
content: "Active SSH Sessions opened by users",
icon: "mdi-devices",
stats: itemsStats.value.active_sessions ?? 0,
buttonName: "View all Sessions",
pathName: "sessions",
nameUseTest: "viewActiveSession-btn",
},
];
} catch (error: any) {
switch (true) {
case error.response && error.response.status === 403: {
Expand Down
2 changes: 2 additions & 0 deletions ui/src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ export default defineComponent({
if (route.query.token) {
store.dispatch("layout/setLayout", "simpleLayout");
loginToken.value = true;
await store.dispatch("stats/clear");
await store.dispatch("namespaces/clearNamespaceList");
await store.dispatch("auth/logout");
createNewClient();
Expand Down

0 comments on commit a8968f9

Please sign in to comment.