Skip to content

Commit

Permalink
Disable persisted cache for API responses, add refresh button (#1043)
Browse files Browse the repository at this point in the history
* Disable persisted cache for API responses

* Remove additional cache configurations

Signed-off-by: Michael Edgar <[email protected]>

* Last updated header

* Bugfixes

* Fix production start warning in the logs

* Update browsers db

* Use a default address when running tests without a base url

* Make the messages page test resilient to async data loading

* Reworked all tests to share common code, and handle async properly

---------

Signed-off-by: Michael Edgar <[email protected]>
Co-authored-by: Michael Edgar <[email protected]>
  • Loading branch information
riccardo-forina and MikeEdgar authored Sep 25, 2024
1 parent 2be7cc9 commit 3966657
Show file tree
Hide file tree
Showing 90 changed files with 499 additions and 336 deletions.
1 change: 0 additions & 1 deletion ui/api/kafka/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export async function getKafkaCluster(
try {
const res = await fetch(url, {
headers: await getHeaders(),
cache: "reload",
});
if (res.status === 200) {
const rawData = await res.json();
Expand Down
1 change: 0 additions & 1 deletion ui/api/messages/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export async function getTopicMessages(
);
const res = await fetch(url, {
headers: await getHeaders(),
cache: "no-store",
next: { tags: [`messages-${topicId}`] },
});
const rawData = await res.json();
Expand Down
6 changes: 0 additions & 6 deletions ui/api/topics/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
import { filterUndefinedFromObj } from "@/utils/filterUndefinedFromObj";
import { logger } from "@/utils/logger";
import { getSession, setSession } from "@/utils/session";
import { revalidateTag } from "next/cache";

const log = logger.child({ module: "topics-api" });

Expand Down Expand Up @@ -121,9 +120,6 @@ export async function createTopic(
log.debug({ url, rawData }, "createTopic response");
const response = TopicCreateResponseSchema.parse(rawData);
log.debug(response, "createTopic response parsed");
if (validateOnly === false) {
revalidateTag("topics");
}
return response;
}

Expand Down Expand Up @@ -155,7 +151,6 @@ export async function updateTopic(
log.debug({ status: res.status }, "updateTopic response");
try {
if (res.status === 204) {
revalidateTag(`topic-${topicId}`);
return true;
} else {
const rawData = await res.json();
Expand All @@ -181,7 +176,6 @@ export async function deleteTopic(
const success = res.status === 204;
if (success) {
log.debug({ url }, "deleteTopic success");
revalidateTag("topics");
}
return success;
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Skeleton } from "@patternfly/react-core";
import { notFound } from "next/navigation";
import { Suspense } from "react";

export const fetchCache = "force-cache";

export async function NodeBreadcrumb({
params: { kafkaId, nodeId },
}: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { NodeBreadcrumb } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/nodes/[nodeId]/NodeBreadcrumb";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/nodes/[nodeId]/NodeBreadcrumb";
export default NodeBreadcrumb;
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { KafkaTopicParams } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/to
import { BreadcrumbLink } from "@/components/Navigation/BreadcrumbLink";
import { BreadcrumbItem } from "@/libs/patternfly/react-core";

export const fetchCache = "force-cache";

export async function TopicBreadcrumb({
params: { kafkaId, topicId },
}: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TopicBreadcrumb } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/topics/[topicId]/TopicBreadcrumb";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/topics/[topicId]/TopicBreadcrumb";
export default TopicBreadcrumb;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TopicBreadcrumb } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/topics/[topicId]/TopicBreadcrumb";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/topics/[topicId]/TopicBreadcrumb";
export default TopicBreadcrumb;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TopicBreadcrumb } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/topics/[topicId]/TopicBreadcrumb";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/topics/[topicId]/TopicBreadcrumb";
export default TopicBreadcrumb;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TopicBreadcrumb } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/topics/[topicId]/TopicBreadcrumb";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/topics/[topicId]/TopicBreadcrumb";
export default TopicBreadcrumb;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TopicBreadcrumb } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/topics/[topicId]/TopicBreadcrumb";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@activeBreadcrumb/topics/[topicId]/TopicBreadcrumb";
export default TopicBreadcrumb;
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Skeleton } from "@patternfly/react-core";
import { notFound } from "next/navigation";
import { Suspense } from "react";

export const fetchCache = "force-cache";

export function KafkaHeader({ params: { kafkaId } }: { params: KafkaParams }) {
return (
<Suspense fallback={<AppHeader title={<Skeleton width="35%" />} />}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { Suspense } from "react";
import { useTranslations } from "next-intl";
import { ConsumerGroupActionButton } from "./ConsumerGroupActionButton";

export const fetchCache = "force-cache";

export default function Page({
params: { kafkaId, groupId },
}: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { Skeleton } from "@patternfly/react-core";
import { notFound } from "next/navigation";
import { Suspense } from "react";

export const fetchCache = "force-cache";

export async function NodeHeader({
params: { kafkaId, nodeId },
}: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { NodeHeader } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/nodes/[nodeId]/NodeHeader";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/nodes/[nodeId]/NodeHeader";
export default NodeHeader;
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { Skeleton } from "@patternfly/react-core";
import { notFound } from "next/navigation";
import { Suspense } from "react";

export const fetchCache = "force-cache";

export default function Header({
params: { kafkaId },
}: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { KafkaHeader } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/KafkaHeader";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/KafkaHeader";
export default KafkaHeader;
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ import { Skeleton } from "@patternfly/react-core";
import { notFound } from "next/navigation";
import { ReactNode, Suspense } from "react";

export const fetchCache = "force-cache";
export type TopicHeaderProps = {
params: KafkaTopicParams;
showRefresh?: boolean;
};

export function TopicHeader({
params: { kafkaId, topicId },
}: {
params: KafkaTopicParams;
}) {
showRefresh,
}: TopicHeaderProps) {
const portal = <div key={"topic-header-portal"} id={"topic-header-portal"} />;
return (
<Suspense
fallback={
<AppHeader
title={<Skeleton width="35%" />}
showRefresh={showRefresh}
navigation={
<PageNavigation>
<Nav aria-label="Group section navigation" variant="tertiary">
Expand Down Expand Up @@ -77,16 +80,22 @@ export function TopicHeader({
/>
}
>
<ConnectedTopicHeader params={{ kafkaId, topicId }} portal={portal} />
<ConnectedTopicHeader
params={{ kafkaId, topicId }}
portal={portal}
showRefresh={showRefresh}
/>
</Suspense>
);
}

async function ConnectedTopicHeader({
params: { kafkaId, topicId },
showRefresh,
portal,
}: {
params: KafkaTopicParams;
showRefresh?: boolean;
portal: ReactNode;
}) {
const cluster = await getKafkaCluster(kafkaId);
Expand All @@ -102,6 +111,7 @@ async function ConnectedTopicHeader({
{topic?.meta?.managed === true && <ManagedTopicLabel />}
</>
}
showRefresh={showRefresh}
navigation={
<PageNavigation>
<Nav aria-label="Group section navigation" variant="tertiary">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TopicHeader } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";
export default TopicHeader;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TopicHeader } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";
export default TopicHeader;
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { TopicHeader } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";
import {
TopicHeader,
TopicHeaderProps,
} from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";
export default TopicHeader;
export default function TopicHeaderNoRefresh(
props: Omit<TopicHeaderProps, "showRefresh">,
) {
return <TopicHeader {...props} showRefresh={false} />;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TopicHeader } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";
export default TopicHeader;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TopicHeader } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";

export { fetchCache } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/@header/topics/[topicId]/TopicHeader";
export default TopicHeader;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { KafkaParams } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/kafka.params";
import { DeleteModal } from "@/components/DeleteModal";
import { useRouter } from "@/navigation";
import { useRouter } from "@/i18n/routing";
import { useTranslations } from "next-intl";
import { useParams } from "next/navigation";
import { useState, useTransition } from "react";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
MenuToggle,
SearchInput,
} from "@/libs/patternfly/react-core";
import { Link, useRouter } from "@/navigation";
import { Link, useRouter } from "@/i18n/routing";
import { Route } from "next";
import { CSSProperties, useState } from "react";

Expand Down Expand Up @@ -49,9 +49,7 @@ export function KafkaSwitcher<T extends string>({
.filter(
(b) =>
searchText === "" ||
b.attributes.name
.toLowerCase()
.includes(searchText.toLowerCase()),
b.attributes.name.toLowerCase().includes(searchText.toLowerCase()),
)
.map(clusterToDropdownItem);
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { ConsumerGroup, ConsumerGroupState } from "@/api/consumerGroups/schema";
import { useRouter } from "@/navigation";
import { useRouter } from "@/i18n/routing";
import { useFilterParams } from "@/utils/useFilterParams";
import { useOptimistic, useState, useTransition } from "react";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
HelpIcon,
InfoCircleIcon,
} from "@/libs/patternfly/react-icons";
import { Link } from "@/navigation";
import { Link } from "@/i18n/routing";
import { useTranslations } from "next-intl";
import { ReactNode, useEffect, useState } from "react";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Number } from "@/components/Format/Number";
import { ResponsiveTable } from "@/components/Table";
import { Tooltip } from "@/libs/patternfly/react-core";
import { HelpIcon } from "@/libs/patternfly/react-icons";
import { Link } from "@/navigation";
import { Link } from "@/i18n/routing";
import { TableVariant } from "@patternfly/react-table";
import { useTranslations } from "next-intl";

Expand Down Expand Up @@ -40,9 +40,7 @@ export function LagTable({
return (
<Th key={key}>
{t("committed_offset")}{" "}
<Tooltip
content={t("committed_offset_tooltip")}
>
<Tooltip content={t("committed_offset_tooltip")}>
<HelpIcon />
</Tooltip>
</Th>
Expand All @@ -51,9 +49,7 @@ export function LagTable({
return (
<Th key={key}>
{t("end_offset")}{" "}
<Tooltip
content={t("end_offset_tooltip")}
>
<Tooltip content={t("end_offset_tooltip")}>
<HelpIcon />
</Tooltip>
</Th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TopicSelection,
partitionSelection,
} from "../types";
import { useRouter } from "@/navigation";
import { useRouter } from "@/i18n/routing";
import {
getDryrunResult,
updateConsumerGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function ConsumerGroupsPage({
| ConsumerGroupState[]
| undefined;
return (
<PageSection>
<PageSection isFilled={true}>
<Suspense
fallback={
<ConnectedConsumerGroupTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { NodeConfig } from "@/api/nodes/schema";
import { Number } from "@/components/Format/Number";
import { TableView } from "@/components/Table";
import { usePathname, useRouter } from "@/navigation";
import { usePathname, useRouter } from "@/i18n/routing";
import { Label, LabelGroup, List, ListItem } from "@patternfly/react-core";
import { TableVariant } from "@patternfly/react-table";
import { useTranslations } from "next-intl";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { KafkaNodeParams } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/nodes/kafkaNode.params";
import { redirect } from "@/navigation";
import { redirect } from "@/i18n/routing";

export default function NodePage({ params }: { params: KafkaNodeParams }) {
redirect(`/kafka/${params.kafkaId}/nodes/${params.nodeId}/configuration`);
Expand Down
4 changes: 2 additions & 2 deletions ui/app/[locale]/(authorized)/kafka/[kafkaId]/nodes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NodesTable,
} from "@/app/[locale]/(authorized)/kafka/[kafkaId]/nodes/NodesTable";
import { Alert, PageSection } from "@/libs/patternfly/react-core";
import { redirect } from "@/navigation";
import { redirect } from "@/i18n/routing";
import { getTranslations } from "next-intl/server";
import { Suspense } from "react";

Expand Down Expand Up @@ -71,7 +71,7 @@ async function ConnectedNodes({ params }: { params: KafkaParams }) {
return (
<>
{!kpis && (
<PageSection>
<PageSection isFilled={true}>
<Alert title={t("nodes.kpis_offline")} variant={"warning"} />
</PageSection>
)}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/[locale]/(authorized)/kafka/[kafkaId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { KafkaParams } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/kafka.params";
import { redirect } from "@/navigation";
import { redirect } from "@/i18n/routing";

export const dynamic = "force-dynamic";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TopicsTableColumn,
TopicsTableColumns,
} from "@/components/TopicsTable/TopicsTable";
import { useRouter } from "@/navigation";
import { useRouter } from "@/i18n/routing";
import { isReadonly } from "@/utils/env";
import { useFilterParams } from "@/utils/useFilterParams";
import { useOptimistic, useTransition } from "react";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { KafkaParams } from "@/app/[locale]/(authorized)/kafka/[kafkaId]/kafka.params";
import { RedirectOnLoad } from "@/components/Navigation/RedirectOnLoad";
import { revalidatePath } from "next/cache";

export default function PostDeletePage({
params: { kafkaId },
}: {
params: KafkaParams;
}) {
revalidatePath(`/kafka/${kafkaId}/topics`, "page");
return <RedirectOnLoad url={`/kafka/${kafkaId}/topics`} />;
}
Loading

0 comments on commit 3966657

Please sign in to comment.