feat(page): Optimize data handling with useMemo for boards, agents, and gateways
This commit is contained in:
@@ -120,8 +120,8 @@ export default function AgentsPage() {
|
|||||||
refetchOnMount: "always",
|
refetchOnMount: "always",
|
||||||
});
|
});
|
||||||
|
|
||||||
const boards = boardsQuery.data ?? [];
|
const boards = useMemo(() => boardsQuery.data ?? [], [boardsQuery.data]);
|
||||||
const agents = agentsQuery.data ?? [];
|
const agents = useMemo(() => agentsQuery.data ?? [], [agentsQuery.data]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!boardId && boards.length > 0) {
|
if (!boardId && boards.length > 0) {
|
||||||
@@ -285,6 +285,7 @@ export default function AgentsPage() {
|
|||||||
[boards]
|
[boards]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/incompatible-library
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data: sortedAgents,
|
data: sortedAgents,
|
||||||
columns,
|
columns,
|
||||||
|
|||||||
@@ -53,10 +53,6 @@ export default function EditBoardPage() {
|
|||||||
|
|
||||||
const isFormReady = Boolean(name.trim() && gatewayId);
|
const isFormReady = Boolean(name.trim() && gatewayId);
|
||||||
|
|
||||||
const selectedGateway = useMemo(
|
|
||||||
() => gateways.find((gateway) => gateway.id === gatewayId) || null,
|
|
||||||
[gateways, gatewayId]
|
|
||||||
);
|
|
||||||
const gatewayOptions = useMemo(
|
const gatewayOptions = useMemo(
|
||||||
() => gateways.map((gateway) => ({ value: gateway.id, label: gateway.name })),
|
() => gateways.map((gateway) => ({ value: gateway.id, label: gateway.name })),
|
||||||
[gateways]
|
[gateways]
|
||||||
|
|||||||
@@ -50,10 +50,6 @@ export default function NewBoardPage() {
|
|||||||
|
|
||||||
const isFormReady = Boolean(name.trim() && gatewayId);
|
const isFormReady = Boolean(name.trim() && gatewayId);
|
||||||
|
|
||||||
const selectedGateway = useMemo(
|
|
||||||
() => gateways.find((gateway) => gateway.id === gatewayId) || null,
|
|
||||||
[gateways, gatewayId]
|
|
||||||
);
|
|
||||||
const gatewayOptions = useMemo(
|
const gatewayOptions = useMemo(
|
||||||
() => gateways.map((gateway) => ({ value: gateway.id, label: gateway.name })),
|
() => gateways.map((gateway) => ({ value: gateway.id, label: gateway.name })),
|
||||||
[gateways]
|
[gateways]
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export default function BoardsPage() {
|
|||||||
refetchOnMount: "always",
|
refetchOnMount: "always",
|
||||||
});
|
});
|
||||||
|
|
||||||
const boards = boardsQuery.data ?? [];
|
const boards = useMemo(() => boardsQuery.data ?? [], [boardsQuery.data]);
|
||||||
|
|
||||||
const sortedBoards = useMemo(
|
const sortedBoards = useMemo(
|
||||||
() => [...boards].sort((a, b) => a.name.localeCompare(b.name)),
|
() => [...boards].sort((a, b) => a.name.localeCompare(b.name)),
|
||||||
@@ -141,6 +141,7 @@ export default function BoardsPage() {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/incompatible-library
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data: sortedBoards,
|
data: sortedBoards,
|
||||||
columns,
|
columns,
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export default function GatewaysPage() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const gateways = gatewaysQuery.data ?? [];
|
const gateways = useMemo(() => gatewaysQuery.data ?? [], [gatewaysQuery.data]);
|
||||||
const sortedGateways = useMemo(() => [...gateways], [gateways]);
|
const sortedGateways = useMemo(() => [...gateways], [gateways]);
|
||||||
|
|
||||||
const deleteMutation = useAuthedMutation<
|
const deleteMutation = useAuthedMutation<
|
||||||
@@ -193,6 +193,7 @@ export default function GatewaysPage() {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/incompatible-library
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data: sortedGateways,
|
data: sortedGateways,
|
||||||
columns,
|
columns,
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ export default function OnboardingPage() {
|
|||||||
const { getToken, isSignedIn } = useAuth();
|
const { getToken, isSignedIn } = useAuth();
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
|
|
||||||
const [profile, setProfile] = useState<UserProfile | null>(null);
|
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [timezone, setTimezone] = useState("");
|
const [timezone, setTimezone] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
@@ -87,7 +86,6 @@ export default function OnboardingPage() {
|
|||||||
throw new Error("Unable to load profile.");
|
throw new Error("Unable to load profile.");
|
||||||
}
|
}
|
||||||
const data = (await response.json()) as UserProfile;
|
const data = (await response.json()) as UserProfile;
|
||||||
setProfile(data);
|
|
||||||
const fallbackName =
|
const fallbackName =
|
||||||
user?.fullName ?? user?.firstName ?? user?.username ?? "";
|
user?.fullName ?? user?.firstName ?? user?.username ?? "";
|
||||||
setName(data.preferred_name ?? data.name ?? fallbackName);
|
setName(data.preferred_name ?? data.name ?? fallbackName);
|
||||||
|
|||||||
Reference in New Issue
Block a user