-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(FR-343): migrate maintenance page to react by using SettingL…
…ist (#3009) ### This PR resolves [#3006](#3006) [(FR-343)](https://lablup.atlassian.net/browse/FR-343) **Changes** * Updated routing from LitElement to React components. * From now on, the `/maintenance` page will operate exclusively with React * Updated `SettingList` component * `isShowChangedOptionFilter`, `isShowResetButton`, and `isShowSearchBar` have been added as props to SettingList. Now, these features can be disabled when they are unnecessary. * Updated i18n. **Checklist:** (if applicable) - [ ] Mention to the original issue - [ ] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after [FR-343]: https://lablup.atlassian.net/browse/FR-343?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
1 parent
c04f7c9
commit 529a225
Showing
31 changed files
with
275 additions
and
578 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,141 @@ | ||
import { useSuspendedBackendaiClient } from '../hooks'; | ||
import { | ||
CLOSING_DURATION, | ||
useSetBAINotification, | ||
} from '../hooks/useBAINotification'; | ||
import SettingList, { SettingGroup } from './SettingList'; | ||
import { RedoOutlined } from '@ant-design/icons'; | ||
import { Button } from 'antd'; | ||
import { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
const MaintenanceSettingList = () => { | ||
const [isRecalculating, setIsRecalculating] = useState(false); | ||
const [isRescanning, setIsRescanning] = useState(false); | ||
|
||
const { t } = useTranslation(); | ||
const { upsertNotification } = useSetBAINotification(); | ||
const baiClient = useSuspendedBackendaiClient(); | ||
|
||
const recalculateUsage = () => { | ||
setIsRecalculating(true); | ||
|
||
upsertNotification({ | ||
message: t('maintenance.RecalculateUsage'), | ||
description: t('maintenance.Recalculating'), | ||
open: true, | ||
backgroundTask: { | ||
status: 'pending', | ||
promise: baiClient.maintenance | ||
.recalculate_usage() | ||
.finally(() => setIsRecalculating(false)), | ||
statusDescriptions: { | ||
pending: t('maintenance.Recalculating'), | ||
resolved: t('maintenance.RecalculationFinished'), | ||
rejected: t('maintenance.RecalculationFailed'), | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
const rescanImages = () => { | ||
setIsRescanning(true); | ||
const notiKey = upsertNotification({ | ||
message: t('maintenance.RescanImages'), | ||
description: t('maintenance.RescanImageScanning'), | ||
open: true, | ||
backgroundTask: { | ||
status: 'pending', | ||
}, | ||
}); | ||
// If values can be passed through resolve, please refactor the following function using promises | ||
baiClient.maintenance | ||
.rescan_images() | ||
.then(({ rescan_images }) => { | ||
if (rescan_images.ok) { | ||
upsertNotification({ | ||
key: notiKey, | ||
backgroundTask: { | ||
status: 'pending', | ||
percent: 0, | ||
taskId: rescan_images.task_id, | ||
statusDescriptions: { | ||
pending: t('maintenance.RescanImageScanning'), | ||
resolved: t('maintenance.RescanImageFinished'), | ||
rejected: t('maintenance.RescanFailed'), | ||
}, | ||
}, | ||
duration: 0, | ||
}); | ||
} else { | ||
throw new Error(t('maintenance.RescanFailed')); | ||
} | ||
}) | ||
.catch((err: any) => { | ||
upsertNotification({ | ||
key: notiKey, | ||
// description: painKiller.relieve(err?.title), | ||
backgroundTask: { | ||
status: 'rejected', | ||
statusDescriptions: { | ||
rejected: err?.message || t('maintenance.RescanFailed'), | ||
}, | ||
}, | ||
open: true, | ||
duration: CLOSING_DURATION, | ||
}); | ||
}) | ||
.finally(() => { | ||
setIsRescanning(false); | ||
}); | ||
}; | ||
|
||
const settingGroupList: SettingGroup = [ | ||
{ | ||
title: t('maintenance.Fix'), | ||
settingItems: [ | ||
{ | ||
type: 'custom', | ||
title: t('maintenance.MatchDatabase'), | ||
description: t('maintenance.DescMatchDatabase'), | ||
children: ( | ||
<Button | ||
icon={<RedoOutlined />} | ||
onClick={recalculateUsage} | ||
loading={isRecalculating} | ||
> | ||
{isRecalculating | ||
? t('maintenance.Recalculating') | ||
: t('maintenance.RecalculateUsage')} | ||
</Button> | ||
), | ||
}, | ||
], | ||
}, | ||
{ | ||
title: t('maintenance.ImagesEnvironment'), | ||
settingItems: [ | ||
{ | ||
type: 'custom', | ||
title: t('maintenance.RescanImageList'), | ||
description: t('maintenance.DescRescanImageList'), | ||
children: ( | ||
<Button | ||
icon={<RedoOutlined />} | ||
onClick={rescanImages} | ||
loading={isRescanning} | ||
> | ||
{isRescanning | ||
? t('maintenance.RescanImageScanning') | ||
: t('maintenance.RescanImages')} | ||
</Button> | ||
), | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
return <SettingList settingGroup={settingGroupList} showSearchBar />; | ||
}; | ||
|
||
export default MaintenanceSettingList; |
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
Oops, something went wrong.