-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: basic logic * feat: basic logic gpu runtime * feat: pricebox and quota box * fix: bug * chore: ubuntu-cuda svg * fix: price bug * fix: build bug * fix: gpu bug * fix: build bug * chore: pytorch svg * fix: delete will not be effective * chore: cursor->vscode * feat: detail support gpu * chore: name change * fix: gpu inventory bug * fix: delete devbox * fix: bug * fix: next build bug * fix: next build bug * chore:delete coonsole.log * perf: code shorten * chore: deploy update * fix: add runtimeClassName * fix: basic fix * fix: gpu bug * fix: type bug * chore: prettier modify * chore: prettier every file * fix: get->watch * fix: merge cause code bug * fix: yaml problem
- Loading branch information
Showing
37 changed files
with
653 additions
and
238 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
dist | ||
.vscode | ||
**/dist | ||
**/.vscode | ||
**/.DS_Store | ||
node_modules | ||
.next |
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
158 changes: 158 additions & 0 deletions
158
...ox/app/[lang]/(platform)/devbox/create/components/form/BasicConfiguration/GpuSelector.tsx
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,158 @@ | ||
import { useMemo } from 'react'; | ||
import { useTranslations } from 'next-intl'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { Box, Center, Flex } from '@chakra-ui/react'; | ||
import { MySelect, MyTooltip } from '@sealos/ui'; | ||
|
||
import Label from '../Label'; | ||
import { usePriceStore } from '@/stores/price'; | ||
import { DevboxEditTypeV2 } from '@/types/devbox'; | ||
import { GpuAmountMarkList } from '@/constants/devbox'; | ||
import { listOfficialTemplateRepository } from '@/api/template'; | ||
|
||
const labelWidth = 100; | ||
|
||
export default function GpuSelector({ | ||
countGpuInventory | ||
}: { | ||
countGpuInventory: (type: string) => number; | ||
}) { | ||
const t = useTranslations(); | ||
const { sourcePrice } = usePriceStore(); | ||
const { watch, setValue, getValues } = useFormContext<DevboxEditTypeV2>(); | ||
const templateRepositoryQuery = useQuery( | ||
['list-official-template-repository'], | ||
listOfficialTemplateRepository | ||
); | ||
|
||
const templateData = useMemo( | ||
() => templateRepositoryQuery.data?.templateRepositoryList || [], | ||
[templateRepositoryQuery.data] | ||
); | ||
const templateRepositoryUid = getValues('templateRepositoryUid'); | ||
const isGpuTemplate = useMemo(() => { | ||
const template = templateData.find((item) => item.uid === templateRepositoryUid); | ||
return template?.templateRepositoryTags.some((item) => item.tag.name === 'gpu'); | ||
}, [templateData, templateRepositoryUid]); | ||
|
||
const selectedGpu = () => { | ||
const selected = sourcePrice?.gpu?.find((item) => item.type === getValues('gpu.type')); | ||
if (!selected) return; | ||
return { | ||
...selected, | ||
inventory: countGpuInventory(selected.type) | ||
}; | ||
}; | ||
|
||
// add NoGPU select item | ||
const gpuSelectList = useMemo( | ||
() => | ||
sourcePrice?.gpu | ||
? [ | ||
{ | ||
label: t('No GPU'), | ||
value: '' | ||
}, | ||
...sourcePrice.gpu.map((item) => ({ | ||
icon: 'nvidia', | ||
label: ( | ||
<Flex> | ||
<Box color={'myGray.900'}>{item.alias}</Box> | ||
<Box mx={3} color={'grayModern.900'}> | ||
| | ||
</Box> | ||
<Box color={'grayModern.900'}> | ||
{t('vm')} : {Math.round(item.vm)}G | ||
</Box> | ||
<Box mx={3} color={'grayModern.900'}> | ||
| | ||
</Box> | ||
<Flex pr={3}> | ||
<Box color={'grayModern.900'}>{t('Inventory')} : </Box> | ||
<Box color={'#FB7C3C'}>{countGpuInventory(item.type)}</Box> | ||
</Flex> | ||
</Flex> | ||
), | ||
value: item.type | ||
})) | ||
] | ||
: [], | ||
[countGpuInventory, t, sourcePrice?.gpu] | ||
); | ||
|
||
if (!isGpuTemplate || !sourcePrice?.gpu) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Box mb={7}> | ||
<Flex alignItems={'center'}> | ||
<Label w={100}>GPU</Label> | ||
<MySelect | ||
width={'300px'} | ||
placeholder={t('No GPU') || ''} | ||
value={getValues('gpu.type')} | ||
list={gpuSelectList} | ||
onchange={(type: any) => { | ||
const selected = sourcePrice?.gpu?.find((item) => item.type === type); | ||
const inventory = countGpuInventory(type); | ||
if (type === '' || (selected && inventory > 0)) { | ||
setValue('gpu.type', type); | ||
} | ||
}} | ||
/> | ||
</Flex> | ||
{!!watch('gpu.type') && ( | ||
<Box mt={4} pl={`${labelWidth}px`}> | ||
<Box mb={1}>{t('Amount')}</Box> | ||
<Flex alignItems={'center'}> | ||
{GpuAmountMarkList.map((item) => { | ||
const inventory = selectedGpu()?.inventory || 0; | ||
|
||
const hasInventory = item.value <= inventory; | ||
|
||
return ( | ||
<MyTooltip key={item.value} label={hasInventory ? '' : t('Under Stock')}> | ||
<Center | ||
mr={2} | ||
w={'32px'} | ||
h={'32px'} | ||
borderRadius={'md'} | ||
border={'1px solid'} | ||
bg={'white'} | ||
{...(getValues('gpu.amount') === item.value | ||
? { | ||
borderColor: 'brightBlue.500', | ||
boxShadow: '0px 0px 0px 2.4px rgba(33, 155, 244, 0.15)' | ||
} | ||
: { | ||
borderColor: 'grayModern.200', | ||
bgColor: 'grayModern.100' | ||
})} | ||
{...(hasInventory | ||
? { | ||
cursor: 'pointer', | ||
onClick: () => { | ||
setValue('gpu.amount', item.value); | ||
} | ||
} | ||
: { | ||
cursor: 'default', | ||
opacity: 0.5 | ||
})} | ||
> | ||
{item.label} | ||
</Center> | ||
</MyTooltip> | ||
); | ||
})} | ||
<Box ml={3} color={'MyGray.500'}> | ||
/ {t('Card')} | ||
</Box> | ||
</Flex> | ||
</Box> | ||
)} | ||
</Box> | ||
); | ||
} |
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
Oops, something went wrong.