Skip to content

Commit 794d439

Browse files
committed
fix bug- cant copy value field
1 parent f7df2df commit 794d439

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

src/components/dagshub/data-engine/metadataKeyValue/CustomTextField.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,22 @@ function CustomTextField({
118118
<Box
119119
sx={{ width: '100%', height: '100%' }}
120120
onMouseEnter={() => {
121+
//have the pencil logic only if a value already exists
121122
if (currentValue) {
122123
setHovered(true);
123124
}
124-
}} //have the pencil logic only if a value already exists
125+
}}
125126
onMouseLeave={() => {
127+
//have the pencil logic only if a value already exists
126128
if (currentValue) {
127129
setHovered(false);
128130
}
129-
}} //have the pencil logic only if a value already exists
131+
}}
130132
onMouseDown={(e) => {
131-
if (currentValue) {
133+
//When there is value, make text field not focused on a regular click, but only when clicking on the edit button, unless you are editing the value
134+
if (!isEditing && currentValue) {
132135
e.preventDefault();
133-
} //When there is value, make text field not focused on a regular click, but only when clicking on the edit button
136+
}
134137
}}
135138
ref={textFieldWrapperContainerRef}
136139
>

src/components/dagshub/data-engine/metadataKeyValue/MetadataKeyValueList.tsx

+27-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import AddIcon from '@mui/icons-material/Add';
77

88
export type MetadataType = 'BOOLEAN' | 'INTEGER' | 'FLOAT' | 'STRING' | 'BLOB';
99

10+
//The format used for managing the metadata list in the component
1011
export interface NewMetadataField {
1112
key?: string;
1213
value?: any;
@@ -16,6 +17,7 @@ export interface NewMetadataField {
1617
isNewlyCreated?: boolean;
1718
}
1819

20+
//The format the component expects to receive the metadata list
1921
export interface MetadataField {
2022
key: string;
2123
value: any;
@@ -24,13 +26,23 @@ export interface MetadataField {
2426
isAutoGenerated?: boolean;
2527
}
2628

29+
//The format the component returns the metadata list
30+
export interface DatapointMetadataInput {
31+
datapointId?: number;
32+
url?: string;
33+
key: string;
34+
value: string;
35+
valueType: MetadataType;
36+
allowMultiple?: boolean;
37+
}
38+
2739
export interface MetadataKeyValueListProps {
2840
maxHeight?: string;
2941
metadataList: MetadataField[];
3042
editingEnabled: boolean;
3143
deletionEnabled: boolean;
3244
onDeleteHandler?: (keyName: string) => void;
33-
onSaveHandler?: (metadataList: NewMetadataField[]) => void;
45+
onChangeHandler?: (metadataList: DatapointMetadataInput[]) => void;
3446
validateValueByType?: (valueType: MetadataType, value: string) => boolean;
3547
}
3648

@@ -40,7 +52,7 @@ export function MetadataKeyValueList({
4052
editingEnabled,
4153
deletionEnabled,
4254
onDeleteHandler,
43-
onSaveHandler,
55+
onChangeHandler,
4456
validateValueByType,
4557
}: MetadataKeyValueListProps) {
4658
//Todo:
@@ -68,10 +80,16 @@ export function MetadataKeyValueList({
6880
}
6981
}, [metadataList]);
7082

71-
//Todo: create a function to save changes
72-
// if (onSaveHandler) {
73-
// onSaveHandler({ ...temporaryMetadataList });
74-
// }
83+
const convertNewMetadataFieldToDatapointMetadataInput = (metadataList: NewMetadataField[]): DatapointMetadataInput[] => {
84+
return metadataList.map((metadataField) => {
85+
return {
86+
key: metadataField.key as string,
87+
value: metadataField.value as string,
88+
valueType: metadataField.valueType as MetadataType,
89+
allowMultiple: !!metadataField.multiple,
90+
};
91+
});
92+
}
7593

7694
useEffect(() => {
7795
if (shouldScrollToBottom && metadataFieldsSection.current) {
@@ -82,6 +100,9 @@ export function MetadataKeyValueList({
82100
setShouldScrollToBottom(false); //turn it off after scrolling
83101
}
84102
setAutoFocusNewlyCreatedFieldKey(true); //highlight again when the user adds new field
103+
104+
!!onChangeHandler && onChangeHandler(convertNewMetadataFieldToDatapointMetadataInput(temporaryMetadataList));
105+
85106
}, [temporaryMetadataList]);
86107

87108
useEffect(() => {

src/stories/elements/customAccordion/customAccordion.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ customAccordion.args = {
2727
]}
2828
editingEnabled={true}
2929
deletionEnabled={false}
30-
onSaveHandler={() => {}}
30+
onChangeHandler={() => {}}
3131
/>
3232
),
3333
};

0 commit comments

Comments
 (0)