Skip to content

Commit 0fa7dbf

Browse files
authored
Update ModelPropertiesDescriptionListGroup component filtering logic (#1297)
* Update ModelPropertiesDescriptionListGroup component filtering logic Signed-off-by: Juntao Wang <[email protected]> * Add hasError prop to ModelRegistrySelector Signed-off-by: Juntao Wang <[email protected]> * address comments Signed-off-by: Juntao Wang <[email protected]> --------- Signed-off-by: Juntao Wang <[email protected]>
1 parent 6b11b58 commit 0fa7dbf

File tree

5 files changed

+70
-36
lines changed

5 files changed

+70
-36
lines changed

clients/ui/frontend/src/app/pages/modelRegistry/screens/ModelPropertiesDescriptionListGroup.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ import { PlusCircleIcon } from '@patternfly/react-icons';
55
import text from '@patternfly/react-styles/css/utilities/Text/text';
66
import spacing from '@patternfly/react-styles/css/utilities/Spacing/spacing';
77
import { DashboardDescriptionListGroup } from 'mod-arch-shared';
8-
import {
9-
filterCustomProperties,
10-
getProperties,
11-
mergeUpdatedProperty,
12-
} from '~/app/pages/modelRegistry/screens/utils';
8+
import { getProperties, mergeUpdatedProperty } from '~/app/pages/modelRegistry/screens/utils';
139
import { ModelRegistryCustomProperties } from '~/app/types';
1410
import ModelPropertiesTableRow from '~/app/pages/modelRegistry/screens/ModelPropertiesTableRow';
15-
import { pipelineRunSpecificKeys } from './ModelVersionDetails/const';
1611

1712
type ModelPropertiesDescriptionListGroupProps = {
1813
customProperties: ModelRegistryCustomProperties;
@@ -35,13 +30,9 @@ const ModelPropertiesDescriptionListGroup: React.FC<ModelPropertiesDescriptionLi
3530
const isEditingSomeRow = isAdding || editingPropertyKeys.length > 0;
3631

3732
const [isSavingEdits, setIsSavingEdits] = React.useState(false);
38-
const filteredCustomProperties = filterCustomProperties(
39-
customProperties,
40-
pipelineRunSpecificKeys,
41-
);
4233

4334
// We only show string properties with a defined value (no labels or other property types)
44-
const filteredProperties = getProperties(filteredCustomProperties);
35+
const filteredProperties = getProperties(customProperties);
4536

4637
const [isShowingMoreProperties, setIsShowingMoreProperties] = React.useState(false);
4738
const keys = Object.keys(filteredProperties);

clients/ui/frontend/src/app/pages/modelRegistry/screens/ModelRegistrySelector.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ type ModelRegistrySelectorProps = {
3636
onSelection: (modelRegistry: string) => void;
3737
primary?: boolean;
3838
isFullWidth?: boolean;
39+
hasError?: boolean;
3940
};
4041

4142
const ModelRegistrySelector: React.FC<ModelRegistrySelectorProps> = ({
4243
modelRegistry,
4344
onSelection,
4445
primary,
4546
isFullWidth,
47+
hasError,
4648
}) => {
4749
const { modelRegistries, updatePreferredModelRegistry } = React.useContext(
4850
ModelRegistrySelectorContext,
@@ -97,7 +99,7 @@ const ModelRegistrySelector: React.FC<ModelRegistrySelectorProps> = ({
9799
isScrollable
98100
placeholder="Select a model registry"
99101
dataTestId="model-registry-selector-dropdown"
100-
toggleProps={{ id: 'download-steps-logs-toggle' }}
102+
toggleProps={{ id: 'download-steps-logs-toggle', status: hasError ? 'danger' : undefined }}
101103
toggleLabel={toggleLabel}
102104
aria-label="Model registry toggle"
103105
previewDescription={false}

clients/ui/frontend/src/app/pages/modelRegistry/screens/ModelVersionDetails/const.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,3 @@ export enum ModelVersionDetailsTabTitle {
77
DETAILS = 'Details',
88
DEPLOYMENTS = 'Deployments',
99
}
10-
export const pipelineRunSpecificKeys: string[] = [
11-
'_registeredFromPipelineProject',
12-
'_registeredFromPipelineRunId',
13-
'_registeredFromPipelineRunName',
14-
];
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* eslint-disable camelcase */
2+
import {
3+
ModelRegistryCustomProperties,
4+
ModelRegistryMetadataType,
5+
ModelRegistryStringCustomProperties,
6+
} from '~/app/types';
7+
import { getProperties } from '~/app/pages/modelRegistry/screens/utils';
8+
9+
describe('getProperties', () => {
10+
it('should return an empty object when customProperties is empty', () => {
11+
const customProperties: ModelRegistryCustomProperties = {};
12+
const result = getProperties(customProperties);
13+
expect(result).toEqual({});
14+
});
15+
16+
it('should return a filtered object including only string properties with a non-empty value', () => {
17+
const customProperties: ModelRegistryCustomProperties = {
18+
property1: { metadataType: ModelRegistryMetadataType.STRING, string_value: 'non-empty' },
19+
property2: {
20+
metadataType: ModelRegistryMetadataType.STRING,
21+
string_value: 'another-non-empty',
22+
},
23+
label1: { metadataType: ModelRegistryMetadataType.STRING, string_value: '' },
24+
label2: { metadataType: ModelRegistryMetadataType.STRING, string_value: '' },
25+
int1: { metadataType: ModelRegistryMetadataType.INT, int_value: '1' },
26+
int2: { metadataType: ModelRegistryMetadataType.INT, int_value: '2' },
27+
};
28+
const result = getProperties(customProperties);
29+
expect(result).toEqual({
30+
property1: { metadataType: ModelRegistryMetadataType.STRING, string_value: 'non-empty' },
31+
property2: {
32+
metadataType: ModelRegistryMetadataType.STRING,
33+
string_value: 'another-non-empty',
34+
},
35+
} satisfies ModelRegistryStringCustomProperties);
36+
});
37+
38+
it('should return an empty object when all values in customProperties are empty strings or non-string values', () => {
39+
const customProperties: ModelRegistryCustomProperties = {
40+
label1: { metadataType: ModelRegistryMetadataType.STRING, string_value: '' },
41+
label2: { metadataType: ModelRegistryMetadataType.STRING, string_value: '' },
42+
int1: { metadataType: ModelRegistryMetadataType.INT, int_value: '1' },
43+
int2: { metadataType: ModelRegistryMetadataType.INT, int_value: '2' },
44+
};
45+
const result = getProperties(customProperties);
46+
expect(result).toEqual({});
47+
});
48+
49+
it('should return with _lastModified and _registeredFrom props filtered out', () => {
50+
const customProperties: ModelRegistryCustomProperties = {
51+
property1: { metadataType: ModelRegistryMetadataType.STRING, string_value: 'non-empty' },
52+
_lastModified: { metadataType: ModelRegistryMetadataType.STRING, string_value: 'non-empty' },
53+
_registeredFromSomething: {
54+
metadataType: ModelRegistryMetadataType.STRING,
55+
string_value: 'non-empty',
56+
},
57+
};
58+
const result = getProperties(customProperties);
59+
expect(result).toEqual({
60+
property1: { metadataType: ModelRegistryMetadataType.STRING, string_value: 'non-empty' },
61+
});
62+
});
63+
});

clients/ui/frontend/src/app/pages/modelRegistry/screens/utils.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ export const mergeUpdatedLabels = (
4545
return customPropertiesCopy;
4646
};
4747

48-
// Retrives the customProperties that are not labels (they have a defined string_value).
48+
// Retrieves the customProperties that are not special (_registeredFrom) or labels (they have a defined string_value).
4949
export const getProperties = <T extends ModelRegistryCustomProperties>(
5050
customProperties: T,
5151
): ModelRegistryStringCustomProperties => {
5252
const initial: ModelRegistryStringCustomProperties = {};
5353
return Object.keys(customProperties).reduce((acc, key) => {
5454
// _lastModified is a property that is required to update the timestamp on the backend and we have a workaround for it. It should be resolved by
5555
// backend team
56-
if (key === '_lastModified') {
56+
if (key === '_lastModified' || /^_registeredFrom/.test(key)) {
5757
return acc;
5858
}
5959

@@ -183,21 +183,4 @@ export const isValidHttpUrl = (value: string): boolean => {
183183
}
184184
};
185185

186-
export const filterCustomProperties = (
187-
customProperties: ModelRegistryCustomProperties,
188-
keys: string[],
189-
): ModelRegistryCustomProperties => {
190-
const filteredCustomProperties: ModelRegistryCustomProperties = {};
191-
Object.keys(customProperties).forEach((key) => {
192-
if (!keys.includes(key)) {
193-
filteredCustomProperties[key] = customProperties[key];
194-
}
195-
});
196-
return filteredCustomProperties;
197-
};
198-
199-
export const isPipelineRunExist = (
200-
customProperties: ModelRegistryCustomProperties,
201-
keys: string[],
202-
): boolean => keys.every((key) => key in customProperties);
203186
export const isRedHatRegistryUri = (uri: string): boolean => uri.startsWith('oci://example.io/'); // TODO: Change this to a proper check

0 commit comments

Comments
 (0)