Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit d9ac772

Browse files
✨ Add API logs date filtering
1 parent 16f957a commit d9ac772

File tree

2 files changed

+79
-20
lines changed

2 files changed

+79
-20
lines changed

pages/manage/_team/developer/logs.vue

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
</div>
6464
<div>
6565
<LargeMessage
66-
v-if="!loading && (!data || !data.hits || !data.hits.total)"
66+
v-if="!loading && (!data || !data.data || !data.data.length)"
6767
heading="No API logs yet"
6868
img="undraw_software_engineer_lvl5.svg"
6969
text="We couldn't find any API logs for this API key yet, go ahead and make some requests first"
@@ -81,14 +81,26 @@
8181
</tr>
8282
</thead>
8383
<tbody>
84-
<tr v-for="(log, i) in data.hits.hits" :key="`l${log._id}${i}`">
85-
<td><TimeAgo :date="log._source.date" /></td>
86-
<td>{{ log._source.method }}</td>
84+
<tr v-for="(log, i) in data.data" :key="`l${log._id}${i}`">
85+
<td v-if="log._source && log._source.date">
86+
<TimeAgo :date="log._source.date" />
87+
</td>
88+
<td v-if="log._source && log._source.method">
89+
{{ log._source.method }}
90+
</td>
8791
<td>
8892
<code>{{ log._source.url.split("?")[0] }}</code>
8993
</td>
90-
<td><HTTPStatus :status="log._source.statusCode" /></td>
91-
<td>
94+
<td v-if="log._source && log._source.statusCode">
95+
<HTTPStatus :status="log._source.statusCode" />
96+
</td>
97+
<td
98+
v-if="
99+
log._source &&
100+
log._source.completedDate &&
101+
log._source.date
102+
"
103+
>
92104
{{
93105
new Date(log._source.completedDate).getTime() -
94106
new Date(log._source.date).getTime()
@@ -112,6 +124,27 @@
112124
</tr>
113125
</tbody>
114126
</table>
127+
<div class="pagination text text--align-center">
128+
<button
129+
v-if="data && data.hasMore"
130+
class="button"
131+
:disabled="loadingMore"
132+
@click="loadMore"
133+
>
134+
<span>Load more logs</span>
135+
<font-awesome-icon
136+
v-if="!loadingMore"
137+
class="icon"
138+
icon="arrow-down"
139+
/>
140+
<font-awesome-icon
141+
v-else
142+
class="icon icon--ml-2 icon--color-light"
143+
icon="sync"
144+
spin
145+
/>
146+
</button>
147+
</div>
115148
</div>
116149
</div>
117150
</div>
@@ -169,11 +202,12 @@ export default class ManageSettings extends Vue {
169202
loading = "";
170203
newScopes = "orgRead";
171204
scopes = scopes;
172-
loggedInMembership = 3;
173205
activeApiKey = 0;
174206
apiKeyOptions: any = {};
175207
timeFilter = "24h";
208+
from = 0;
176209
timeOptions = {
210+
"10s": "Last 10 seconds",
177211
"60s": "Last 60 seconds",
178212
"10m": "Last 10 minutes",
179213
"24h": "Last 24 hours",
@@ -185,9 +219,12 @@ export default class ManageSettings extends Vue {
185219
this.apiKeys = {
186220
...this.$store.getters["manage/apiKeys"](this.$route.params.team)
187221
};
188-
this.loggedInMembership = parseInt(
189-
this.$store.getters["manage/loggedInMembership"](this.$route.params.team)
190-
);
222+
this.data = {
223+
...this.$store.getters["manage/apiKeyLogs"](
224+
this.$route.params.team,
225+
this.activeApiKey
226+
)
227+
};
191228
}
192229
193230
private load() {
@@ -219,12 +256,15 @@ export default class ManageSettings extends Vue {
219256
}
220257
221258
private loadData() {
259+
this.from = 0;
222260
if (!this.activeApiKey) return;
223261
this.loading = "Loading your API logs";
224262
this.$store
225263
.dispatch("manage/getApiKeyLogs", {
226264
team: this.$route.params.team,
227-
id: this.activeApiKey
265+
id: this.activeApiKey,
266+
range: this.timeFilter,
267+
from: this.from
228268
})
229269
.then(data => {
230270
this.data = data;
@@ -236,15 +276,24 @@ export default class ManageSettings extends Vue {
236276
}
237277
238278
private loadMore() {
279+
const data = { ...this.data };
280+
if (data && data.data) {
281+
this.from = data.data.length;
282+
}
239283
this.loadingMore = true;
240284
this.$store
241-
.dispatch("manage/getApiKeys", {
285+
.dispatch("manage/getApiKeyLogs", {
242286
team: this.$route.params.team,
243-
start: this.$store.state.manage.apiKeys[this.$route.params.team].next
287+
id: this.activeApiKey,
288+
range: this.timeFilter,
289+
from: this.from
244290
})
245291
.then(() => {
246-
this.apiKeys = {
247-
...this.$store.getters["manage/apiKeys"](this.$route.params.team)
292+
this.data = {
293+
...this.$store.getters["manage/apiKeyLogs"](
294+
this.$route.params.team,
295+
this.activeApiKey
296+
)
248297
};
249298
})
250299
.catch(error => {

store/manage.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,18 @@ export const mutations: MutationTree<RootState> = {
137137
currentApiKeys[team][id] = { ...apiKey };
138138
Vue.set(state, "apiKey", currentApiKeys);
139139
},
140-
setApiKeyLogs(state: RootState, { team, apiKeyLogs, id }): void {
140+
setApiKeyLogs(state: RootState, { team, apiKeyLogs, id, from }): void {
141141
const currentApiKeyLogs = state.apiKeyLogs;
142142
currentApiKeyLogs[team] = currentApiKeyLogs[team] || {};
143-
currentApiKeyLogs[team][id] = { ...apiKeyLogs };
143+
currentApiKeyLogs[team][id] = currentApiKeyLogs[team][id] || emptyPagination;
144+
if (from) {
145+
currentApiKeyLogs[team][id].data = [
146+
...currentApiKeyLogs[team][id].data,
147+
...apiKeyLogs.data
148+
];
149+
} else {
150+
currentApiKeyLogs[team][id] = { ...apiKeyLogs };
151+
}
144152
Vue.set(state, "apiKeyLogs", currentApiKeyLogs);
145153
},
146154
setDomains(state: RootState, { team, domains, start, next }): void {
@@ -383,11 +391,11 @@ export const actions: ActionTree<RootState, RootState> = {
383391
commit("setApiKey", { team, apiKey, id });
384392
return apiKey;
385393
},
386-
async getApiKeyLogs({ commit }, { team, id }) {
394+
async getApiKeyLogs({ commit }, { team, id, range, from }) {
387395
const apiKeyLogs: any = (await this.$axios.get(
388-
`/organizations/${team}/api-keys/${id}/logs`
396+
`/organizations/${team}/api-keys/${id}/logs?range=${range}&from=${from}`
389397
)).data;
390-
commit("setApiKeyLogs", { team, apiKeyLogs, id });
398+
commit("setApiKeyLogs", { team, apiKeyLogs, range, id, from });
391399
return apiKeyLogs;
392400
},
393401
async createApiKey({ dispatch }, context) {
@@ -530,5 +538,7 @@ export const getters: GetterTree<RootState, RootState> = {
530538
webhooks: state => (team: string) => (state.webhooks)[team],
531539
webhook: state => (team: string, webhook: string) =>
532540
state.webhook[team] && state.webhook[team][webhook],
541+
apiKeyLogs: state => (team: string, apiKeyLogs: string) =>
542+
state.apiKeyLogs[team] && state.apiKeyLogs[team][apiKeyLogs],
533543
organization: state => (team: string) => (state.organizations)[team]
534544
};

0 commit comments

Comments
 (0)