Skip to content

Commit

Permalink
rewview: 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 21, 2025
1 parent 47d5d98 commit 363f77c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/api/networks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export const fetchNetworks = (
target?: string,
): Promise<LxdNetwork[]> => {
const targetParam = target ? `&target=${target}` : "";
const entitlements = `&${withEntitlementsQuery(
const entitlements = withEntitlementsQuery(
isFineGrained,
networkEntitlements,
)}`;
);
return new Promise((resolve, reject) => {
fetch(
`/1.0/networks?project=${project}&recursion=1${targetParam}${entitlements}`,
Expand Down Expand Up @@ -81,10 +81,10 @@ export const fetchNetwork = (
target?: string,
): Promise<LxdNetwork> => {
const targetParam = target ? `&target=${target}` : "";
const entitlements = `&${withEntitlementsQuery(
const entitlements = withEntitlementsQuery(
isFineGrained,
networkEntitlements,
)}`;
);
return new Promise((resolve, reject) => {
fetch(
`/1.0/networks/${name}?project=${project}${targetParam}${entitlements}`,
Expand Down
27 changes: 21 additions & 6 deletions src/api/storage-pools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ export const fetchStoragePool = (
isFineGrained: boolean | null,
target?: string,
): Promise<LxdStoragePool> => {
const entitlements = `&${withEntitlementsQuery(isFineGrained, storagePoolEntitlements)}`;
const entitlements = withEntitlementsQuery(
isFineGrained,
storagePoolEntitlements,
);
return new Promise((resolve, reject) => {
const targetParam = `&target=${target}`;
const targetParam = target ? `&target=${target}` : "";
fetch(`/1.0/storage-pools/${pool}?recursion=1${targetParam}${entitlements}`)
.then(handleResponse)
.then((data: LxdApiResponse<LxdStoragePool>) => resolve(data.metadata))
Expand All @@ -40,7 +43,10 @@ export const fetchStoragePool = (
export const fetchStoragePools = (
isFineGrained: boolean | null,
): Promise<LxdStoragePool[]> => {
const entitlements = `&${withEntitlementsQuery(isFineGrained, storagePoolEntitlements)}`;
const entitlements = withEntitlementsQuery(
isFineGrained,
storagePoolEntitlements,
);
return new Promise((resolve, reject) => {
fetch(`/1.0/storage-pools?recursion=1${entitlements}`)
.then(handleResponse)
Expand Down Expand Up @@ -247,7 +253,10 @@ export const fetchStorageVolumes = (
project: string,
isFineGrained: boolean | null,
): Promise<LxdStorageVolume[]> => {
const entitlements = `&${withEntitlementsQuery(isFineGrained, storageVolumeEntitlements)}`;
const entitlements = withEntitlementsQuery(
isFineGrained,
storageVolumeEntitlements,
);
return new Promise((resolve, reject) => {
fetch(
`/1.0/storage-pools/${pool}/volumes?project=${project}&recursion=1${entitlements}`,
Expand All @@ -264,7 +273,10 @@ export const fetchAllStorageVolumes = (
project: string,
isFineGrained: boolean | null,
): Promise<LxdStorageVolume[]> => {
const entitlements = `&${withEntitlementsQuery(isFineGrained, storageVolumeEntitlements)}`;
const entitlements = withEntitlementsQuery(
isFineGrained,
storageVolumeEntitlements,
);
return new Promise((resolve, reject) => {
fetch(`/1.0/storage-volumes?recursion=1&project=${project}${entitlements}`)
.then(handleResponse)
Expand All @@ -282,7 +294,10 @@ export const fetchStorageVolume = (
volume: string,
isFineGrained: boolean | null,
): Promise<LxdStorageVolume> => {
const entitlements = `&${withEntitlementsQuery(isFineGrained, storageVolumeEntitlements)}`;
const entitlements = withEntitlementsQuery(
isFineGrained,
storageVolumeEntitlements,
);
return new Promise((resolve, reject) => {
fetch(
`/1.0/storage-pools/${pool}/volumes/${type}/${volume}?project=${project}&recursion=1${entitlements}`,
Expand Down
4 changes: 4 additions & 0 deletions src/components/forms/DiskSizeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface Props {
setMemoryLimit: (val: string) => void;
disabled?: boolean;
classname?: string;
disabledReason?: string;
}

const DiskSizeSelector: FC<Props> = ({
Expand All @@ -23,6 +24,7 @@ const DiskSizeSelector: FC<Props> = ({
setMemoryLimit,
disabled,
classname,
disabledReason,
}) => {
const limit = parseMemoryLimit(value) ?? {
value: 1,
Expand Down Expand Up @@ -55,6 +57,7 @@ const DiskSizeSelector: FC<Props> = ({
value={value?.match(/^\d/) ? limit.value : ""}
disabled={disabled}
className={classname}
title={disabledReason}
/>
<Select
id={`memUnitSelect-${id}`}
Expand All @@ -68,6 +71,7 @@ const DiskSizeSelector: FC<Props> = ({
value={limit.unit}
disabled={disabled}
className={classname}
title={disabledReason}
/>
</div>
{(help || helpTotal) && (
Expand Down
7 changes: 4 additions & 3 deletions src/pages/storage/EditStoragePool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ const EditStoragePool: FC<Props> = ({ pool }) => {
: undefined;

const formik = useFormik<StoragePoolFormValues>({
initialValues: {
...toStoragePoolFormValues(pool, poolOnMembers),
initialValues: toStoragePoolFormValues(
pool,
poolOnMembers,
editRestriction,
},
),
validationSchema: StoragePoolSchema,
enableReinitialize: true,
onSubmit: (values) => {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/storage/actions/CreateStoragePoolBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const CreateStoragePoolBtn: FC<Props> = ({ project, className }) => {
className={className}
hasIcon={!isSmallScreen}
title={
!canCreateStoragePools()
? "You do not have permission to create storage pools"
: ""
canCreateStoragePools()
? ""
: "You do not have permission to create storage pools"
}
onClick={() => navigate(`/ui/project/${project}/storage/pools/create`)}
disabled={!canCreateStoragePools()}
Expand Down
1 change: 1 addition & 0 deletions src/pages/storage/forms/StoragePoolFormMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const StoragePoolFormMain: FC<Props> = ({ formik }) => {
!!formik.values.editRestriction ||
formik.values.driver === dirDriver
}
disabledReason={formik.values.editRestriction}
/>
))}
{hasSource &&
Expand Down
2 changes: 2 additions & 0 deletions src/util/storagePoolForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const isStoragePoolWithSource = (driver: string) => {
export const toStoragePoolFormValues = (
pool: LxdStoragePool,
poolOnMembers?: LXDStoragePoolOnClusterMember[],
editRestriction?: string,
): StoragePoolFormValues => {
const sourcePerClusterMember: ClusterSpecificValues = {};
const zfsPoolNamePerClusterMember: ClusterSpecificValues = {};
Expand Down Expand Up @@ -88,6 +89,7 @@ export const toStoragePoolFormValues = (
zfs_export: pool.config?.["zfs.export"],
zfs_pool_name: pool.config?.["zfs.pool_name"],
zfsPoolNamePerClusterMember,
editRestriction,
};
};

Expand Down

0 comments on commit 363f77c

Please sign in to comment.