@innertia-solutions/innertia-nuxt 0.1.77 → 0.1.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/__tests__/version.test.ts +15 -0
- package/build/version.ts +12 -1
- package/components/App/NotificationHistory.vue +176 -0
- package/components/App/VersionBadge.vue +50 -0
- package/composables/useNotificationHistory/index.ts +50 -0
- package/composables/useNotificationHistory/internal/__tests__/format.test.ts +51 -0
- package/composables/useNotificationHistory/internal/format.ts +66 -0
- package/nuxt.config.ts +1 -1
- package/package.json +1 -1
- package/utils/__tests__/version-string.test.ts +36 -0
- package/utils/version-string.ts +34 -0
|
@@ -42,4 +42,19 @@ describe('collectBuildVersion', () => {
|
|
|
42
42
|
expect(v.commit).toBe('')
|
|
43
43
|
expect(Number.isNaN(Date.parse(v.buildDate))).toBe(false)
|
|
44
44
|
})
|
|
45
|
+
|
|
46
|
+
it('sin APP_VERSION ni build-info usa VERSION del monorepo (../VERSION) como vX.Y.Z-dev', () => {
|
|
47
|
+
const front = join(root, 'frontend')
|
|
48
|
+
pkg(front, { name: 'acme-front', version: '9.9.9' })
|
|
49
|
+
writeFileSync(join(root, 'VERSION'), '1.0.2\n')
|
|
50
|
+
expect(collectBuildVersion(front, {}, { git: false, packages: [] }).version).toBe('v1.0.2-dev')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('APP_VERSION tiene precedencia sobre VERSION', () => {
|
|
54
|
+
const front = join(root, 'frontend')
|
|
55
|
+
pkg(front, { name: 'acme-front' })
|
|
56
|
+
writeFileSync(join(root, 'VERSION'), '1.0.2\n')
|
|
57
|
+
expect(collectBuildVersion(front, { APP_VERSION: 'v1.0.2-20261111.3' }, { git: false, packages: [] }).version)
|
|
58
|
+
.toBe('v1.0.2-20261111.3')
|
|
59
|
+
})
|
|
45
60
|
})
|
package/build/version.ts
CHANGED
|
@@ -51,6 +51,17 @@ function gitCommit(rootDir: string): string {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/** Dev local: VERSION en la raíz del monorepo (padre del front) → "vX.Y.Z-dev". */
|
|
55
|
+
function devVersion(rootDir: string): string {
|
|
56
|
+
try {
|
|
57
|
+
const path = join(rootDir, '..', 'VERSION')
|
|
58
|
+
const semver = existsSync(path) ? readFileSync(path, 'utf8').trim() : ''
|
|
59
|
+
return /^\d+\.\d+\.\d+$/.test(semver) ? `v${semver}-dev` : ''
|
|
60
|
+
} catch {
|
|
61
|
+
return ''
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
54
65
|
/**
|
|
55
66
|
* Prioridad por campo: env de build (APP_COMMIT / APP_BUILD_DATE / APP_VERSION)
|
|
56
67
|
* → build-info.json en rootDir (lo escribe el Dockerfile) → fallback
|
|
@@ -67,7 +78,7 @@ export function collectBuildVersion(
|
|
|
67
78
|
|
|
68
79
|
return {
|
|
69
80
|
app: str(product.name),
|
|
70
|
-
version: str(env.APP_VERSION) || str(info.version) || str(product.version),
|
|
81
|
+
version: str(env.APP_VERSION) || str(info.version) || devVersion(rootDir) || str(product.version),
|
|
71
82
|
commit: str(env.APP_COMMIT) || str(info.commit) || (opts.git === false ? '' : gitCommit(rootDir)),
|
|
72
83
|
buildDate: str(env.APP_BUILD_DATE) || str(info.build_date) || new Date().toISOString(),
|
|
73
84
|
packages: readPackageVersions(rootDir, opts.packages ?? DEFAULT_FRONT_PACKAGES),
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { IconBellOff, IconChecks, IconCheck, IconTrash, IconChevronLeft, IconChevronRight, IconArrowUpRight } from '@tabler/icons-vue'
|
|
3
|
+
import { groupByDay, timeAgo, defaultNotificationLink, type HistoryFilter, type NotificationItem } from '../../composables/useNotificationHistory/internal/format'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* App.NotificationHistory — vista "ver todas" del centro de notificaciones:
|
|
7
|
+
* lista paginada agrupada por día, filtro Todas / No leídas, marcar leída
|
|
8
|
+
* (una o todas), eliminar una y borrar las leídas.
|
|
9
|
+
*
|
|
10
|
+
* Backend: notification center de innertia-laravel (useNotificationHistory).
|
|
11
|
+
* Cada producto monta la página (p. ej. /backoffice/notifications) y puede
|
|
12
|
+
* pasar `resolveLink` para mapear el payload de sus eventos a una ruta.
|
|
13
|
+
*
|
|
14
|
+
* <App.NotificationHistory :resolve-link="(n) => n.data?.project_id ? `/projects/${n.data.project_id}` : null" />
|
|
15
|
+
*/
|
|
16
|
+
const props = withDefaults(defineProps<{
|
|
17
|
+
perPage?: number
|
|
18
|
+
/** Ruta destino al abrir una notificación; null = no navega. Default: data.link → data.url. */
|
|
19
|
+
resolveLink?: (n: NotificationItem) => string | null | undefined
|
|
20
|
+
}>(), { perPage: 20, resolveLink: undefined })
|
|
21
|
+
|
|
22
|
+
const emit = defineEmits<{ (e: 'open', n: NotificationItem): void }>()
|
|
23
|
+
|
|
24
|
+
const filter = ref<HistoryFilter>('all')
|
|
25
|
+
const page = ref(1)
|
|
26
|
+
watch(filter, () => { page.value = 1 })
|
|
27
|
+
|
|
28
|
+
const { list, markRead, markAllRead, remove, removeRead } = useNotificationHistory()
|
|
29
|
+
const { data, isLoading, isError, refetch } = list(() => ({ filter: filter.value, page: page.value, perPage: props.perPage }))
|
|
30
|
+
const { mutateAsync: doMarkRead } = markRead()
|
|
31
|
+
const { mutate: doMarkAll, isPending: markingAll } = markAllRead()
|
|
32
|
+
const { mutate: doRemove } = remove()
|
|
33
|
+
const { mutate: doRemoveRead, isPending: removingRead } = removeRead()
|
|
34
|
+
const { confirm } = useModal()
|
|
35
|
+
|
|
36
|
+
const items = computed<NotificationItem[]>(() => (data.value as any)?.data ?? [])
|
|
37
|
+
const unread = computed<number>(() => (data.value as any)?.unread ?? 0)
|
|
38
|
+
const total = computed<number>(() => (data.value as any)?.total ?? 0)
|
|
39
|
+
const lastPage = computed<number>(() => (data.value as any)?.last_page ?? 1)
|
|
40
|
+
const groups = computed(() => groupByDay(items.value))
|
|
41
|
+
|
|
42
|
+
// Si la página actual quedó vacía (p. ej. tras marcar/borrar), retrocede una.
|
|
43
|
+
watch([items, lastPage], () => {
|
|
44
|
+
if (!items.value.length && page.value > 1 && page.value > lastPage.value) page.value = lastPage.value
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const filterOptions = computed(() => [
|
|
48
|
+
{ value: 'all', label: 'Todas' },
|
|
49
|
+
{ value: 'unread', label: unread.value ? `No leídas (${unread.value})` : 'No leídas' },
|
|
50
|
+
])
|
|
51
|
+
|
|
52
|
+
const linkOf = (n: NotificationItem) => (props.resolveLink ? props.resolveLink(n) : defaultNotificationLink(n)) ?? null
|
|
53
|
+
|
|
54
|
+
async function open(n: NotificationItem) {
|
|
55
|
+
emit('open', n)
|
|
56
|
+
if (!n.read_at) { try { await doMarkRead(n.id) } catch { /* noop */ } }
|
|
57
|
+
const link = linkOf(n)
|
|
58
|
+
if (link) navigateTo(link)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function removeOne(n: NotificationItem) {
|
|
62
|
+
if (await confirm({ severity: 'danger', message: '¿Eliminar esta notificación?' })) doRemove(n.id)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function clearRead() {
|
|
66
|
+
if (await confirm({ severity: 'danger', message: '¿Borrar todas las notificaciones leídas? Esta acción no se puede deshacer.' })) doRemoveRead()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const initial = (t?: string | null) => (t || '?').trim().charAt(0).toUpperCase()
|
|
70
|
+
const fullDate = (iso?: string | null) => iso ? new Date(iso).toLocaleString('es-CL', { dateStyle: 'medium', timeStyle: 'short' }) : ''
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<template>
|
|
74
|
+
<div class="bg-card border border-card-line rounded-card overflow-hidden">
|
|
75
|
+
<!-- Toolbar -->
|
|
76
|
+
<div class="flex flex-wrap items-center justify-between gap-3 px-4 sm:px-5 py-3 border-b border-card-divider">
|
|
77
|
+
<App.SegmentedControl v-model="filter" :options="filterOptions" />
|
|
78
|
+
<div class="flex items-center gap-2">
|
|
79
|
+
<button
|
|
80
|
+
type="button"
|
|
81
|
+
class="inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-sm font-medium text-muted-foreground-1 hover:bg-muted-hover hover:text-foreground disabled:opacity-50 disabled:pointer-events-none"
|
|
82
|
+
:disabled="!unread || markingAll"
|
|
83
|
+
@click="doMarkAll()"
|
|
84
|
+
>
|
|
85
|
+
<IconChecks class="size-4" /> Marcar todas como leídas
|
|
86
|
+
</button>
|
|
87
|
+
<button
|
|
88
|
+
type="button"
|
|
89
|
+
class="inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-sm font-medium text-red-600 hover:bg-red-500/10 disabled:opacity-50 disabled:pointer-events-none"
|
|
90
|
+
:disabled="removingRead || (filter === 'all' && total > 0 && unread === total)"
|
|
91
|
+
@click="clearRead"
|
|
92
|
+
>
|
|
93
|
+
<IconTrash class="size-4" /> Borrar leídas
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<!-- Loading -->
|
|
99
|
+
<div v-if="isLoading" class="p-5 space-y-5">
|
|
100
|
+
<div v-for="i in 5" :key="i" class="flex gap-3 animate-pulse">
|
|
101
|
+
<span class="size-9 rounded-full bg-surface-1 shrink-0" />
|
|
102
|
+
<div class="flex-1 space-y-2"><span class="block h-3 w-1/4 bg-surface-1 rounded" /><span class="block h-3 w-2/3 bg-surface-1 rounded" /></div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<!-- Error -->
|
|
107
|
+
<div v-else-if="isError" class="py-14 text-center text-sm text-muted-foreground">
|
|
108
|
+
No se pudieron cargar las notificaciones.
|
|
109
|
+
<button type="button" class="ms-1 text-primary hover:underline" @click="refetch()">Reintentar</button>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<!-- Vacío -->
|
|
113
|
+
<div v-else-if="!items.length" class="py-16 flex flex-col items-center text-center text-muted-foreground">
|
|
114
|
+
<IconBellOff class="size-10 mb-3 opacity-30" :stroke-width="1.5" />
|
|
115
|
+
<p class="text-sm font-medium text-foreground">{{ filter === 'unread' ? 'Estás al día' : 'No tienes notificaciones' }}</p>
|
|
116
|
+
<p class="text-sm">{{ filter === 'unread' ? 'No hay notificaciones sin leer.' : 'Aquí verás el historial de avisos del sistema.' }}</p>
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
<!-- Lista agrupada por día -->
|
|
120
|
+
<div v-else>
|
|
121
|
+
<section v-for="g in groups" :key="g.key">
|
|
122
|
+
<h3 class="px-4 sm:px-5 py-2 text-xs font-medium uppercase tracking-wide text-muted-foreground bg-muted/40 border-b border-card-divider first-letter:uppercase">{{ g.label }}</h3>
|
|
123
|
+
<ul class="divide-y divide-card-divider">
|
|
124
|
+
<li
|
|
125
|
+
v-for="n in g.items" :key="n.id"
|
|
126
|
+
class="group relative flex gap-x-3 px-4 sm:px-5 py-3.5 cursor-pointer hover:bg-muted-hover transition-colors"
|
|
127
|
+
:class="!n.read_at && 'bg-primary/5'"
|
|
128
|
+
@click="open(n)"
|
|
129
|
+
>
|
|
130
|
+
<div class="relative shrink-0">
|
|
131
|
+
<span class="flex items-center justify-center size-9 rounded-full bg-primary/10 text-primary text-sm font-semibold">{{ initial(n.title) }}</span>
|
|
132
|
+
<span v-if="!n.read_at" class="absolute -top-0.5 -start-0.5 size-2.5 bg-primary rounded-full ring-2 ring-card" />
|
|
133
|
+
</div>
|
|
134
|
+
<div class="grow min-w-0">
|
|
135
|
+
<div class="flex items-baseline gap-2">
|
|
136
|
+
<p class="text-sm text-foreground truncate" :class="!n.read_at ? 'font-semibold' : 'font-medium'">{{ n.title || 'Notificación' }}</p>
|
|
137
|
+
<IconArrowUpRight v-if="linkOf(n)" class="size-3.5 shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100" />
|
|
138
|
+
</div>
|
|
139
|
+
<p v-if="n.body" class="text-sm text-muted-foreground-1 line-clamp-2">{{ n.body }}</p>
|
|
140
|
+
<p class="mt-0.5 text-xs text-muted-foreground" :title="fullDate(n.created_at)">{{ timeAgo(n.created_at) }}</p>
|
|
141
|
+
</div>
|
|
142
|
+
<div class="shrink-0 flex items-start gap-1 sm:opacity-0 sm:group-hover:opacity-100 sm:focus-within:opacity-100 transition-opacity">
|
|
143
|
+
<button
|
|
144
|
+
v-if="!n.read_at" type="button" title="Marcar como leída" aria-label="Marcar como leída"
|
|
145
|
+
class="size-8 inline-flex items-center justify-center rounded-lg text-muted-foreground-1 hover:bg-card hover:text-foreground"
|
|
146
|
+
@click.stop="doMarkRead(n.id)"
|
|
147
|
+
><IconCheck class="size-4" /></button>
|
|
148
|
+
<button
|
|
149
|
+
type="button" title="Eliminar" aria-label="Eliminar"
|
|
150
|
+
class="size-8 inline-flex items-center justify-center rounded-lg text-muted-foreground-1 hover:bg-red-500/10 hover:text-red-600"
|
|
151
|
+
@click.stop="removeOne(n)"
|
|
152
|
+
><IconTrash class="size-4" /></button>
|
|
153
|
+
</div>
|
|
154
|
+
</li>
|
|
155
|
+
</ul>
|
|
156
|
+
</section>
|
|
157
|
+
</div>
|
|
158
|
+
|
|
159
|
+
<!-- Paginación -->
|
|
160
|
+
<div v-if="lastPage > 1" class="flex items-center justify-between gap-3 px-4 sm:px-5 py-3 border-t border-card-divider text-sm text-muted-foreground-1">
|
|
161
|
+
<span>Página {{ page }} de {{ lastPage }} · {{ total }} {{ total === 1 ? 'notificación' : 'notificaciones' }}</span>
|
|
162
|
+
<div class="flex items-center gap-1">
|
|
163
|
+
<button
|
|
164
|
+
type="button" aria-label="Página anterior"
|
|
165
|
+
class="size-8 inline-flex items-center justify-center rounded-lg border border-card-line hover:bg-muted-hover disabled:opacity-50 disabled:pointer-events-none"
|
|
166
|
+
:disabled="page <= 1" @click="page--"
|
|
167
|
+
><IconChevronLeft class="size-4" /></button>
|
|
168
|
+
<button
|
|
169
|
+
type="button" aria-label="Página siguiente"
|
|
170
|
+
class="size-8 inline-flex items-center justify-center rounded-lg border border-card-line hover:bg-muted-hover disabled:opacity-50 disabled:pointer-events-none"
|
|
171
|
+
:disabled="page >= lastPage" @click="page++"
|
|
172
|
+
><IconChevronRight class="size-4" /></button>
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
</template>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
/**
|
|
3
|
+
* <AppVersionBadge /> — versión desplegada del front, visible en shells y login.
|
|
4
|
+
* Lee /_version (público). Muestra "v1.0.2 · QA #7"; tooltip con versión completa,
|
|
5
|
+
* commit y fecha de build. Con `to`, enlaza al detalle (p. ej. la página con <AppVersions />).
|
|
6
|
+
*
|
|
7
|
+
* ```vue
|
|
8
|
+
* <AppVersionBadge />
|
|
9
|
+
* <AppVersionBadge to="/platform" />
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
import { NuxtLink } from '#components'
|
|
13
|
+
import { parseVersion, versionLabel } from '../../utils/version-string'
|
|
14
|
+
|
|
15
|
+
const props = defineProps({
|
|
16
|
+
endpoint: { type: String, default: '/_version' },
|
|
17
|
+
to: { type: String, default: '' },
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const { data } = useFetch(props.endpoint, { server: false, key: `innertia-version-badge:${props.endpoint}` })
|
|
21
|
+
|
|
22
|
+
const parts = computed(() => parseVersion(data.value?.version))
|
|
23
|
+
const label = computed(() => versionLabel(data.value?.version))
|
|
24
|
+
const title = computed(() => {
|
|
25
|
+
const d = data.value
|
|
26
|
+
if (!d) return ''
|
|
27
|
+
const date = d.build_date ? new Date(d.build_date) : null
|
|
28
|
+
return [
|
|
29
|
+
d.version,
|
|
30
|
+
d.commit ? `commit ${d.commit}` : null,
|
|
31
|
+
date && !Number.isNaN(date.getTime()) ? date.toLocaleString() : null,
|
|
32
|
+
].filter(Boolean).join(' · ')
|
|
33
|
+
})
|
|
34
|
+
const tone = computed(() => parts.value?.environment === 'qa'
|
|
35
|
+
? 'text-amber-600 dark:text-amber-400'
|
|
36
|
+
: 'text-muted-foreground')
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<template>
|
|
40
|
+
<component
|
|
41
|
+
:is="to ? NuxtLink : 'span'"
|
|
42
|
+
v-if="label"
|
|
43
|
+
:to="to || undefined"
|
|
44
|
+
:title="title"
|
|
45
|
+
class="inline-flex items-center font-mono text-[11px] leading-none hover:text-foreground"
|
|
46
|
+
:class="tone"
|
|
47
|
+
>
|
|
48
|
+
{{ label }}
|
|
49
|
+
</component>
|
|
50
|
+
</template>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { computed, toValue, type MaybeRefOrGetter } from 'vue'
|
|
2
|
+
import { historyParams, type HistoryFilter } from './internal/format'
|
|
3
|
+
|
|
4
|
+
// Solo se exporta el composable: los helpers de ./internal/format no se
|
|
5
|
+
// auto-importan globalmente (evita choques de nombres en los productos).
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Historial de notificaciones del usuario (vista "ver todas"), sobre el
|
|
9
|
+
* notification center de innertia-laravel (\Innertia\Notifications\Routes):
|
|
10
|
+
* GET notifications ?all=1&page=N&per_page=N → {data,total,unread,current_page,last_page,per_page}
|
|
11
|
+
* PATCH notifications/{id}/read · PATCH notifications/read-all
|
|
12
|
+
* DELETE notifications/{id} · DELETE notifications (borra las leídas)
|
|
13
|
+
*
|
|
14
|
+
* Usa la query key raíz ['notifications'] para que invalidar aquí refresque
|
|
15
|
+
* también la campanita del producto (y viceversa) si comparte el QueryClient.
|
|
16
|
+
* Nombre propio (no useNotifications) para no chocar con composables de producto.
|
|
17
|
+
*/
|
|
18
|
+
export function useNotificationHistory() {
|
|
19
|
+
const api = useApi()
|
|
20
|
+
const queryClient = useQueryClient()
|
|
21
|
+
const invalidate = () => queryClient.invalidateQueries({ queryKey: ['notifications'] })
|
|
22
|
+
|
|
23
|
+
const list = (opts: MaybeRefOrGetter<{ filter: HistoryFilter; page: number; perPage: number }>) => useQuery({
|
|
24
|
+
queryKey: computed(() => ['notifications', 'history', historyParams(toValue(opts))]),
|
|
25
|
+
queryFn: () => api.get('notifications', { params: historyParams(toValue(opts)) }),
|
|
26
|
+
placeholderData: (prev: any) => prev,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const markRead = () => useMutation({
|
|
30
|
+
mutationFn: (id: string) => api.patch(`notifications/${id}/read`),
|
|
31
|
+
onSuccess: invalidate,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const markAllRead = () => useMutation({
|
|
35
|
+
mutationFn: () => api.patch('notifications/read-all'),
|
|
36
|
+
onSuccess: invalidate,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const remove = () => useMutation({
|
|
40
|
+
mutationFn: (id: string) => api.delete(`notifications/${id}`),
|
|
41
|
+
onSuccess: invalidate,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const removeRead = () => useMutation({
|
|
45
|
+
mutationFn: () => api.delete('notifications'),
|
|
46
|
+
onSuccess: invalidate,
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return { list, markRead, markAllRead, remove, removeRead, invalidate }
|
|
50
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { historyParams, groupByDay, timeAgo, defaultNotificationLink } from '../format'
|
|
3
|
+
|
|
4
|
+
const now = new Date('2026-11-10T15:00:00')
|
|
5
|
+
|
|
6
|
+
describe('historyParams', () => {
|
|
7
|
+
it('pide todas (all=1) con página y tamaño', () => {
|
|
8
|
+
expect(historyParams({ filter: 'all', page: 2, perPage: 20 })).toEqual({ all: 1, page: 2, per_page: 20 })
|
|
9
|
+
})
|
|
10
|
+
it('para no leídas omite all (el backend filtra por defecto)', () => {
|
|
11
|
+
expect(historyParams({ filter: 'unread', page: 1, perPage: 20 })).toEqual({ page: 1, per_page: 20 })
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
describe('groupByDay', () => {
|
|
16
|
+
it('agrupa en Hoy / Ayer / fecha, preservando el orden', () => {
|
|
17
|
+
const items = [
|
|
18
|
+
{ id: 'a', created_at: '2026-11-10T14:00:00' },
|
|
19
|
+
{ id: 'b', created_at: '2026-11-10T09:00:00' },
|
|
20
|
+
{ id: 'c', created_at: '2026-11-09T20:00:00' },
|
|
21
|
+
{ id: 'd', created_at: '2026-10-01T10:00:00' },
|
|
22
|
+
]
|
|
23
|
+
const groups = groupByDay(items, now)
|
|
24
|
+
expect(groups.map(g => g.label)).toEqual(['Hoy', 'Ayer', expect.stringContaining('oct')])
|
|
25
|
+
expect(groups[0].items.map(i => i.id)).toEqual(['a', 'b'])
|
|
26
|
+
expect(groups[2].items.map(i => i.id)).toEqual(['d'])
|
|
27
|
+
})
|
|
28
|
+
it('sin fecha cae en un grupo "Sin fecha"', () => {
|
|
29
|
+
expect(groupByDay([{ id: 'x' }], now)[0].label).toBe('Sin fecha')
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('timeAgo', () => {
|
|
34
|
+
it('formatea relativo en español', () => {
|
|
35
|
+
expect(timeAgo('2026-11-10T14:59:30', now)).toBe('hace un momento')
|
|
36
|
+
expect(timeAgo('2026-11-10T14:45:00', now)).toBe('hace 15 min')
|
|
37
|
+
expect(timeAgo('2026-11-10T12:00:00', now)).toBe('hace 3 h')
|
|
38
|
+
expect(timeAgo('2026-11-08T15:00:00', now)).toBe('hace 2 d')
|
|
39
|
+
})
|
|
40
|
+
it('vacío sin fecha', () => {
|
|
41
|
+
expect(timeAgo(null, now)).toBe('')
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('defaultNotificationLink', () => {
|
|
46
|
+
it('usa data.link, luego data.url, si no null', () => {
|
|
47
|
+
expect(defaultNotificationLink({ data: { link: '/a', url: '/b' } })).toBe('/a')
|
|
48
|
+
expect(defaultNotificationLink({ data: { url: '/b' } })).toBe('/b')
|
|
49
|
+
expect(defaultNotificationLink({ data: null })).toBeNull()
|
|
50
|
+
})
|
|
51
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers puros de la vista de historial de notificaciones (sin Nuxt/Vue),
|
|
3
|
+
* testeables en node. Los consume useNotificationHistory / <App.NotificationHistory>.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type HistoryFilter = 'all' | 'unread'
|
|
7
|
+
|
|
8
|
+
export interface NotificationItem {
|
|
9
|
+
id: string
|
|
10
|
+
title?: string | null
|
|
11
|
+
body?: string | null
|
|
12
|
+
data?: Record<string, any> | null
|
|
13
|
+
read_at?: string | null
|
|
14
|
+
created_at?: string | null
|
|
15
|
+
[key: string]: any
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Query params para GET notifications (el backend lista solo no leídas si no va `all`). */
|
|
19
|
+
export function historyParams({ filter, page, perPage }: { filter: HistoryFilter; page: number; perPage: number }) {
|
|
20
|
+
return filter === 'all'
|
|
21
|
+
? { all: 1, page, per_page: perPage }
|
|
22
|
+
: { page, per_page: perPage }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const dayKey = (d: Date) => `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`
|
|
26
|
+
|
|
27
|
+
/** Agrupa (ya ordenadas por fecha desc) en Hoy / Ayer / fecha larga. */
|
|
28
|
+
export function groupByDay<T extends { created_at?: string | null }>(items: T[], now: Date = new Date()) {
|
|
29
|
+
const today = dayKey(now)
|
|
30
|
+
const y = new Date(now); y.setDate(y.getDate() - 1)
|
|
31
|
+
const yesterday = dayKey(y)
|
|
32
|
+
|
|
33
|
+
const groups: { key: string; label: string; items: T[] }[] = []
|
|
34
|
+
for (const item of items) {
|
|
35
|
+
const d = item.created_at ? new Date(item.created_at) : null
|
|
36
|
+
const key = d ? dayKey(d) : 'none'
|
|
37
|
+
let g = groups.find(g => g.key === key)
|
|
38
|
+
if (!g) {
|
|
39
|
+
const label = !d ? 'Sin fecha'
|
|
40
|
+
: key === today ? 'Hoy'
|
|
41
|
+
: key === yesterday ? 'Ayer'
|
|
42
|
+
: d.toLocaleDateString('es-CL', { weekday: 'long', day: 'numeric', month: 'short', year: d.getFullYear() === now.getFullYear() ? undefined : 'numeric' })
|
|
43
|
+
g = { key, label, items: [] }
|
|
44
|
+
groups.push(g)
|
|
45
|
+
}
|
|
46
|
+
g.items.push(item)
|
|
47
|
+
}
|
|
48
|
+
return groups
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** "hace 5 min", "hace 3 h", "hace 2 d" o fecha corta. */
|
|
52
|
+
export function timeAgo(iso: string | null | undefined, now: Date = new Date()) {
|
|
53
|
+
if (!iso) return ''
|
|
54
|
+
const d = new Date(iso)
|
|
55
|
+
const s = Math.floor((now.getTime() - d.getTime()) / 1000)
|
|
56
|
+
if (s < 60) return 'hace un momento'
|
|
57
|
+
const m = Math.floor(s / 60); if (m < 60) return `hace ${m} min`
|
|
58
|
+
const h = Math.floor(m / 60); if (h < 24) return `hace ${h} h`
|
|
59
|
+
const days = Math.floor(h / 24); if (days < 7) return `hace ${days} d`
|
|
60
|
+
return d.toLocaleDateString('es-CL', { day: 'numeric', month: 'short' })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Destino por defecto al abrir una notificación: data.link → data.url → null. */
|
|
64
|
+
export function defaultNotificationLink(n: NotificationItem): string | null {
|
|
65
|
+
return n?.data?.link ?? n?.data?.url ?? null
|
|
66
|
+
}
|
package/nuxt.config.ts
CHANGED
|
@@ -29,7 +29,7 @@ export default defineNuxtConfig({
|
|
|
29
29
|
{ path: './components', pathPrefix: true, prefix: '' },
|
|
30
30
|
],
|
|
31
31
|
imports: {
|
|
32
|
-
dirs: ['stores', 'composables', 'composables/useWorkflow', 'composables/useStorageTestRunner'],
|
|
32
|
+
dirs: ['stores', 'composables', 'composables/useWorkflow', 'composables/useStorageTestRunner', 'composables/useNotificationHistory'],
|
|
33
33
|
presets: [
|
|
34
34
|
{
|
|
35
35
|
from: '@tanstack/vue-query',
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { parseVersion, versionLabel } from '../version-string'
|
|
3
|
+
|
|
4
|
+
describe('parseVersion', () => {
|
|
5
|
+
it('prod', () => {
|
|
6
|
+
expect(parseVersion('v1.0.2-20261111.2')).toEqual({
|
|
7
|
+
raw: 'v1.0.2-20261111.2', semver: '1.0.2', date: '2026-11-11', environment: 'production', sequence: 2,
|
|
8
|
+
})
|
|
9
|
+
})
|
|
10
|
+
it('QA', () => {
|
|
11
|
+
expect(parseVersion('v1.0.2-20261111-QA.7')).toEqual({
|
|
12
|
+
raw: 'v1.0.2-20261111-QA.7', semver: '1.0.2', date: '2026-11-11', environment: 'qa', sequence: 7,
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
it('dev', () => {
|
|
16
|
+
expect(parseVersion('v1.0.2-dev')).toEqual({
|
|
17
|
+
raw: 'v1.0.2-dev', semver: '1.0.2', date: null, environment: 'dev', sequence: null,
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
it.each([null, undefined, '', '1.0.2', 'v.1.0.2-20261111.2', 'v1.0.2-20261111', 'v1.0.2-20261111-qa.1'])(
|
|
21
|
+
'null si no calza: %s', (raw) => {
|
|
22
|
+
expect(parseVersion(raw as any)).toBeNull()
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
describe('versionLabel', () => {
|
|
27
|
+
it('formatea prod, QA y dev', () => {
|
|
28
|
+
expect(versionLabel('v1.0.2-20261111.2')).toBe('v1.0.2 · #2')
|
|
29
|
+
expect(versionLabel('v1.0.2-20261111-QA.7')).toBe('v1.0.2 · QA #7')
|
|
30
|
+
expect(versionLabel('v1.0.2-dev')).toBe('v1.0.2 · dev')
|
|
31
|
+
})
|
|
32
|
+
it('devuelve el string crudo si no calza, vacío si no hay', () => {
|
|
33
|
+
expect(versionLabel('1.4.0')).toBe('1.4.0')
|
|
34
|
+
expect(versionLabel(null)).toBe('')
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Formato estándar de versión de despliegue (espejo de Innertia\Version\VersionString):
|
|
2
|
+
// prod v1.0.2-20261111.2 · QA v1.0.2-20261111-QA.7 · dev v1.0.2-dev
|
|
3
|
+
|
|
4
|
+
export interface VersionParts {
|
|
5
|
+
raw: string
|
|
6
|
+
semver: string
|
|
7
|
+
date: string | null
|
|
8
|
+
environment: 'production' | 'qa' | 'dev'
|
|
9
|
+
sequence: number | null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const PATTERN = /^v(\d+\.\d+\.\d+)-(?:(\d{8})(?:-(QA))?\.(\d+)|(dev))$/
|
|
13
|
+
|
|
14
|
+
export function parseVersion(raw?: string | null): VersionParts | null {
|
|
15
|
+
const value = (raw ?? '').trim()
|
|
16
|
+
const m = PATTERN.exec(value)
|
|
17
|
+
if (!m) return null
|
|
18
|
+
if (m[5] === 'dev') return { raw: value, semver: m[1], date: null, environment: 'dev', sequence: null }
|
|
19
|
+
return {
|
|
20
|
+
raw: value,
|
|
21
|
+
semver: m[1],
|
|
22
|
+
date: `${m[2].slice(0, 4)}-${m[2].slice(4, 6)}-${m[2].slice(6, 8)}`,
|
|
23
|
+
environment: m[3] === 'QA' ? 'qa' : 'production',
|
|
24
|
+
sequence: Number(m[4]),
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Etiqueta corta para UI: "v1.0.2 · QA #7" | "v1.0.2 · #2" | "v1.0.2 · dev" | crudo. */
|
|
29
|
+
export function versionLabel(raw?: string | null): string {
|
|
30
|
+
const p = parseVersion(raw)
|
|
31
|
+
if (!p) return (raw ?? '').trim()
|
|
32
|
+
if (p.environment === 'dev') return `v${p.semver} · dev`
|
|
33
|
+
return `v${p.semver} · ${p.environment === 'qa' ? 'QA ' : ''}#${p.sequence}`
|
|
34
|
+
}
|