Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions web/package/agama-web-ui.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Apr 1 08:53:43 UTC 2025 - José Iván López González <jlopez@suse.com>

- Fix reloading data after reprobing devices
(gh#agama-project/agama#2235).

-------------------------------------------------------------------
Thu Mar 27 12:40:04 UTC 2025 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
3 changes: 3 additions & 0 deletions web/src/api/storage/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import {
import { StorageDevice } from "~/types/storage";

/**
* @fixme Use a transformation instead of building the devices as part of the fetch function, see
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* https://tkdodo.eu/blog/react-query-data-transformations.
*
* Returns the list of devices in the given scope
*
* @param scope - "system": devices in the current state of the system; "result":
Expand Down
45 changes: 21 additions & 24 deletions web/src/queries/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

import { useMutation, useQuery, useQueryClient, useSuspenseQuery } from "@tanstack/react-query";
import React from "react";
import React, { useMemo } from "react";
import {
fetchConfig,
setConfig,
Expand Down Expand Up @@ -65,6 +65,12 @@ const devicesQuery = (scope: "result" | "system") => ({
staleTime: Infinity,
});

const usableDevicesQuery = () => ({
queryKey: ["storage", "usableDevices"],
queryFn: fetchUsableDevices,
staleTime: Infinity,
});

const productParamsQuery = {
queryKey: ["storage", "productParams"],
queryFn: fetchProductParams,
Expand Down Expand Up @@ -145,34 +151,25 @@ const useDevices = (
return data;
};

const availableDevices = async (devices: StorageDevice[]): Promise<StorageDevice[]> => {
const findDevice = (devices: StorageDevice[], sid: number): StorageDevice | undefined => {
const device = devices.find((d) => d.sid === sid);
if (device === undefined) console.warn("Device not found:", sid);

return device;
};

const availableDevices = await fetchUsableDevices();

return availableDevices
.map((sid: number) => findDevice(devices, sid))
.filter((d: StorageDevice | undefined) => d);
};

const availableDevicesQuery = (devices: StorageDevice[]) => ({
queryKey: ["storage", "availableDevices"],
queryFn: () => availableDevices(devices),
staleTime: Infinity,
});

/**
* Hook that returns the list of available devices for installation.
*/
const useAvailableDevices = (): StorageDevice[] => {
const devices = useDevices("system", { suspense: true });
const { data } = useSuspenseQuery(availableDevicesQuery(devices));
return data;
const { data: usableDevices } = useSuspenseQuery(usableDevicesQuery());

const availableDevices = useMemo(() => {
/** @todo Extract this function to some shared place. */
const findDevice = (devices: StorageDevice[], sid: number): StorageDevice | undefined => {
const device = devices.find((d) => d.sid === sid);
if (device === undefined) console.warn("Device not found:", sid);

return device;
};
Comment on lines +163 to +168
Copy link
Copy Markdown
Contributor

@dgdavid dgdavid Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP: If possible (and when possible) I'd extract that function from here. Looks like it can be defined somewhere and consumed by this (and potentially others) method instead of be (re)defined/hidden here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to add a TODO in order to keep the change as minimal as possible because it goes to beta3 branch.

return usableDevices.map((sid: number) => findDevice(devices, sid)).filter((d) => d);
}, [devices, usableDevices]);

return availableDevices;
};

/**
Expand Down