Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat: introducing a new smart table hoppscotch ui component (#3178)

Joel Jacob Stephen23e373971849
diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts
index f4d4b2e39..b1c4080b5 100644
--- a/packages/hoppscotch-common/src/components.d.ts
+++ b/packages/hoppscotch-common/src/components.d.ts
@@ -5,7 +5,7 @@
// Read more: https://github.com/vuejs/core/pull/3399
export {}
-declare module 'vue' {
+declare module "vue" {
export interface GlobalComponents {
AppActionHandler: typeof import('./components/app/ActionHandler.vue')['default']
AppAnnouncement: typeof import('./components/app/Announcement.vue')['default']
diff --git a/packages/hoppscotch-sh-admin/locales/en.json b/packages/hoppscotch-sh-admin/locales/en.json
index 0ddbc8e48..8ee46d30b 100644
--- a/packages/hoppscotch-sh-admin/locales/en.json
+++ b/packages/hoppscotch-sh-admin/locales/en.json
@@ -98,9 +98,10 @@
"load_info_error": "Unable to load team info",
"load_list_error": "Unable to Load Teams List",
"members": "Number of members",
- "name": "Team name",
+ "name": "Team Name",
"no_members": "No members in this team. Add members to this team to collaborate",
"no_pending_invites": "No pending invites",
+ "no_teams": "No teams found",
"pending_invites": "Pending invites",
"remove": "Remove",
"rename": "Rename",
@@ -112,6 +113,7 @@
"team_members_tab": "Team members",
"teams": "Teams",
"uid": "UID",
+ "unnamed": "(Unnamed Team)",
"valid_name": "Please enter a valid team name",
"valid_owner_email": "Please enter a valid owner email"
},
@@ -125,6 +127,7 @@
"created_on": "Created On",
"date": "Date",
"delete": "Delete",
+ "delete_user": "Delete User",
"email": "Email",
"email_address": "Email Address",
"id": "User ID",
@@ -136,6 +139,7 @@
"load_info_error": "Unable to load user info",
"load_list_error": "Unable to Load Users List",
"make_admin": "Make admin",
+ "invite_load_list_error": "Unable to Load Invited Users List",
"name": "Name",
"no_invite": "No invited users found",
"no_users": "No users found",
diff --git a/packages/hoppscotch-sh-admin/src/components.d.ts b/packages/hoppscotch-sh-admin/src/components.d.ts
index 953862949..418a20579 100644
--- a/packages/hoppscotch-sh-admin/src/components.d.ts
+++ b/packages/hoppscotch-sh-admin/src/components.d.ts
@@ -1,44 +1,71 @@
// generated by unplugin-vue-components
// We suggest you to commit this file into source control
// Read more: https://github.com/vuejs/core/pull/3399
-import '@vue/runtime-core';
+import '@vue/runtime-core'
-export {};
+export {}
declare module '@vue/runtime-core' {
export interface GlobalComponents {
- AppHeader: typeof import('./components/app/Header.vue')['default'];
- AppLogin: typeof import('./components/app/Login.vue')['default'];
- AppLogout: typeof import('./components/app/Logout.vue')['default'];
- AppModal: typeof import('./components/app/Modal.vue')['default'];
- AppSidebar: typeof import('./components/app/Sidebar.vue')['default'];
- AppToast: typeof import('./components/app/Toast.vue')['default'];
- DashboardMetricsCard: typeof import('./components/dashboard/MetricsCard.vue')['default'];
- HoppButtonPrimary: typeof import('@hoppscotch/ui')['HoppButtonPrimary'];
- HoppButtonSecondary: typeof import('@hoppscotch/ui')['HoppButtonSecondary'];
- HoppSmartAnchor: typeof import('@hoppscotch/ui')['HoppSmartAnchor'];
- HoppSmartAutoComplete: typeof import('@hoppscotch/ui')['HoppSmartAutoComplete'];
- HoppSmartConfirmModal: typeof import('@hoppscotch/ui')['HoppSmartConfirmModal'];
- HoppSmartInput: typeof import('@hoppscotch/ui')['HoppSmartInput'];
- HoppSmartItem: typeof import('@hoppscotch/ui')['HoppSmartItem'];
- HoppSmartModal: typeof import('@hoppscotch/ui')['HoppSmartModal'];
- HoppSmartPicture: typeof import('@hoppscotch/ui')['HoppSmartPicture'];
- HoppSmartPlaceholder: typeof import('@hoppscotch/ui')['HoppSmartPlaceholder'];
- HoppSmartSpinner: typeof import('@hoppscotch/ui')['HoppSmartSpinner'];
- HoppSmartTab: typeof import('@hoppscotch/ui')['HoppSmartTab'];
- IconLucideArrowLeft: typeof import('~icons/lucide/arrow-left')['default'];
- IconLucideChevronDown: typeof import('~icons/lucide/chevron-down')['default'];
- IconLucideHelpCircle: typeof import('~icons/lucide/help-circle')['default'];
- IconLucideInbox: typeof import('~icons/lucide/inbox')['default'];
- IconLucideUser: typeof import('~icons/lucide/user')['default'];
- TeamsAdd: typeof import('./components/teams/Add.vue')['default'];
- TeamsDetails: typeof import('./components/teams/Details.vue')['default'];
- TeamsInvite: typeof import('./components/teams/Invite.vue')['default'];
- TeamsMembers: typeof import('./components/teams/Members.vue')['default'];
- TeamsPendingInvites: typeof import('./components/teams/PendingInvites.vue')['default'];
- TeamsTable: typeof import('./components/teams/Table.vue')['default'];
- Tippy: typeof import('vue-tippy')['Tippy'];
- UsersInviteModal: typeof import('./components/users/InviteModal.vue')['default'];
- UsersTable: typeof import('./components/users/Table.vue')['default'];
+ AppHeader: typeof import('./components/app/Header.vue')['default']
+ AppLogin: typeof import('./components/app/Login.vue')['default']
+ AppLogout: typeof import('./components/app/Logout.vue')['default']
+ AppModal: typeof import('./components/app/Modal.vue')['default']
+ AppSidebar: typeof import('./components/app/Sidebar.vue')['default']
+ AppToast: typeof import('./components/app/Toast.vue')['default']
+ ButtonPrimary: typeof import('./../../hoppscotch-ui/src/components/button/Primary.vue')['default']
+ ButtonSecondary: typeof import('./../../hoppscotch-ui/src/components/button/Secondary.vue')['default']
+ DashboardMetricsCard: typeof import('./components/dashboard/MetricsCard.vue')['default']
+ HoppButtonPrimary: typeof import('@hoppscotch/ui')['HoppButtonPrimary']
+ HoppButtonSecondary: typeof import('@hoppscotch/ui')['HoppButtonSecondary']
+ HoppSmartAnchor: typeof import('@hoppscotch/ui')['HoppSmartAnchor']
+ HoppSmartAutoComplete: typeof import('@hoppscotch/ui')['HoppSmartAutoComplete']
+ HoppSmartConfirmModal: typeof import('@hoppscotch/ui')['HoppSmartConfirmModal']
+ HoppSmartInput: typeof import('@hoppscotch/ui')['HoppSmartInput']
+ HoppSmartItem: typeof import('@hoppscotch/ui')['HoppSmartItem']
+ HoppSmartModal: typeof import('@hoppscotch/ui')['HoppSmartModal']
+ HoppSmartPicture: typeof import('@hoppscotch/ui')['HoppSmartPicture']
+ HoppSmartPlaceholder: typeof import('@hoppscotch/ui')['HoppSmartPlaceholder']
+ HoppSmartSpinner: typeof import('@hoppscotch/ui')['HoppSmartSpinner']
+ HoppSmartTab: typeof import('@hoppscotch/ui')['HoppSmartTab']
+ HoppSmartTable: typeof import('@hoppscotch/ui')['HoppSmartTable']
+ IconLucideArrowLeft: typeof import('~icons/lucide/arrow-left')['default']
+ IconLucideChevronDown: typeof import('~icons/lucide/chevron-down')['default']
+ IconLucideHelpCircle: typeof import('~icons/lucide/help-circle')['default']
+ IconLucideInbox: typeof import('~icons/lucide/inbox')['default']
+ SmartAnchor: typeof import('./../../hoppscotch-ui/src/components/smart/Anchor.vue')['default']
+ SmartAutoComplete: typeof import('./../../hoppscotch-ui/src/components/smart/AutoComplete.vue')['default']
+ SmartCheckbox: typeof import('./../../hoppscotch-ui/src/components/smart/Checkbox.vue')['default']
+ SmartConfirmModal: typeof import('./../../hoppscotch-ui/src/components/smart/ConfirmModal.vue')['default']
+ SmartExpand: typeof import('./../../hoppscotch-ui/src/components/smart/Expand.vue')['default']
+ SmartFileChip: typeof import('./../../hoppscotch-ui/src/components/smart/FileChip.vue')['default']
+ SmartInput: typeof import('./../../hoppscotch-ui/src/components/smart/Input.vue')['default']
+ SmartIntersection: typeof import('./../../hoppscotch-ui/src/components/smart/Intersection.vue')['default']
+ SmartItem: typeof import('./../../hoppscotch-ui/src/components/smart/Item.vue')['default']
+ SmartLink: typeof import('./../../hoppscotch-ui/src/components/smart/Link.vue')['default']
+ SmartModal: typeof import('./../../hoppscotch-ui/src/components/smart/Modal.vue')['default']
+ SmartPicture: typeof import('./../../hoppscotch-ui/src/components/smart/Picture.vue')['default']
+ SmartPlaceholder: typeof import('./../../hoppscotch-ui/src/components/smart/Placeholder.vue')['default']
+ SmartProgressRing: typeof import('./../../hoppscotch-ui/src/components/smart/ProgressRing.vue')['default']
+ SmartRadio: typeof import('./../../hoppscotch-ui/src/components/smart/Radio.vue')['default']
+ SmartRadioGroup: typeof import('./../../hoppscotch-ui/src/components/smart/RadioGroup.vue')['default']
+ SmartSlideOver: typeof import('./../../hoppscotch-ui/src/components/smart/SlideOver.vue')['default']
+ SmartSpinner: typeof import('./../../hoppscotch-ui/src/components/smart/Spinner.vue')['default']
+ SmartTab: typeof import('./../../hoppscotch-ui/src/components/smart/Tab.vue')['default']
+ SmartTable: typeof import('./../../hoppscotch-ui/src/components/smart/Table.vue')['default']
+ SmartTabs: typeof import('./../../hoppscotch-ui/src/components/smart/Tabs.vue')['default']
+ SmartToggle: typeof import('./../../hoppscotch-ui/src/components/smart/Toggle.vue')['default']
+ SmartTree: typeof import('./../../hoppscotch-ui/src/components/smart/Tree.vue')['default']
+ SmartTreeBranch: typeof import('./../../hoppscotch-ui/src/components/smart/TreeBranch.vue')['default']
+ SmartWindow: typeof import('./../../hoppscotch-ui/src/components/smart/Window.vue')['default']
+ SmartWindows: typeof import('./../../hoppscotch-ui/src/components/smart/Windows.vue')['default']
+ TeamsAdd: typeof import('./components/teams/Add.vue')['default']
+ TeamsDetails: typeof import('./components/teams/Details.vue')['default']
+ TeamsInvite: typeof import('./components/teams/Invite.vue')['default']
+ TeamsMembers: typeof import('./components/teams/Members.vue')['default']
+ TeamsPendingInvites: typeof import('./components/teams/PendingInvites.vue')['default']
+ Tippy: typeof import('vue-tippy')['Tippy']
+ UsersInviteModal: typeof import('./components/users/InviteModal.vue')['default']
}
+
}
diff --git a/packages/hoppscotch-sh-admin/src/components/teams/Table.vue b/packages/hoppscotch-sh-admin/src/components/teams/Table.vue
deleted file mode 100644
index 5e26bbc05..000000000
--- a/packages/hoppscotch-sh-admin/src/components/teams/Table.vue
+++ /dev/null
@@ -1,102 +0,0 @@
-<template>
- <table class="w-full">
- <thead>
- <tr class="text-secondary border-b border-dividerDark text-sm text-left">
- <th class="px-3 pb-3">Team ID</th>
- <th class="px-3 pb-3">Team Name</th>
- <th class="px-3 pb-3">Number of Members</th>
- <th class="px-3 pb-3"></th>
- </tr>
- </thead>
-
- <tbody class="divide-y divide-divider">
- <tr v-if="teamList.length === 0">
- <div class="py-6 px-3">No teams found ...</div>
- </tr>
- <tr
- v-else
- v-for="team in teamList"
- :key="team.id"
- class="text-secondaryDark hover:bg-divider hover:cursor-pointer rounded-xl"
- >
- <td
- @click="$emit('go-to-team-details', team.id)"
- class="py-4 px-3 max-w-50"
- >
- <div class="flex">
- <span class="truncate">
- {{ team.id }}
- </span>
- </div>
- </td>
-
- <td
- @click="$emit('go-to-team-details', team.id)"
- class="py-4 px-3 min-w-80"
- >
- <span v-if="team.name" class="flex items-center ml-4 truncate">
- {{ team.name }}
- </span>
- <span v-else class="flex items-center ml-4"> (Unnamed team) </span>
- </td>
-
- <td @click="$emit('go-to-team-details', team.id)" class="py-4 px-3">
- <span class="ml-7">
- {{ team.members?.length }}
- </span>
- </td>
-
- <td>
- <div class="relative">
- <tippy interactive trigger="click" theme="popover">
- <HoppButtonSecondary
- v-tippy="{ theme: 'tooltip' }"
- :icon="IconMoreHorizontal"
- />
- <template #content="{ hide }">
- <div
- ref="tippyActions"
- class="flex flex-col focus:outline-none"
- tabindex="0"
- @keyup.escape="hide()"
- >
- <HoppSmartItem
- :icon="IconTrash"
- :label="'Delete Team'"
- class="!hover:bg-red-600 w-full"
- @click="
- () => {
- $emit('delete-team', team.id);
- hide();
- }
- "
- />
- </div>
- </template>
- </tippy>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
-</template>
-
-<script setup lang="ts">
-import { TippyComponent } from 'vue-tippy';
-import { ref } from 'vue';
-import IconTrash from '~icons/lucide/trash';
-import IconMoreHorizontal from '~icons/lucide/more-horizontal';
-import { TeamListQuery } from '~/helpers/backend/graphql';
-
-// Template refs
-const tippyActions = ref<TippyComponent | null>(null);
-
-defineProps<{
- teamList: TeamListQuery['infra']['allTeams'];
-}>();
-
-defineEmits<{
- (event: 'go-to-team-details', teamID: string): void;
- (event: 'delete-team', teamID: string): void;
-}>();
-</script>
diff --git a/packages/hoppscotch-sh-admin/src/components/users/Table.vue b/packages/hoppscotch-sh-admin/src/components/users/Table.vue
deleted file mode 100644
index 9e3c8d657..000000000
--- a/packages/hoppscotch-sh-admin/src/components/users/Table.vue
+++ /dev/null
@@ -1,162 +0,0 @@
-<template>
- <table class="w-full">
- <thead>
- <tr class="text-secondary border-b border-dividerDark text-sm text-left">
- <th class="px-3 pb-3">{{ t('users.id') }}</th>
- <th class="px-3 pb-3">{{ t('users.name') }}</th>
- <th class="px-3 pb-3">{{ t('users.email') }}</th>
- <th class="px-3 pb-3">{{ t('users.date') }}</th>
- <th class="px-3 pb-3"></th>
- </tr>
- </thead>
-
- <tbody class="divide-y divide-divider">
- <tr
- v-for="user in usersList"
- :key="user.uid"
- class="text-secondaryDark hover:bg-divider hover:cursor-pointer rounded-xl"
- >
- <td
- @click="$emit('goToUserDetails', user.uid)"
- class="py-2 px-3 max-w-30"
- >
- <div class="flex">
- <span class="truncate">
- {{ user.uid }}
- </span>
- </div>
- </td>
-
- <td @click="$emit('goToUserDetails', user.uid)" class="py-2 px-3">
- <div v-if="user.displayName" class="flex items-center space-x-3">
- <span>
- {{ user.displayName }}
- </span>
- <span
- v-if="user.isAdmin"
- class="text-xs font-medium px-3 py-0.5 rounded-full bg-green-900 text-green-300"
- >
- {{ t('users.admin') }}
- </span>
- </div>
- <div v-else class="flex items-center space-x-3">
- <span> {{ t('users.unnamed') }} </span>
- <span
- v-if="user.isAdmin"
- class="text-xs font-medium px-3 py-0.5 rounded-full bg-green-900 text-green-300"
- >
- {{ t('users.admin') }}
- </span>
- </div>
- </td>
-
- <td @click="$emit('goToUserDetails', user.uid)" class="py-2 px-3">
- <span>
- {{ user.email }}
- </span>
- </td>
-
- <td @click="$emit('goToUserDetails', user.uid)" class="py-2 px-3">
- <div class="flex items-center">
- <div class="flex flex-col">
- {{ getCreatedDate(user.createdOn) }}
- <div class="text-gray-400 text-tiny">
- {{ getCreatedTime(user.createdOn) }}
- </div>
- </div>
- </div>
- </td>
-
- <td>
- <div class="relative">
- <span>
- <tippy interactive trigger="click" theme="popover">
- <HoppButtonSecondary
- v-tippy="{ theme: 'tooltip' }"
- :icon="IconMoreHorizontal"
- />
- <template #content="{ hide }">
- <div
- ref="tippyActions"
- class="flex flex-col focus:outline-none"
- tabindex="0"
- @keyup.escape="hide()"
- >
- <HoppSmartItem
- v-if="!user.isAdmin"
- :icon="IconUserCheck"
- :label="'Make Admin'"
- class="!hover:bg-emerald-600"
- @click="
- () => {
- $emit('makeUserAdmin', user.uid);
- hide();
- }
- "
- />
- <HoppSmartItem
- v-else
- :icon="IconUserMinus"
- :label="'Remove Admin Status'"
- class="!hover:bg-emerald-600"
- @click="
- () => {
- $emit('makeAdminToUser', user.uid);
- hide();
- }
- "
- />
- <HoppSmartItem
- v-if="!user.isAdmin"
- :icon="IconTrash"
- :label="'Delete User'"
- class="!hover:bg-red-600"
- @click="
- () => {
- $emit('deleteUser', user.uid);
- hide();
- }
- "
- />
- </div>
- </template>
- </tippy>
- </span>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
-</template>
-
-<script lang="ts" setup>
-import { format } from 'date-fns';
-import { ref } from 'vue';
-import IconTrash from '~icons/lucide/trash';
-import IconUserMinus from '~icons/lucide/user-minus';
-import IconUserCheck from '~icons/lucide/user-check';
-import IconMoreHorizontal from '~icons/lucide/more-horizontal';
-import { UsersListQuery } from '~/helpers/backend/graphql';
-import { TippyComponent } from 'vue-tippy';
-import { useI18n } from '~/composables/i18n';
-
-const t = useI18n();
-
-defineProps<{
- usersList: UsersListQuery['infra']['allUsers'];
-}>();
-
-defineEmits<{
- (event: 'goToUserDetails', uid: string): void;
- (event: 'makeUserAdmin', uid: string): void;
- (event: 'makeAdminToUser', uid: string): void;
- (event: 'deleteUser', uid: string): void;
-}>();
-
-// Get Proper Date Formats
-const getCreatedDate = (date: string) => format(new Date(date), 'dd-MM-yyyy');
-const getCreatedTime = (date: string) => format(new Date(date), 'hh:mm a');
-
-// Template refs
-const tippyActions = ref<TippyComponent | null>(null);
-</script>
diff --git a/packages/hoppscotch-sh-admin/src/pages/teams/index.vue b/packages/hoppscotch-sh-admin/src/pages/teams/index.vue
index a51b75aca..8dcdbffaf 100644
--- a/packages/hoppscotch-sh-admin/src/pages/teams/index.vue
+++ b/packages/hoppscotch-sh-admin/src/pages/teams/index.vue
@@ -12,25 +12,90 @@
</div>
<div class="overflow-x-auto">
- <div
- v-if="fetching && !error && teamList.length === 0"
- class="flex justify-center"
- >
+ <div v-if="fetching" class="flex justify-center">
<HoppSmartSpinner />
</div>
<div v-else-if="error">{{ t('teams.load_list_error') }}</div>
- <TeamsTable
- v-else
- :teamList="teamList"
- @goToTeamDetails="goToTeamDetails"
- @deleteTeam="deleteTeam"
- class=""
- />
+ <HoppSmartTable v-else-if="teamsList.length" :list="teamsList">
+ <template #head>
+ <tr
+ class="text-secondary border-b border-dividerDark text-sm text-left bg-primaryLight"
+ >
+ <th class="px-6 py-2">{{ t('teams.id') }}</th>
+ <th class="px-6 py-3">{{ t('teams.name') }}</th>
+ <th class="px-6 py-2">{{ t('teams.members') }}</th>
+ <!-- Empty Heading for the Action Button -->
+ <th class="px-6 py-2"></th>
+ </tr>
+ </template>
+ <template #body="{ list }">
+ <tr
+ v-for="team in list"
+ :key="team.id"
+ class="text-secondaryDark hover:bg-divider hover:cursor-pointer rounded-xl"
+ @click="goToTeamDetails(team.id)"
+ >
+ <td class="flex py-4 px-7 max-w-50">
+ <span class="truncate">
+ {{ team.id }}
+ </span>
+ </td>
+
+ <td class="py-4 px-7 min-w-80">
+ <span
+ class="flex items-center truncate"
+ :class="{ truncate: team.name }"
+ >
+ {{ team.name ?? t('teams.unnamed') }}
+ </span>
+ </td>
+
+ <td class="py-4 px-7">
+ {{ team.members?.length }}
+ </td>
+
+ <td @click.stop>
+ <div class="relative">
+ <tippy interactive trigger="click" theme="popover">
+ <HoppButtonSecondary
+ v-tippy="{ theme: 'tooltip' }"
+ :icon="IconMoreHorizontal"
+ />
+ <template #content="{ hide }">
+ <div
+ ref="tippyActions"
+ class="flex flex-col focus:outline-none"
+ tabindex="0"
+ @keyup.escape="hide()"
+ >
+ <HoppSmartItem
+ :icon="IconTrash"
+ :label="t('teams.delete_team')"
+ class="!hover:bg-red-600 w-full"
+ @click="
+ () => {
+ deleteTeam(team.id);
+ hide();
+ }
+ "
+ />
+ </div>
+ </template>
+ </tippy>
+ </div>
+ </td>
+ </tr>
+ </template>
+ </HoppSmartTable>
+
+ <div v-else class="px-2 text-lg">
+ {{ t('teams.no_teams') }}
+ </div>
<div
- v-if="hasNextPage && teamList.length >= teamsPerPage"
+ v-if="hasNextPage && teamsList.length >= teamsPerPage"
class="flex justify-center my-5 px-3 py-2 cursor-pointer font-semibold rounded-3xl bg-dividerDark hover:bg-divider transition mx-auto w-38 text-secondaryDark"
@click="fetchNextTeams"
>
@@ -66,10 +131,12 @@ import {
UsersListDocument,
} from '../../helpers/backend/graphql';
import { usePagedQuery } from '~/composables/usePagedQuery';
-import { ref, watch, computed } from 'vue';
+import { computed, ref, watch } from 'vue';
import { useMutation, useQuery } from '@urql/vue';
import { useToast } from '~/composables/toast';
import IconAddUsers from '~icons/lucide/plus';
+import IconTrash from '~icons/lucide/trash';
+import IconMoreHorizontal from '~icons/lucide/more-horizontal';
import { useI18n } from '~/composables/i18n';
const t = useI18n();
@@ -96,7 +163,7 @@ const {
error,
goToNextPage: fetchNextTeams,
refetch,
- list: teamList,
+ list: teamsList,
hasNextPage,
} = usePagedQuery(
TeamListDocument,
@@ -143,9 +210,7 @@ const createTeam = async (newTeamName: string, ownerEmail: string) => {
// Go To Individual Team Details Page
const router = useRouter();
-const goToTeamDetails = (teamId: string) => {
- router.push('/teams/' + teamId);
-};
+const goToTeamDetails = (teamId: string) => router.push('/teams/' + teamId);
// Reload Teams Page when routed back to the teams page
const route = useRoute();
@@ -175,7 +240,7 @@ const deleteTeamMutation = async (id: string | null) => {
if (result.error) {
toast.error(`${t('state.delete_team_failure')}`);
} else {
- teamList.value = teamList.value.filter((team) => team.id !== id);
+ teamsList.value = teamsList.value.filter((team) => team.id !== id);
toast.success(`${t('state.delete_team_success')}`);
}
});
diff --git a/packages/hoppscotch-sh-admin/src/pages/users/index.vue b/packages/hoppscotch-sh-admin/src/pages/users/index.vue
index 40c35d337..27ed25780 100644
--- a/packages/hoppscotch-sh-admin/src/pages/users/index.vue
+++ b/packages/hoppscotch-sh-admin/src/pages/users/index.vue
@@ -22,27 +22,118 @@
</div>
</div>
<div class="overflow-x-auto">
- <div
- v-if="fetching && !error && usersList.length === 0"
- class="flex justify-center"
- >
+ <div v-if="fetching" class="flex justify-center">
<HoppSmartSpinner />
</div>
<div v-else-if="error">{{ t('users.load_list_error') }}</div>
- <UsersTable
- v-else-if="usersList.length >= 1"
- :usersList="usersList"
- :fetching="fetching"
- :error="error"
- @goToUserDetails="goToUserDetails"
- @makeUserAdmin="makeUserAdmin"
- @makeAdminToUser="makeAdminToUser"
- @deleteUser="deleteUser"
- />
+ <HoppSmartTable v-else-if="usersList.length" :list="usersList">
+ <template #head>
+ <tr
+ class="text-secondary border-b border-dividerDark text-sm text-left bg-primaryLight"
+ >
+ <th class="px-6 py-2">{{ t('users.id') }}</th>
+ <th class="px-6 py-2">{{ t('users.name') }}</th>
+ <th class="px-6 py-2">{{ t('users.email') }}</th>
+ <th class="px-6 py-2">{{ t('users.date') }}</th>
+ <!-- Empty header for Action Button -->
+ <th class="px-6 py-2"></th>
+ </tr>
+ </template>
+
+ <template #body="{ list }">
+ <tr
+ v-for="user in list"
+ :key="user.uid"
+ class="text-secondaryDark hover:bg-divider hover:cursor-pointer rounded-xl"
+ @click="goToUserDetails(user.uid)"
+ >
+ <td class="py-2 px-7 max-w-30 truncate">
+ {{ user.uid }}
+ </td>
+
+ <td class="py-2 px-7">
+ <div class="flex items-center space-x-2">
+ <span>
+ {{ user.displayName ?? t('users.unnamed') }}
+ </span>
+
+ <span
+ v-if="user.isAdmin"
+ class="text-xs font-medium px-3 py-0.5 rounded-full bg-green-900 text-green-300"
+ >
+ {{ t('users.admin') }}
+ </span>
+ </div>
+ </td>
- <div v-else class="flex justify-center">{{ t('users.no_users') }}</div>
+ <td class="py-2 px-7">
+ {{ user.email }}
+ </td>
+
+ <td class="py-2 px-7">
+ {{ getCreatedDate(user.createdOn) }}
+ <div class="text-gray-400 text-tiny">
+ {{ getCreatedTime(user.createdOn) }}
+ </div>
+ </td>
+
+ <td @click.stop>
+ <div class="relative">
+ <tippy interactive trigger="click" theme="popover">
+ <HoppButtonSecondary
+ v-tippy="{ theme: 'tooltip' }"
+ :icon="IconMoreHorizontal"
+ />
+ <template #content="{ hide }">
+ <div
+ ref="tippyActions"
+ class="flex flex-col focus:outline-none"
+ tabindex="0"
+ @keyup.escape="hide()"
+ >
+ <HoppSmartItem
+ :icon="user.isAdmin ? IconUserMinus : IconUserCheck"
+ :label="
+ user.isAdmin
+ ? t('users.remove_admin_status')
+ : t('users.make_admin')
+ "
+ class="!hover:bg-emerald-600"
+ @click="
+ () => {
+ user.isAdmin
+ ? makeAdminToUser(user.uid)
+ : makeUserAdmin(user.uid);
+ hide();
+ }
+ "
+ />
+ <HoppSmartItem
+ v-if="!user.isAdmin"
+ :icon="IconTrash"
+ :label="t('users.delete_user')"
+ class="!hover:bg-red-600"
+ @click="
+ () => {
+ deleteUser(user.uid);
+ hide();
+ }
+ "
+ />
+ </div>
+ </template>
+ </tippy>
+ </div>
+ </td>
+ </tr>
+ </template>
+ </HoppSmartTable>
+
+ <div v-else-if="usersList.length === 0" class="flex justify-center">
+ {{ t('users.no_users') }}
+ </div>
<div
v-if="hasNextPage && usersList.length >= usersPerPage"
@@ -82,6 +173,7 @@
</template>
<script setup lang="ts">
+import { format } from 'date-fns';
import { ref, watch } from 'vue';
import { useMutation } from '@urql/vue';
import {
@@ -96,8 +188,16 @@ import { useRoute, useRouter } from 'vue-router';
import { useToast } from '~/composables/toast';
import { HoppButtonSecondary } from '@hoppscotch/ui';
import IconAddUser from '~icons/lucide/user-plus';
+import IconTrash from '~icons/lucide/trash';
+import IconUserMinus from '~icons/lucide/user-minus';
+import IconUserCheck from '~icons/lucide/user-check';
+import IconMoreHorizontal from '~icons/lucide/more-horizontal';
import { useI18n } from '~/composables/i18n';
+// Get Proper Date Formats
+const getCreatedDate = (date: string) => format(new Date(date), 'dd-MM-yyyy');
+const getCreatedTime = (date: string) => format(new Date(date), 'hh:mm a');
+
const t = useI18n();
const toast = useToast();
@@ -141,9 +241,7 @@ const sendInvite = async (email: string) => {
// Go to Individual User Details Page
const route = useRoute();
const router = useRouter();
-const goToUserDetails = (uid: string) => {
- router.push('/users/' + uid);
-};
+const goToUserDetails = (uid: string) => router.push('/users/' + uid);
watch(
() => route.params.id,
diff --git a/packages/hoppscotch-sh-admin/src/pages/users/invited.vue b/packages/hoppscotch-sh-admin/src/pages/users/invited.vue
index 028e0086e..5e738daf3 100644
--- a/packages/hoppscotch-sh-admin/src/pages/users/invited.vue
+++ b/packages/hoppscotch-sh-admin/src/pages/users/invited.vue
@@ -12,71 +12,34 @@
<div class="flex flex-col">
<div class="py-2 overflow-x-auto">
- <div>
- <div v-if="fetching" class="flex justify-center">
- <HoppSmartSpinner />
- </div>
- <div v-else-if="error || invitedUsers === undefined">
- <p class="text-xl">{{ t('users.no_invite') }}</p>
- </div>
+ <div v-if="fetching" class="flex justify-center">
+ <HoppSmartSpinner />
+ </div>
- <table v-else class="w-full text-left">
- <thead>
- <tr
- class="text-secondary border-b border-dividerDark text-sm text-left"
- >
- <th class="px-3 pb-3">{{ t('users.admin_id') }}</th>
- <th class="px-3 pb-3">{{ t('users.admin_email') }}</th>
- <th class="px-3 pb-3">{{ t('users.invitee_email') }}</th>
- <th class="px-3 pb-3">{{ t('users.invited_on') }}</th>
- </tr>
- </thead>
- <tbody class="divide-y divide-divider">
- <tr
- v-if="invitedUsers.length === 0"
- class="text-secondaryDark py-4"
- >
- <div class="py-6 px-3">{{ t('users.no_invite') }}</div>
- </tr>
- <tr
- v-else
- v-for="(user, index) in invitedUsers"
- :key="index"
- class="text-secondaryDark hover:bg-zinc-800 hover:cursor-pointer rounded-xl"
- >
- <td class="py-2 px-3 max-w-36">
- <div class="flex">
- <span class="truncate">
- {{ user?.adminUid }}
- </span>
- </div>
- </td>
- <td class="py-2 px-3">
- <span class="flex items-center">
- {{ user?.adminEmail }}
- </span>
- </td>
- <td class="py-2 px-3 max-w-52">
- <div class="flex">
- <span class="truncate">
- {{ user?.inviteeEmail }}
- </span>
- </div>
- </td>
- <td class="py-2 px-3">
- <div class="flex items-center">
- <div class="flex flex-col">
- {{ getCreatedDate(user?.invitedOn) }}
- <div class="text-gray-400 text-xs">
- {{ getCreatedTime(user?.invitedOn) }}
- </div>
- </div>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
+ <div v-else-if="error" class="text-xl">
+ {{ t('users.invite_load_list_error') }}
</div>
+
+ <HoppSmartTable
+ v-else-if="invitedUsers?.length"
+ :list="invitedUsers"
+ :headings="headings"
+ >
+ <template #invitedOn="{ item }">
+ <div v-if="item" class="pr-2 truncate">
+ <span class="truncate">
+ {{ getCreatedDate(item.invitedOn) }}
+ </span>
+
+ <div class="text-gray-400 text-tiny">
+ {{ getCreatedTime(item.invitedOn) }}
+ </div>
+ </div>
+ <span v-else> - </span>
+ </template>
+ </HoppSmartTable>
+
+ <div v-else class="text-lg">{{ t('users.no_invite') }}</div>
</div>
</div>
</div>
@@ -102,4 +65,12 @@ const getCreatedTime = (date: string) => format(new Date(date), 'hh:mm a');
// Get Invited Users
const { fetching, error, data } = useQuery({ query: InvitedUsersDocument });
const invitedUsers = computed(() => data?.value?.infra.invitedUsers);
+
+// Table Headings
+const headings = [
+ { key: 'adminUid', label: t('users.admin_id') },
+ { key: 'adminEmail', label: t('users.admin_email') },
+ { key: 'inviteeEmail', label: t('users.invitee_email') },
+ { key: 'invitedOn', label: t('users.invited_on') },
+];
</script>
diff --git a/packages/hoppscotch-ui/src/components/smart/Table.vue b/packages/hoppscotch-ui/src/components/smart/Table.vue
new file mode 100644
index 000000000..ab283c83e
--- /dev/null
+++ b/packages/hoppscotch-ui/src/components/smart/Table.vue
@@ -0,0 +1,69 @@
+<template>
+ <div class="overflow-auto rounded-md border border-dividerDark shadow-md">
+ <table class="w-full">
+ <thead>
+ <slot name="head">
+ <tr
+ class="text-secondary border-b border-dividerDark text-sm text-left bg-primaryLight"
+ >
+ <th v-for="th in headings" scope="col" class="px-6 py-3">
+ {{ th.label ?? th.key }}
+ </th>
+ </tr>
+ </slot>
+ </thead>
+
+ <tbody class="divide-y divide-divider">
+ <!-- We are using slot props for future proofing so that in future, we can implement features like filtering -->
+ <slot name="body" :list="list">
+ <tr
+ v-for="(rowData, rowIndex) in list"
+ :key="rowIndex"
+ class="text-secondaryDark hover:bg-divider hover:cursor-pointer rounded-xl"
+ :class="{ 'divide-x divide-divider': showYBorder }"
+ >
+ <td
+ v-for="cellHeading in headings"
+ :key="cellHeading.key"
+ @click="!cellHeading.preventClick && onRowClicked(rowData)"
+ class="max-w-40 pl-6 py-1"
+ >
+ <!-- Dynamic column slot -->
+ <slot :name="cellHeading.key" :item="rowData">
+ <!-- Generic implementation of the column -->
+ <div class="flex flex-col truncate">
+ <span class="truncate">
+ {{ rowData[cellHeading.key] ?? "-" }}
+ </span>
+ </div>
+ </slot>
+ </td>
+ </tr>
+ </slot>
+ </tbody>
+ </table>
+ </div>
+</template>
+
+<script lang="ts" setup generic="Item extends Record<string, unknown>">
+export type CellHeading = {
+ key: string
+ label?: string
+ preventClick?: boolean
+}
+
+defineProps<{
+ /** Whether to show the vertical border between columns */
+ showYBorder?: boolean
+ /** The list of items to be displayed in the table */
+ list?: Item[]
+ /** The headings of the table */
+ headings?: CellHeading[]
+}>()
+
+const emit = defineEmits<{
+ (event: "onRowClicked", item: Item): void
+}>()
+
+const onRowClicked = (item: Item) => emit("onRowClicked", item)
+</script>
diff --git a/packages/hoppscotch-ui/src/components/smart/index.ts b/packages/hoppscotch-ui/src/components/smart/index.ts
index 157124566..81d04c985 100644
--- a/packages/hoppscotch-ui/src/components/smart/index.ts
+++ b/packages/hoppscotch-ui/src/components/smart/index.ts
@@ -16,6 +16,7 @@ export { default as HoppSmartSlideOver } from "./SlideOver.vue"
export { default as HoppSmartSpinner } from "./Spinner.vue"
export { default as HoppSmartTab } from "./Tab.vue"
export { default as HoppSmartTabs } from "./Tabs.vue"
+export { default as HoppSmartTable } from "./Table.vue"
export { default as HoppSmartToggle } from "./Toggle.vue"
export { default as HoppSmartWindow } from "./Window.vue"
export { default as HoppSmartWindows } from "./Windows.vue"
diff --git a/packages/hoppscotch-ui/src/stories/Table.story.vue b/packages/hoppscotch-ui/src/stories/Table.story.vue
new file mode 100644
index 000000000..d123a7bf9
--- /dev/null
+++ b/packages/hoppscotch-ui/src/stories/Table.story.vue
@@ -0,0 +1,69 @@
+<template>
+ <Story title="Table">
+ <Variant title="General">
+ <HoppSmartTable :list="list" :headings="headings" />
+ </Variant>
+ <Variant title="Custom">
+ <HoppSmartTable>
+ <template #head>
+ <tr
+ class="text-secondary border-b border-dividerDark text-sm text-left bg-primaryLight"
+ >
+ <th
+ v-for="heading in headings"
+ :key="heading.key"
+ scope="col"
+ class="px-6 py-3"
+ >
+ {{ heading.label }}
+ </th>
+ </tr>
+ </template>
+
+ <template #body>
+ <tr
+ v-for="item in list"
+ :key="item.id"
+ class="text-secondaryDark hover:bg-divider hover:cursor-pointer rounded-xl"
+ >
+ <td
+ v-for="cellHeading in headings"
+ :key="cellHeading.key"
+ class="max-w-40 pl-6 py-1"
+ >
+ {{ item[cellHeading.key] ?? "-" }}
+ </td>
+ </tr>
+ </template>
+ </HoppSmartTable>
+ </Variant>
+ </Story>
+</template>
+
+<script setup lang="ts">
+import { HoppSmartTable } from "../components/smart"
+import { CellHeading } from "~/components/smart/Table.vue"
+
+// Table Headings
+const headings: CellHeading[] = [
+ { key: "id", label: "ID" },
+ { key: "name", label: "Name" },
+ { key: "members", label: "Members" },
+ { key: "role", label: "Role" },
+]
+
+const list: Record<string, string | number>[] = [
+ {
+ id: "123455",
+ name: "Joel",
+ members: 10,
+ role: "Frontend Engineer",
+ },
+ {
+ id: "123456",
+ name: "Anwar",
+ members: 12,
+ role: "Frontend Engineer",
+ },
+]
+</script>