-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Use filtered resource pools when creating notebook #9045
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ import { paths } from 'routes/utils'; | |
import { getTaskTemplates } from 'services/api'; | ||
import clusterStore from 'stores/cluster'; | ||
import workspaceStore from 'stores/workspaces'; | ||
import { RawJson, Template, Workspace } from 'types'; | ||
import { RawJson, ResourcePool, Template, Workspace } from 'types'; | ||
import handleError from 'utils/error'; | ||
import { JupyterLabOptions, launchJupyterLab, previewJupyterLab } from 'utils/jupyter'; | ||
import { useObservable } from 'utils/observable'; | ||
|
@@ -349,12 +349,23 @@ const JupyterLabForm: React.FC<{ | |
}> = ({ form, formId, currentWorkspace, defaults, lockedWorkspace, setWorkspace, workspaces }) => { | ||
const [templates, setTemplates] = useState<Template[]>([]); | ||
|
||
const resourcePools = Loadable.getOrElse([], useObservable(clusterStore.resourcePools)); | ||
const selectedWorkspace = Form.useWatch('workspaceId', form); | ||
|
||
const resourcePools = useObservable(clusterStore.resourcePools); | ||
const boundResourcePoolsMap = useObservable(workspaceStore.boundResourcePoolsMap()); | ||
|
||
const boundResourcePools: ResourcePool[] = useMemo(() => { | ||
if (!Loadable.isLoaded(resourcePools) || !boundResourcePoolsMap || !selectedWorkspace) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does nit: |
||
return []; | ||
return resourcePools.data.filter( | ||
(rp) => boundResourcePoolsMap.get(selectedWorkspace)?.includes(rp.name), | ||
); | ||
}, [resourcePools, boundResourcePoolsMap, selectedWorkspace]); | ||
|
||
const selectedPoolName = Form.useWatch('pool', form); | ||
|
||
const resourceInfo = useMemo(() => { | ||
const selectedPool = resourcePools.find((pool) => pool.name === selectedPoolName); | ||
const selectedPool = boundResourcePools.find((pool) => pool.name === selectedPoolName); | ||
if (!selectedPool) return { hasAux: false, hasCompute: false, maxSlots: 0 }; | ||
|
||
/** | ||
|
@@ -372,7 +383,7 @@ const JupyterLabForm: React.FC<{ | |
hasCompute: hasComputeCapacity, | ||
maxSlots: maxSlots, | ||
}; | ||
}, [selectedPoolName, resourcePools]); | ||
}, [selectedPoolName, boundResourcePools]); | ||
|
||
useEffect(() => { | ||
if (!resourceInfo.hasCompute && resourceInfo.hasAux) form.setFieldValue('slots', 0); | ||
|
@@ -382,6 +393,10 @@ const JupyterLabForm: React.FC<{ | |
} | ||
}, [resourceInfo, form]); | ||
|
||
useEffect(() => { | ||
selectedWorkspace && workspaceStore.fetchAvailableResourcePools(selectedWorkspace); | ||
}, [selectedWorkspace]); | ||
|
||
const fetchTemplates = useCallback(async () => { | ||
try { | ||
setTemplates(await getTaskTemplates({})); | ||
|
@@ -396,11 +411,11 @@ const JupyterLabForm: React.FC<{ | |
|
||
useEffect(() => { | ||
const fields = form.getFieldsValue(true); | ||
if (!fields?.pool && resourcePools[0]?.name) { | ||
const firstPoolInList = resourcePools[0]?.name; | ||
if (!fields?.pool && boundResourcePools[0]?.name) { | ||
const firstPoolInList = boundResourcePools[0]?.name; | ||
form.setFieldValue('pool', firstPoolInList); | ||
} | ||
}, [resourcePools, form]); | ||
}, [boundResourcePools, form]); | ||
|
||
useEffect(() => { | ||
form.setFieldValue('workspaceId', currentWorkspace?.id); | ||
|
@@ -442,9 +457,9 @@ const JupyterLabForm: React.FC<{ | |
<Form.Item initialValue={defaults?.name} label="Name" name="name"> | ||
<Input placeholder="Name (optional)" /> | ||
</Form.Item> | ||
<Form.Item initialValue={defaults?.pool} label="Resource Pool" name="pool"> | ||
<Select allowClear placeholder="Pick the best option"> | ||
{resourcePools.map((pool) => ( | ||
<Form.Item label="Resource Pool" name="pool"> | ||
<Select allowClear disabled={!selectedWorkspace} placeholder="Pick the best option"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: i dont think workspace id would take |
||
{boundResourcePools.map((pool) => ( | ||
<Option key={pool.name} value={pool.name}> | ||
{pool.name} | ||
</Option> | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -129,6 +129,8 @@ class WorkspaceStore extends PollingStore { | |||||
public readonly boundResourcePools = (workspaceId: number) => | ||||||
this.#boundResourcePools.select((map) => map.get(workspaceId)?.toJS()); | ||||||
|
||||||
public readonly boundResourcePoolsMap = () => this.#boundResourcePools.readOnly(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that need to be a function?
Suggested change
|
||||||
|
||||||
public async fetchAvailableResourcePools(workspaceId: number) { | ||||||
const response = await getAvailableResourcePools({ workspaceId }); | ||||||
this.#boundResourcePools.update((map) => map.set(workspaceId, List(response))); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: