Skip to content

Commit fb803a4

Browse files
committed
send patch to groupname rather than base
1 parent 05a3ac5 commit fb803a4

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

src/components/Dashboard/EditBulkTerms/EditBulkTermsDialog.jsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ HeaderRightSideContent.propTypes = {
7171
};
7272

7373
const EditBulkTermsDialog = ({ open, handleClose, activeStep, setActiveStep }) => {
74-
const { activeOntology } = useContext(GlobalDataContext);
74+
const { activeOntology, user } = useContext(GlobalDataContext);
7575
const [searchConditions, setSearchConditions] = useState([initialSearchConditions]);
7676
const [ontologyTerms, setOntologyTerms] = useState([]);
7777
const [ontologyAttributes, setOntologyAttributes] = useState([]);
@@ -88,6 +88,28 @@ const EditBulkTermsDialog = ({ open, handleClose, activeStep, setActiveStep }) =
8888
}
8989
}, [open, activeOntology, selectedOntology]);
9090

91+
// Helper function to replace "base" with user groupname in term data
92+
const replaceBaseWithUserGroup = (obj, userGroupname) => {
93+
if (!obj || !userGroupname) return obj;
94+
95+
const replaceInValue = (value) => {
96+
if (typeof value === 'string') {
97+
return value.replace(/\bbase\b/g, userGroupname);
98+
} else if (Array.isArray(value)) {
99+
return value.map(replaceInValue);
100+
} else if (value && typeof value === 'object') {
101+
return replaceBaseWithUserGroup(value, userGroupname);
102+
}
103+
return value;
104+
};
105+
106+
const result = {};
107+
for (const [key, value] of Object.entries(obj)) {
108+
result[key] = replaceInValue(value);
109+
}
110+
return result;
111+
};
112+
91113
const performBatchUpdate = async (termsToUpdate = null) => {
92114
setIsUpdating(true);
93115

@@ -117,19 +139,25 @@ const EditBulkTermsDialog = ({ open, handleClose, activeStep, setActiveStep }) =
117139
termId = termId.split('/').pop();
118140
}
119141

120-
const group = 'base'; // Default group, can be made configurable
142+
// Use user's groupname instead of 'base'
143+
const group = user?.groupname || 'base';
121144

122-
// Create the JSON-LD payload with the current term data
123-
const jsonLdPayload = {
145+
// Create the JSON-LD payload with the current term data, replacing base with user groupname
146+
let jsonLdPayload = {
124147
"@context": term["@context"] || {
125-
"@vocab": "http://uri.interlex.org/base/",
148+
"@vocab": `http://uri.interlex.org/${group}/`,
126149
"owl": "http://www.w3.org/2002/07/owl#",
127150
"rdfs": "http://www.w3.org/2000/01/rdf-schema#"
128151
},
129152
"@id": term['@id'] || termId,
130153
...term
131154
};
132155

156+
// Replace any "base" references with user's groupname in the payload
157+
if (user?.groupname && user.groupname !== 'base') {
158+
jsonLdPayload = replaceBaseWithUserGroup(jsonLdPayload, user.groupname);
159+
}
160+
133161
// Send PATCH request
134162
const response = await patchTerm(group, termId, jsonLdPayload);
135163

0 commit comments

Comments
 (0)