Skip to content
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: add the slots property to the props #8498

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions webui/react/src/pages/ResourcePool/ResourcepoolDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ const ResourcepoolDetailInner: React.FC = () => {
const [tabKey, setTabKey] = useState<TabType>(tab ?? DEFAULT_POOL_TAB_KEY);
const [poolStats, setPoolStats] = useState<V1RPQueueStat>();

const topologyAgentPool = useMemo(
() => (poolname ? agents.filter(({ resourcePools }) => resourcePools.includes(poolname)) : []),
[poolname, agents],
);

const fetchStats = useCallback(async () => {
try {
const promises = [getJobQStats({}, { signal: canceler.signal })] as [
Expand Down Expand Up @@ -219,11 +224,7 @@ const ResourcepoolDetailInner: React.FC = () => {
size={ShirtSize.Large}
/>
</Section>
{!!agents.length && poolname && (
<Topology
nodes={agents.filter(({ resourcePools }) => resourcePools.includes(poolname))}
/>
)}
{!!topologyAgentPool.length && poolname && <Topology nodes={topologyAgentPool} />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: this looks better. I'm not too familiar here, but it's kind of odd that the ResourcepoolDetail.tsx doesn't make poolname required and is optional. Is there a case for the card to handle undefined value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just following the type 😅 , I also think that it doesn't make much sense having it as undefined...

string | undefined

<Section>
{pool.schedulerType === V1SchedulerType.ROUNDROBIN ? (
<Section>
Expand Down
2 changes: 1 addition & 1 deletion webui/react/src/pages/ResourcePool/Topology.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
.singleSlot {
width: 90px;
}
.fewSlot {
.coupleSlot {
width: 42px;
}
.active {
Expand Down
23 changes: 14 additions & 9 deletions webui/react/src/pages/ResourcePool/Topology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@ import Tooltip from 'hew/Tooltip';
import React, { PropsWithChildren, useEffect, useMemo, useRef, useState } from 'react';

import Section from 'components/Section';
import { Agent, Resource } from 'types';
import { Agent, Resource, SlotsRecord } from 'types';

import css from './Topology.module.scss';

interface NodeElementProps {
name: string;
slots: Resource[];
resources: Resource[];
slots?: SlotsRecord;
}

interface Props {
nodes: Agent[];
}

const NodeElement: React.FC<PropsWithChildren<NodeElementProps>> = ({ name, slots }) => {
const NodeElement: React.FC<PropsWithChildren<NodeElementProps>> = ({ name, slots, resources }) => {
const [containerWidth, setContainerWidth] = useState(0);
const shouldTruncate = useMemo(() => name.length > 5, [name]);
const slotsContainer = useRef<HTMLSpanElement>(null);
const singleSlot = slots.length === 1;
const fewSlot = slots.length === 2;
const slotsData = useMemo(
() => (slots !== undefined ? Object.values(slots) : resources),
[slots, resources],
);
const singleSlot = slotsData.length === 1;
const coupleSlot = slotsData.length === 2;
const styles = [css.nodeSlot];

if (singleSlot) styles.push(css.singleSlot);
if (fewSlot) styles.push(css.fewSlot);
if (coupleSlot) styles.push(css.coupleSlot);

useEffect(() => {
setContainerWidth(slotsContainer.current?.getBoundingClientRect().width || 0);
Expand All @@ -42,7 +47,7 @@ const NodeElement: React.FC<PropsWithChildren<NodeElementProps>> = ({ name, slot
<span className={css.nodeName}>{name}</span>
)}
<span className={css.nodeCluster} ref={slotsContainer}>
{slots.map(({ enabled }, idx) => (
{slotsData.map(({ enabled }, idx) => (
<span className={`${styles.join(' ')} ${enabled ? css.active : ''}`} key={`slot${idx}`} />
))}
</span>
Expand All @@ -54,8 +59,8 @@ const Topology: React.FC<PropsWithChildren<Props>> = ({ nodes }) => {
return (
<Section title="Topology">
<div className={`${css.mainContainer} ${css.nodesContainer}`}>
{nodes.map(({ id, resources }) => {
return <NodeElement key={id} name={id} slots={resources} />;
{nodes.map(({ id, resources, slots }) => {
return <NodeElement key={id} name={id} resources={resources} slots={slots} />;
})}
</div>
</Section>
Expand Down
5 changes: 4 additions & 1 deletion webui/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as t from 'io-ts';
import { RouteProps } from 'react-router-dom';

import * as Api from 'services/api-ts-sdk';
import { V1AgentUserGroup, V1Group, V1LaunchWarning, V1Trigger } from 'services/api-ts-sdk';
import { V1AgentUserGroup, V1Group, V1LaunchWarning, V1Slot, V1Trigger } from 'services/api-ts-sdk';
import { valueof, ValueOf } from 'utils/valueof';

export type { ValueOf } from 'utils/valueof';
Expand Down Expand Up @@ -233,10 +233,13 @@ export interface Resource {
uuid?: string;
}

export type SlotsRecord = { [k: string]: V1Slot };

export interface Agent {
id: string;
registeredTime: number;
resourcePools: string[];
slots?: SlotsRecord;
resources: Resource[];
}

Expand Down