mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-11-25 18:09:31 +00:00
feat: add events amount selector
This commit is contained in:
1 parent
afc2e749b9
commit
aff4bb70a9
2 files changed
+16
-5
No files matched your search
@@ -17,7 +17,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import { Box } from "@mui/material";
|
import { Box, MenuItem, TextField } from "@mui/material";
|
||||||
import { DataGrid, type GridColDef } from "@mui/x-data-grid";
|
import { DataGrid, type GridColDef } from "@mui/x-data-grid";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import EventDurationLineChart from "components/charts/EventDurationLineChart";
|
import EventDurationLineChart from "components/charts/EventDurationLineChart";
|
||||||
@@ -26,7 +26,7 @@ import { useClient } from "hooks/useClient";
|
|||||||
import type { Event } from "models/Event";
|
import type { Event } from "models/Event";
|
||||||
import type { RepositoryId } from "models/RepositoryId";
|
import type { RepositoryId } from "models/RepositoryId";
|
||||||
import type React from "react";
|
import type React from "react";
|
||||||
import { useMemo } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { DETAIL_TABLE_PROPS } from "utils";
|
import { DETAIL_TABLE_PROPS } from "utils";
|
||||||
|
|
||||||
interface EventsTabProps {
|
interface EventsTabProps {
|
||||||
@@ -49,11 +49,12 @@ const columns: GridColDef<EventRow>[] = [
|
|||||||
|
|
||||||
export default function EventsTab({ packageBase, repository }: EventsTabProps): React.JSX.Element {
|
export default function EventsTab({ packageBase, repository }: EventsTabProps): React.JSX.Element {
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
|
const [limit, setLimit] = useState(30);
|
||||||
|
|
||||||
const { data: events = [] } = useQuery<Event[]>({
|
const { data: events = [] } = useQuery<Event[]>({
|
||||||
enabled: !!packageBase,
|
enabled: !!packageBase,
|
||||||
queryFn: () => client.fetch.fetchPackageEvents(repository, packageBase, 30),
|
queryFn: () => client.fetch.fetchPackageEvents(repository, packageBase, limit),
|
||||||
queryKey: QueryKeys.events(repository, packageBase),
|
queryKey: QueryKeys.events(repository, packageBase, limit),
|
||||||
refetchOnMount: "always",
|
refetchOnMount: "always",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -65,6 +66,15 @@ export default function EventsTab({ packageBase, repository }: EventsTabProps):
|
|||||||
})), [events]);
|
})), [events]);
|
||||||
|
|
||||||
return <Box sx={{ mt: 1 }}>
|
return <Box sx={{ mt: 1 }}>
|
||||||
|
<TextField
|
||||||
|
label="Show events"
|
||||||
|
onChange={event => setLimit(Number(event.target.value))}
|
||||||
|
select
|
||||||
|
size="small"
|
||||||
|
value={limit}
|
||||||
|
>
|
||||||
|
{[30, 100, 500].map(value => <MenuItem key={value} value={value}>Last {value} events</MenuItem>)}
|
||||||
|
</TextField>
|
||||||
<EventDurationLineChart events={events} />
|
<EventDurationLineChart events={events} />
|
||||||
<DataGrid columns={columns} rows={rows} {...DETAIL_TABLE_PROPS} />
|
<DataGrid columns={columns} rows={rows} {...DETAIL_TABLE_PROPS} />
|
||||||
</Box>;
|
</Box>;
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ export const QueryKeys = {
|
|||||||
|
|
||||||
dependencies: (packageBase: string, repository: RepositoryId) => ["dependencies", repository.key, packageBase] as const,
|
dependencies: (packageBase: string, repository: RepositoryId) => ["dependencies", repository.key, packageBase] as const,
|
||||||
|
|
||||||
events: (repository: RepositoryId, objectId?: string) => ["events", repository.key, objectId] as const,
|
events: (repository: RepositoryId, objectId?: string, limit?: number) =>
|
||||||
|
["events", repository.key, objectId, limit] as const,
|
||||||
|
|
||||||
info: ["info"] as const,
|
info: ["info"] as const,
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user