-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add NotificationsClientTable component with store and API integ…
…ration - Created a new NotificationsClientsTable.vue component to display `notifications client` data. - Implemented a new useNotificationsClientsStore for handling the API calls related to `notifications client` data. - Updated `customFetch.ts` to include the new API endpoints and methods for fetching `notifications client` data. - Added translations for the `NotificationsClientsTable.vue` component in the en.json file. - Applied code styling updates in `notifications.vue` and added the ClientsTab to display the `NotificationsClientsTable.vue` component. See: BEDS-324
- Loading branch information
1 parent
4d5ed1e
commit 488fc7c
Showing
5 changed files
with
253 additions
and
1 deletion.
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
frontend/components/notifications/NotificationsClientsTable.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<script setup lang="ts"> | ||
import { useNotificationsClientsStore } from '~/stores/notifications/useNotificationsClientsStore'; | ||
import type { Cursor } from '~/types/datatable' | ||
defineEmits<{ (e: 'openDialog'): void }>() | ||
const { width } = useWindowSize() | ||
const cursor = ref<Cursor>() | ||
const pageSize = ref<number>(10) | ||
const { t: $t } = useTranslation() | ||
const { | ||
clientsNotifications, | ||
isLoading, | ||
onSort, | ||
query, | ||
setCursor, | ||
setPageSize, | ||
setSearch, | ||
} = useNotificationsClientsStore() | ||
const colsVisible = computed(() => { | ||
return { | ||
footer: 1024, | ||
threshold: width.value > 830, | ||
} | ||
}) | ||
const clientLink = computed(() => { | ||
// TODO: implement client link when it's available from the API | ||
// TODO: Test the endpoints | ||
// return `/client/${data.clientId}` | ||
return '/notifications' | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<BcTableControl | ||
:title="$t('notifications.clients.title')" | ||
:search-placeholder="$t('notifications.dashboards.search_placeholder')" | ||
@set-search="setSearch" | ||
> | ||
<template #table> | ||
<ClientOnly fallback-tag="span"> | ||
<BcTable | ||
:data="clientsNotifications" | ||
data-key="notification_id" | ||
:cursor | ||
:page-size | ||
:selected-sort="query?.sort" | ||
:loading="isLoading" | ||
:add-spacer="true" | ||
@set-cursor="setCursor" | ||
@sort="onSort" | ||
@set-page-size="setPageSize" | ||
> | ||
<Column | ||
field="machine_name" | ||
sortable | ||
header-class="col-client-name" | ||
body-class="col-client-name" | ||
:header="$t('notifications.clients.col.client_name')" | ||
> | ||
<template #body="slotProps"> | ||
<pre> | ||
{{ slotProps.data.client_name }} | ||
</pre> | ||
</template> | ||
</Column> | ||
<Column | ||
field="machine_name" | ||
header-class="col-client-name" | ||
body-class="col-client-name" | ||
:header="$t('notifications.clients.col.version')" | ||
> | ||
<template #body="slotProps"> | ||
<BcLink | ||
:to="clientLink" | ||
class="link link-dashboard" | ||
target="_blank" | ||
> | ||
{{ slotProps.data.version }} | ||
</BcLink> | ||
</template> | ||
</Column> | ||
<Column | ||
field="timestamp" | ||
sortable | ||
header-class="col-age" | ||
body-class="col-age" | ||
> | ||
<template #header> | ||
<BcTableAgeHeader /> | ||
</template> | ||
<template #body="slotProps"> | ||
<BcFormatTimePassed | ||
:value="slotProps.data.timestamp" | ||
type="go-timestamp" | ||
/> | ||
</template> | ||
</Column> | ||
<template #empty> | ||
<NotificationsDashboardsTableEmpty | ||
v-if="!clientsNotifications?.data.length" | ||
@open-dialog="$emit('openDialog')" | ||
/> | ||
</template> | ||
<!-- TODO: implement number of clients subscriptions --> | ||
<template #bc-table-footer-right> | ||
<template v-if="colsVisible"> | ||
{{ $t('notifications.clients.footer.subscriptions', { count: 3 }) }} | ||
</template> | ||
</template> | ||
</BcTable> | ||
</ClientOnly> | ||
</template> | ||
</BcTableControl> | ||
</div> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
@use "~/assets/css/utils.scss"; | ||
$breakpoint-sm: 630px; | ||
$breakpoint-md: 780px; | ||
$breakpoint-lg: 1024px; | ||
:deep(.col-client-name) { | ||
*:not([data-pc-section="sort"]) { | ||
@include utils.truncate-text; | ||
} | ||
@media (max-width: $breakpoint-lg) { | ||
@include utils.set-all-width(240px); | ||
} | ||
@media (max-width: $breakpoint-md) { | ||
@include utils.set-all-width(200px); | ||
} | ||
@media (max-width: $breakpoint-sm) { | ||
@include utils.set-all-width(106px); | ||
} | ||
} | ||
:deep(.col-age) { | ||
@media (max-width: $breakpoint-lg) { | ||
@include utils.set-all-width(140px); | ||
} | ||
@media (max-width: $breakpoint-sm) { | ||
@include utils.set-all-width(78px); | ||
} | ||
*:not([data-pc-section="sort"]) { | ||
@include utils.truncate-text; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
frontend/stores/notifications/useNotificationsClientsStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { defineStore } from 'pinia' | ||
import type { | ||
InternalGetUserNotificationClientsResponse, NotificationClientsTableRow | ||
Check failure on line 3 in frontend/stores/notifications/useNotificationsClientsStore.ts GitHub Actions / lint and typecheck
|
||
} from '~/types/api/notifications' | ||
import { API_PATH } from '~/types/customFetch' | ||
import type { TableQueryParams } from '~/types/datatable' | ||
|
||
const notificationsClientsStore = defineStore('notifications-clients-store', () => { | ||
const data = ref<InternalGetUserNotificationClientsResponse | undefined>() | ||
return { data } | ||
}) | ||
|
||
export function useNotificationsClientsStore() { | ||
const { isLoggedIn } = useUserStore() | ||
|
||
const { fetch } = useCustomFetch() | ||
const { data } = storeToRefs(notificationsClientsStore()) | ||
const { | ||
cursor, isStoredQuery, onSort, pageSize, pendingQuery, query, setCursor, setPageSize, setSearch, setStoredQuery, | ||
} = useTableQuery({ | ||
limit: 10, sort: 'timestamp:desc', | ||
}, 10) | ||
const isLoading = ref(false) | ||
|
||
async function loadClientsNotifications(q: TableQueryParams) { | ||
isLoading.value = true | ||
setStoredQuery(q) | ||
try { | ||
const result = await fetch<InternalGetUserNotificationClientsResponse>( | ||
API_PATH.NOTIFICATIONS_CLIENTS, | ||
undefined, | ||
undefined, | ||
q, | ||
) | ||
|
||
isLoading.value = false | ||
if (!isStoredQuery(q)) { | ||
return // in case some query params change while loading | ||
} | ||
|
||
data.value = result | ||
} | ||
catch (e) { | ||
data.value = undefined | ||
isLoading.value = false | ||
} | ||
return data.value | ||
} | ||
|
||
const clientsNotifications = computed(() => { | ||
return data.value | ||
}) | ||
|
||
watch(query, (q) => { | ||
if (q) { | ||
isLoggedIn.value && loadClientsNotifications(q) | ||
} | ||
}, { immediate: true }) | ||
|
||
return { | ||
clientsNotifications, | ||
cursor, | ||
isLoading, | ||
onSort, | ||
pageSize, | ||
query: pendingQuery, | ||
setCursor, | ||
setPageSize, | ||
setSearch, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters