feat: update storage schema (#1142)

This commit is contained in:
boojack
2023-02-24 00:02:51 +08:00
committed by GitHub
parent 84fb8b2288
commit 9c5b44d070
9 changed files with 271 additions and 229 deletions

View File

@ -13,16 +13,12 @@ const StorageSection = () => {
const globalStore = useGlobalStore();
const systemStatus = globalStore.state.systemStatus;
const [storageServiceId, setStorageServiceId] = useState(systemStatus.storageServiceId);
const [storageList, setStorageList] = useState<Storage[]>([]);
const [storageList, setStorageList] = useState<ObjectStorage[]>([]);
useEffect(() => {
fetchStorageList();
}, []);
useEffect(() => {
setStorageServiceId(systemStatus.storageServiceId);
}, [systemStatus]);
const fetchStorageList = async () => {
const {
data: { data: storageList },
@ -31,6 +27,10 @@ const StorageSection = () => {
};
const handleActiveStorageServiceChanged = async (storageId: StorageId) => {
if (storageList.length === 0) {
return;
}
await api.upsertSystemSetting({
name: "storageServiceId",
value: JSON.stringify(storageId),
@ -38,7 +38,7 @@ const StorageSection = () => {
setStorageServiceId(storageId);
};
const handleDeleteStorage = (storage: Storage) => {
const handleDeleteStorage = (storage: ObjectStorage) => {
showCommonDialog({
title: t("setting.storage-section.delete-storage"),
content: t("setting.storage-section.warning-text"),
@ -68,12 +68,12 @@ const StorageSection = () => {
handleActiveStorageServiceChanged(storageId || 0);
}}
>
<Option value={0}>Database</Option>
{storageList.map((storage) => (
<Option key={storage.id} value={storage.id}>
{storage.name}
</Option>
))}
<Option value={0}>Database</Option>
</Select>
<Divider />
<div className="mt-4 mb-2 w-full flex flex-row justify-start items-center">