-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from KKoukiou/storage-pre-cockpit-cleanup
Prepare for the blivet-gui / cockpit-storage migration
- Loading branch information
Showing
7 changed files
with
160 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2.1 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with This program; If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import { useEffect, useState } from "react"; | ||
|
||
import { | ||
getDiskFreeSpace, | ||
getDiskTotalSpace, | ||
getMountPointConstraints, | ||
getRequiredDeviceSize, | ||
} from "../../apis/storage_devicetree.js"; | ||
import { | ||
getRequiredSpace | ||
} from "../../apis/payloads.js"; | ||
import { findDuplicatesInArray } from "../../helpers/utils.js"; | ||
|
||
export const useDiskTotalSpace = ({ selectedDisks, devices }) => { | ||
const [diskTotalSpace, setDiskTotalSpace] = useState(); | ||
|
||
useEffect(() => { | ||
const update = async () => { | ||
const diskTotalSpace = await getDiskTotalSpace({ diskNames: selectedDisks }); | ||
|
||
setDiskTotalSpace(diskTotalSpace); | ||
}; | ||
update(); | ||
}, [selectedDisks, devices]); | ||
|
||
return diskTotalSpace; | ||
}; | ||
|
||
export const useDiskFreeSpace = ({ selectedDisks, devices }) => { | ||
const [diskFreeSpace, setDiskFreeSpace] = useState(); | ||
|
||
useEffect(() => { | ||
const update = async () => { | ||
const diskFreeSpace = await getDiskFreeSpace({ diskNames: selectedDisks }); | ||
|
||
setDiskFreeSpace(diskFreeSpace); | ||
}; | ||
update(); | ||
}, [selectedDisks, devices]); | ||
|
||
return diskFreeSpace; | ||
}; | ||
|
||
export const useDuplicateDeviceNames = ({ deviceNames }) => { | ||
const [duplicateDeviceNames, setDuplicateDeviceNames] = useState([]); | ||
|
||
useEffect(() => { | ||
const update = async () => { | ||
const _duplicateDeviceNames = findDuplicatesInArray(deviceNames); | ||
|
||
setDuplicateDeviceNames(_duplicateDeviceNames); | ||
}; | ||
update(); | ||
}, [deviceNames]); | ||
|
||
return duplicateDeviceNames; | ||
}; | ||
|
||
export const useHasFilesystems = ({ selectedDisks, devices }) => { | ||
const [hasFilesystems, setHasFilesystems] = useState(); | ||
|
||
useEffect(() => { | ||
const _hasFilesystems = ( | ||
selectedDisks.some(device => ( | ||
devices[device]?.children.v.some(child => ( | ||
devices[child]?.formatData.mountable.v || devices[child]?.formatData.type.v === "luks") | ||
) | ||
)) | ||
); | ||
|
||
setHasFilesystems(_hasFilesystems); | ||
}, [selectedDisks, devices]); | ||
|
||
return hasFilesystems; | ||
}; | ||
|
||
export const useRequiredSize = () => { | ||
const [requiredSize, setRequiredSize] = useState(); | ||
|
||
useEffect(() => { | ||
const update = async () => { | ||
const requiredSpace = await getRequiredSpace().catch(console.error); | ||
const requiredSize = await getRequiredDeviceSize({ requiredSpace }).catch(console.error); | ||
|
||
setRequiredSize(requiredSize); | ||
}; | ||
update(); | ||
}, []); | ||
|
||
return requiredSize; | ||
}; | ||
|
||
export const useMountPointConstraints = () => { | ||
const [mountPointConstraints, setMountPointConstraints] = useState(); | ||
|
||
useEffect(() => { | ||
const update = async () => { | ||
const mountPointConstraints = await getMountPointConstraints().catch(console.error); | ||
setMountPointConstraints(mountPointConstraints); | ||
}; | ||
update(); | ||
}, []); | ||
|
||
return mountPointConstraints; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters