Skip to content

Commit

Permalink
feat(audit): fetch events within period
Browse files Browse the repository at this point in the history
  • Loading branch information
mtthp committed Dec 26, 2024
1 parent bb5d181 commit fc4478b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/i18n/locales/en-GB/audit.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"list": {
"description": "Everything that happens in detail.",
"empty": {
"description": "For the term \"{search}\".\nTry to refine your criteria.",
"descriptionFr": "Pour le terme « {search} ».\nEssayez de peaufiner vos critères.",
"title": "Nothing found"
},
"head": {
Expand All @@ -48,6 +50,7 @@
"shortcuts": {
"currentWeek": "This week",
"last30days": "Last 30 days",
"last7days": "Last 7 days",
"sinceFirstDay": "Since always",
"today": "Today"
},
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/fr-FR/audit.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"list": {
"description": "Tout ce qui se passe en détail.",
"empty": {
"description": "Pour le terme « {search} ».\nEssayez de peaufiner vos critères.",
"title": "Rien trouvé"
},
"head": {
Expand All @@ -48,6 +49,7 @@
"shortcuts": {
"currentWeek": "Cette semaine",
"last30days": "30 derniers jours",
"last7days": "7 derniers jours",
"sinceFirstDay": "Depuis toujours",
"today": "Aujourd'hui"
},
Expand Down
9 changes: 7 additions & 2 deletions src/services/api/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export interface AuditEvent {
occurred: string;
}

export const getAllAuditEvents = (): Promise<AuditEvent[]> => {
return HTTP.get('/api/audit').then(({ data }) => data);
export const getAllAuditEvents = (from?: string, to?: string): Promise<AuditEvent[]> => {
return HTTP.get('/api/audit', {
params: {
...(from && { from }),
...(to && { to }),
},
}).then(({ data }) => data);
};
36 changes: 24 additions & 12 deletions src/views/Private/History/HistoryEventsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
<EmptyState
v-else-if="!slicedList.length"
class="m-auto py-6"
:description="
state.search ? $t('audit.list.empty.description', { search: state.search }) : ''
"
:title="$t('audit.list.empty.title')" />
<li v-else v-for="(event, eventIndex) in slicedList" :key="`event-${event._id}`">
<AuditEntry
Expand Down Expand Up @@ -228,10 +231,14 @@ const props = defineProps({
const { width } = useWindowSize();
const router = useRouter();
const i18n = useI18n();
const now = dayjs();
const state = reactive({
search: null as string | null,
slice: Number(props.slice) as number,
period: { start: '' as string, end: '' as string },
period: {
start: now.subtract(7, 'days').format(DATE_FORMAT) as string,
end: now.format(DATE_FORMAT) as string,
},
});
const {
Expand All @@ -240,11 +247,13 @@ const {
isFetching: isFetchingHistory,
data: history,
error: historyError,
} = useQuery({
queryKey: ['history'],
queryFn: () => getAllAuditEvents(),
retry: false,
});
} = useQuery(
computed(() => ({
queryKey: ['history', state.period.start, state.period.end],
queryFn: () => getAllAuditEvents(state.period.start, state.period.end),
retry: false,
})),
);
const filteredList = computed(() => {
return (history.value || [])
Expand Down Expand Up @@ -362,7 +371,7 @@ const shortcuts = computed(() => () => [
label: i18n.t('audit.list.period.shortcuts.today'),
atClick: () => {
const now = dayjs();
return [now.startOf('day').format(DATE_FORMAT), now.endOf('day').format(DATE_FORMAT)];
return [now.startOf('day').format(DATE_FORMAT), now.add(1, 'day').format(DATE_FORMAT)];
},
},
{
Expand All @@ -373,19 +382,22 @@ const shortcuts = computed(() => () => [
},
},
{
label: i18n.t('audit.list.period.shortcuts.last30days'),
label: i18n.t('audit.list.period.shortcuts.last7days'),
atClick: () => {
const now = dayjs();
return [now.subtract(30, 'day').format(DATE_FORMAT), now.format(DATE_FORMAT)];
return [now.subtract(7, 'day').format(DATE_FORMAT), now.format(DATE_FORMAT)];
},
},
{
label: i18n.t('audit.list.period.shortcuts.sinceFirstDay'),
label: i18n.t('audit.list.period.shortcuts.last30days'),
atClick: () => {
const now = dayjs();
const [oldest] = (history.value || []).map(({ occurred }) => occurred).sort();
return [dayjs(oldest || '01-01-2014').format(DATE_FORMAT), now.format(DATE_FORMAT)];
return [now.subtract(30, 'day').format(DATE_FORMAT), now.format(DATE_FORMAT)];
},
},
{
label: i18n.t('audit.list.period.shortcuts.sinceFirstDay'),
atClick: () => [dayjs('01-01-2014').format(DATE_FORMAT)],
},
]);
</script>

0 comments on commit fc4478b

Please sign in to comment.