Skip to content

Commit

Permalink
review: review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Mason Hu <[email protected]>
  • Loading branch information
MasWho committed Feb 19, 2025
1 parent d5cd79a commit 579ea82
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 41 deletions.
23 changes: 3 additions & 20 deletions src/api/storage-pools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import { withEntitlementsQuery } from "util/entitlements/api";
export const storagePoolEntitlements = ["can_delete", "can_edit"];
export const storageVolumeEntitlements = ["can_delete"];

export const fetchStoragePoolOnMember = (
export const fetchStoragePool = (
pool: string,
target: string,
isFineGrained: boolean | null,
target?: string,
): Promise<LxdStoragePool> => {
const entitlements = `&${withEntitlementsQuery(isFineGrained, storagePoolEntitlements)}`;
return new Promise((resolve, reject) => {
Expand All @@ -37,19 +37,6 @@ export const fetchStoragePoolOnMember = (
});
};

export const fetchStoragePool = (
pool: string,
isFineGrained: boolean | null,
): Promise<LxdStoragePool> => {
const entitlements = `&${withEntitlementsQuery(isFineGrained, storagePoolEntitlements)}`;
return new Promise((resolve, reject) => {
fetch(`/1.0/storage-pools/${pool}?recursion=1${entitlements}`)
.then(handleResponse)
.then((data: LxdApiResponse<LxdStoragePool>) => resolve(data.metadata))
.catch(reject);
});
};

export const fetchStoragePools = (
isFineGrained: boolean | null,
): Promise<LxdStoragePool[]> => {
Expand Down Expand Up @@ -231,11 +218,7 @@ export const fetchPoolFromClusterMembers = (
return new Promise((resolve, reject) => {
Promise.allSettled(
clusterMembers.map((member) => {
return fetchStoragePoolOnMember(
poolName,
member.server_name,
isFineGrained,
);
return fetchStoragePool(poolName, isFineGrained, member.server_name);
}),
)
.then((results) => {
Expand Down
9 changes: 3 additions & 6 deletions src/components/forms/YamlForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { FC, ReactNode, useEffect, useRef, useState } from "react";
import { Editor, loader } from "@monaco-editor/react";
import { updateMaxHeight } from "util/updateMaxHeight";
import useEventListener from "util/useEventListener";
import {
editor,
IMarkdownString,
} from "monaco-editor/esm/vs/editor/editor.api";
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
import IStandaloneCodeEditor = editor.IStandaloneCodeEditor;
import classnames from "classnames";

Expand All @@ -19,7 +16,7 @@ interface Props {
children?: ReactNode;
autoResize?: boolean;
readOnly?: boolean;
readOnlyMessage?: IMarkdownString;
readOnlyMessage?: string;
}

const YamlForm: FC<Props> = ({
Expand Down Expand Up @@ -75,7 +72,7 @@ const YamlForm: FC<Props> = ({
},
overviewRulerLanes: 0,
readOnly: readOnly,
readOnlyMessage: readOnlyMessage,
readOnlyMessage: { value: readOnlyMessage ?? "" },
}}
onMount={(editor: IStandaloneCodeEditor) => {
setEditor(editor);
Expand Down
11 changes: 2 additions & 9 deletions src/context/useStoragePools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ import { queryKeys } from "util/queryKeys";
import { UseQueryResult } from "@tanstack/react-query";
import { useAuth } from "./auth";
import { LxdStoragePool } from "types/storage";
import {
fetchStoragePool,
fetchStoragePoolOnMember,
fetchStoragePools,
} from "api/storage-pools";
import { fetchStoragePool, fetchStoragePools } from "api/storage-pools";

export const useStoragePool = (
pool: string,
target?: string,
enabled?: boolean,
): UseQueryResult<LxdStoragePool> => {
const { isFineGrained } = useAuth();
const queryFn = target
? () => fetchStoragePoolOnMember(pool, target, isFineGrained)
: () => fetchStoragePool(pool, isFineGrained);
return useQuery({
queryKey: [queryKeys.storage, pool, target],
queryFn: queryFn,
queryFn: () => fetchStoragePool(pool, isFineGrained, target),
enabled: (enabled ?? true) && isFineGrained !== null,
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/instances/EditInstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ const EditInstance: FC<Props> = ({ instance }) => {
void formik.setFieldValue("yaml", yaml);
}}
readOnly={!!formik.values.editRestriction}
readOnlyMessage={{ value: formik.values.editRestriction ?? "" }}
readOnlyMessage={formik.values.editRestriction}
>
<YamlNotification
entity="instance"
Expand Down
9 changes: 5 additions & 4 deletions src/pages/storage/EditStoragePool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
import {
fetchPoolFromClusterMembers,
fetchStoragePool,
fetchStoragePoolOnMember,
updateClusteredPool,
updatePool,
} from "api/storage-pools";
Expand Down Expand Up @@ -126,9 +125,11 @@ const EditStoragePool: FC<Props> = ({ pool }) => {
</>,
);
const member = clusterMembers[0]?.server_name ?? undefined;
const updatedPool = member
? await fetchStoragePoolOnMember(values.name, member, isFineGrained)
: await fetchStoragePool(values.name, isFineGrained);
const updatedPool = await fetchStoragePool(
values.name,
isFineGrained,
member,
);
const updatedPoolOnMembers = await fetchPoolFromClusterMembers(
pool.name,
clusterMembers,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/storage/forms/StoragePoolForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ const StoragePoolForm: FC<Props> = ({
void formik.setFieldValue("yaml", yaml);
}}
readOnly={!!formik.values.editRestriction}
readOnlyMessage={{ value: formik.values.editRestriction ?? "" }}
readOnlyMessage={formik.values.editRestriction}
>
<Notification severity="information" title="YAML Configuration">
{`${isSupportedStorageDriver ? "" : `The ${formik.values.driver} driver is not fully supported in the web interface. `}This is the YAML representation of the storage pool.`}
Expand Down

0 comments on commit 579ea82

Please sign in to comment.