Skip to content

Commit

Permalink
refactor(web): extend the iSCSI queries docs
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 13, 2024
1 parent abe872a commit 684d796
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion web/src/queries/storage/iscsi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,31 @@ const initiatorQuery = {
},
};

/**
* Hook that returns the information about the ISCSI initiator.
*
* This hook uses the Suspense API.
*/
const useInitiator = (): ISCSIInitiator => {
const { data } = useSuspenseQuery(initiatorQuery);
return data;
};

/**
* Hook that builds a mutation to update the initiator information.
*/
const useInitiatorMutation = () => {
const queryClient = useQueryClient();
const query = {
mutationFn: ({ name }) => updateInitiator({ name }),
// TODO: update the name if the query already contains data
onSuccess: () => queryClient.invalidateQueries({ queryKey: initiatorQuery.queryKey }),
};
return useMutation(query);
};

/**
* Subscribes to ISCSI initiator changes to keep the data up-to-date.
*/
const useInitiatorChanges = () => {
const client = useInstallerClient();
const queryClient = useQueryClient();
Expand Down Expand Up @@ -81,6 +91,9 @@ const useNodes = (): ISCSINode[] => {
return data;
};

/**
* Subscribes to ISCSI nodes changes to keep the query up-to-date.
*/
const useNodesChanges = () => {
const client = useInstallerClient();
const queryClient = useQueryClient();
Expand Down

0 comments on commit 684d796

Please sign in to comment.