From 76aa6dd5156df9f154e2572816dd171f8fb83ae1 Mon Sep 17 00:00:00 2001 From: Jeff Phillips Date: Fri, 27 Aug 2021 14:23:22 -0400 Subject: [PATCH] Hide and un-schedulable sizes from the Size selection (#38) --- .../ui/src/SizesForm/SizesForm.tsx | 38 ++++++++++++------- .../ui/src/__mock__/mockData.ts | 19 +++++++++- .../ui/src/utils/types.ts | 1 + 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/jupyterhub_singleuser_profiles/ui/src/SizesForm/SizesForm.tsx b/jupyterhub_singleuser_profiles/ui/src/SizesForm/SizesForm.tsx index 9a14f587..87d9ce7e 100644 --- a/jupyterhub_singleuser_profiles/ui/src/SizesForm/SizesForm.tsx +++ b/jupyterhub_singleuser_profiles/ui/src/SizesForm/SizesForm.tsx @@ -58,9 +58,9 @@ const SizesForm: React.FC = ({ uiConfig }) => { return; } const promises = sizeList.map((size) => APIGet(`${SINGLE_SIZE_PATH}/${size}`)); - Promise.all(promises).then((results) => { + Promise.all(promises).then((results: SizeDescription[]) => { if (!cancelled) { - setSizeDescriptions(results as SizeDescription[]); + setSizeDescriptions(results); } }); return () => { @@ -96,20 +96,30 @@ const SizesForm: React.FC = ({ uiConfig }) => { ['Default'], ); - const getDescription = (size: string): string => { - const description = sizeDescriptions?.find((desc) => desc?.name === size); - if (description) { - return ( - `Limits: ${description.resources.limits.cpu} CPU, ${description.resources.limits.memory} Memory ` + - `Requests: ${description.resources.requests.cpu} CPU, ${description.resources.requests.memory} Memory` + return sizes.reduce((acc, size) => { + const sizeDescription = sizeDescriptions?.find((desc) => desc?.name === size); + if (!sizeDescription) { + acc.push( + , + ); + } else if (sizeDescription.schedulable !== false) { + acc.push( + , ); } - return 'Resources set based on administrator configurations'; - }; - - return sizes.map((size) => ( - - )); + return acc; + }, [] as React.ReactElement[]); }, [sizeList, sizeDescriptions]); const gpuOptions = React.useMemo(() => { diff --git a/jupyterhub_singleuser_profiles/ui/src/__mock__/mockData.ts b/jupyterhub_singleuser_profiles/ui/src/__mock__/mockData.ts index cb63432c..d248e836 100644 --- a/jupyterhub_singleuser_profiles/ui/src/__mock__/mockData.ts +++ b/jupyterhub_singleuser_profiles/ui/src/__mock__/mockData.ts @@ -14,6 +14,7 @@ type MockDataType = { ['size/Small']: SizeDescription; ['size/Medium']: SizeDescription; ['size/Large']: SizeDescription; + ['size/Huge']: SizeDescription; [UI_CONFIG_PATH]: UiConfigType; [DEFAULT_IMAGE_PATH]: string; }; @@ -26,7 +27,7 @@ export const mockData: MockDataType = { last_selected_size: 'Default', }, [DEFAULT_IMAGE_PATH]: 's2i-generic-data-science-notebook:v0.0.4', - [SIZES_PATH]: ['Small', 'Medium', 'Large'], + [SIZES_PATH]: ['Small', 'Medium', 'Large', 'Huge'], [IMAGE_PATH]: [ { description: @@ -390,6 +391,7 @@ export const mockData: MockDataType = { memory: '1Gi', }, }, + schedulable: true, }, ['size/Medium']: { name: 'Medium', @@ -403,6 +405,7 @@ export const mockData: MockDataType = { memory: '2Gi', }, }, + schedulable: true, }, ['size/Large']: { name: 'Large', @@ -417,6 +420,20 @@ export const mockData: MockDataType = { }, }, }, + ['size/Huge']: { + name: 'Huge', + resources: { + limits: { + cpu: 16, + memory: '18Gi', + }, + requests: { + cpu: 8, + memory: '8Gi', + }, + }, + schedulable: false, + }, [UI_CONFIG_PATH]: { envVarConfig: { categories: [ diff --git a/jupyterhub_singleuser_profiles/ui/src/utils/types.ts b/jupyterhub_singleuser_profiles/ui/src/utils/types.ts index 3d5cf811..43105cbe 100644 --- a/jupyterhub_singleuser_profiles/ui/src/utils/types.ts +++ b/jupyterhub_singleuser_profiles/ui/src/utils/types.ts @@ -76,6 +76,7 @@ export type SizeDescription = { memory: string; }; }; + schedulable?: boolean; }; //