Skip to content

Commit

Permalink
Auto scroll on expanding deployed models tab and auto expand when dep…
Browse files Browse the repository at this point in the history
…loying models
  • Loading branch information
DaoDaoNoCode committed Aug 9, 2023
1 parent 84afc4c commit 2c7a13e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
24 changes: 15 additions & 9 deletions frontend/src/components/ScrollViewOnMount.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import * as React from 'react';

const ScrollViewOnMount: React.FC = () => (
<div
ref={(elm) => {
if (elm) {
elm.scrollIntoView();
}
}}
/>
);
type ScrollViewOnMountProps = {
shouldScroll: boolean;
};

const ScrollViewOnMount: React.FC<ScrollViewOnMountProps> = ({ shouldScroll }) => {
const ref = React.useRef<HTMLDivElement>(null);

React.useEffect(() => {
if (shouldScroll && ref.current) {
ref.current?.scrollIntoView();
}
}, [shouldScroll]);

return <div ref={ref} />;
};

export default ScrollViewOnMount;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Table from '~/components/table/Table';
import useTableColumnSort from '~/components/table/useTableColumnSort';
import { ServingRuntimeKind } from '~/k8sTypes';
import { ProjectDetailsContext } from '~/pages/projects/ProjectDetailsContext';
import { ServingRuntimeTableTabs } from '~/pages/modelServing/screens/types';
import { columns } from './data';
import ServingRuntimeTableRow from './ServingRuntimeTableRow';
import DeleteServingRuntimeModal from './DeleteServingRuntimeModal';
Expand All @@ -25,6 +26,7 @@ const ServingRuntimeTable: React.FC<ServingRuntimeTableProps> = ({
const [deployServingRuntime, setDeployServingRuntime] = React.useState<ServingRuntimeKind>();
const [deleteServingRuntime, setDeleteServingRuntime] = React.useState<ServingRuntimeKind>();
const [editServingRuntime, setEditServingRuntime] = React.useState<ServingRuntimeKind>();
const [expandedColumn, setExpandedColumn] = React.useState<ServingRuntimeTableTabs>();

const {
dataConnections: { data: dataConnections },
Expand All @@ -48,7 +50,9 @@ const ServingRuntimeTable: React.FC<ServingRuntimeTableProps> = ({
obj={modelServer}
onDeleteServingRuntime={(obj) => setDeleteServingRuntime(obj)}
onEditServingRuntime={(obj) => setEditServingRuntime(obj)}
onDeployModal={(obj) => setDeployServingRuntime(obj)}
onDeployModel={(obj) => setDeployServingRuntime(obj)}
expandedColumn={expandedColumn}
setExpandedColumn={setExpandedColumn}
/>
)}
/>
Expand Down Expand Up @@ -86,6 +90,7 @@ const ServingRuntimeTable: React.FC<ServingRuntimeTableProps> = ({
setDeployServingRuntime(undefined);
if (submit) {
refreshInferenceServices();
setExpandedColumn(ServingRuntimeTableTabs.DEPLOYED_MODELS);
}
}}
projectContext={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const ServingRuntimeTableExpandedSection: React.FC<ServingRuntimeTableExpandedSe
) : (
<EmptyInferenceServicesCell onDeployModel={onDeployModel} />
)}
<ScrollViewOnMount />
<ScrollViewOnMount
shouldScroll={activeColumn === ServingRuntimeTableTabs.DEPLOYED_MODELS}
/>
</ExpandableRowContent>
</Td>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ type ServingRuntimeTableRowProps = {
obj: ServingRuntimeKind;
onDeleteServingRuntime: (obj: ServingRuntimeKind) => void;
onEditServingRuntime: (obj: ServingRuntimeKind) => void;
onDeployModal: (obj: ServingRuntimeKind) => void;
onDeployModel: (obj: ServingRuntimeKind) => void;
expandedColumn?: ServingRuntimeTableTabs;
setExpandedColumn: (column?: ServingRuntimeTableTabs) => void;
};

const ServingRuntimeTableRow: React.FC<ServingRuntimeTableRowProps> = ({
obj,
onDeleteServingRuntime,
onEditServingRuntime,
onDeployModal,
onDeployModel,
expandedColumn,
setExpandedColumn,
}) => {
const [expandedColumn, setExpandedColumn] = React.useState<ServingRuntimeTableTabs | undefined>();

const {
inferenceServices: {
data: inferenceServices,
Expand Down Expand Up @@ -118,7 +120,7 @@ const ServingRuntimeTableRow: React.FC<ServingRuntimeTableRowProps> = ({
</Td>
<Td style={{ textAlign: 'end' }}>
<Button
onClick={() => onDeployModal(obj)}
onClick={() => onDeployModel(obj)}
key={`action-${ProjectSectionID.CLUSTER_STORAGES}`}
variant="secondary"
>
Expand All @@ -145,7 +147,7 @@ const ServingRuntimeTableRow: React.FC<ServingRuntimeTableRowProps> = ({
activeColumn={expandedColumn}
obj={obj}
onClose={() => setExpandedColumn(undefined)}
onDeployModel={() => onDeployModal(obj)}
onDeployModel={() => onDeployModel(obj)}
/>
</Tr>
</Tbody>
Expand Down

0 comments on commit 2c7a13e

Please sign in to comment.