Skip to content

Commit dcbe837

Browse files
committed
SimpleChatTC:ShowObjPropsEdit:Any depth trapping of ui setup
Maintain the current property hierarchy to its root over recursive calls. Allow callers to specify the props to be trapped using the prop hierarchy. Pass the prop hierarchy to the fTrapper. This should allow one to trap any prop wrt its editing ui setup, irrespective of whether it is a prop of the main object passed, or a member of a child prop of the main object passed or so ... Update the setting up of ChatHistoryInCtxt and ApiEndPoint to follow the new semantic/flow.
1 parent d34dfc1 commit dcbe837

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

tools/server/public_simplechat/simplechat.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,20 +1110,20 @@ class Me {
11101110
* @param {HTMLDivElement} elDiv
11111111
*/
11121112
show_settings(elDiv) {
1113-
ui.ui_show_obj_props_edit(elDiv, this, ["baseURL", "headers", "bStream", "tools", "apiRequestOptions", "TRAPME-apiEP", "TRAPME-iRecentUserMsgCnt", "bTrimGarbage", "bCompletionFreshChatAlways", "bCompletionInsertStandardRolePrefix"], "Settings", (prop, elProp)=>{
1113+
ui.ui_show_obj_props_edit(elDiv, "", this, ["baseURL", "headers", "bStream", "tools", "apiRequestOptions", "TRAPME-apiEP", "TRAPME-iRecentUserMsgCnt", "bTrimGarbage", "bCompletionFreshChatAlways", "bCompletionInsertStandardRolePrefix"], "Settings", (prop, elProp)=>{
11141114
if (prop == "headers:Authorization") {
11151115
// @ts-ignore
11161116
elProp.placeholder = "Bearer OPENAI_API_KEY";
11171117
}
1118-
}, "TRAPME-", (tag, elParent)=>{
1119-
if (tag == "TRAPME-apiEP") {
1118+
}, ["apiEP", "iRecentUserMsgCnt"], (propWithPath, prop, elParent)=>{
1119+
if (propWithPath == "apiEP") {
11201120
let sel = ui.el_creatediv_select("SetApiEP", "ApiEndPoint", ApiEP.Type, this.apiEP, (val)=>{
11211121
// @ts-ignore
11221122
this.apiEP = ApiEP.Type[val];
11231123
});
11241124
elParent.appendChild(sel.div);
11251125
}
1126-
if (tag == "TRAPME-iRecentUserMsgCnt") {
1126+
if (propWithPath == "iRecentUserMsgCnt") {
11271127
let sel = ui.el_creatediv_select("SetChatHistoryInCtxt", "ChatHistoryInCtxt", this.sRecentUserMsgCnt, this.iRecentUserMsgCnt, (val)=>{
11281128
this.iRecentUserMsgCnt = this.sRecentUserMsgCnt[val];
11291129
});

tools/server/public_simplechat/ui.mjs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,15 @@ export function el_creatediv_input(id, label, type, defaultValue, cb, className=
246246
* * fTrapper will be called with the parent ui element
247247
* into which the new ui elements created for editting the prop, if any, should be attached
248248
* @param {HTMLDivElement|HTMLFieldSetElement} elParent
249+
* @param {string} propsTreeRoot
249250
* @param {any} oObj
250251
* @param {Array<string>} lProps
251252
* @param {string} sLegend
252253
* @param {((prop:string, elProp: HTMLElement)=>void)| undefined} fRefiner
253-
* @param {string | undefined} sTrapTag
254-
* @param {((tagPlusProp: string, elParent: HTMLFieldSetElement)=>void) | undefined} fTrapper
254+
* @param {Array<string> | undefined} lTrapThese
255+
* @param {((propWithPath: string, prop: string, elParent: HTMLFieldSetElement)=>void) | undefined} fTrapper
255256
*/
256-
export function ui_show_obj_props_edit(elParent, oObj, lProps, sLegend, fRefiner=undefined, sTrapTag=undefined, fTrapper=undefined) {
257+
export function ui_show_obj_props_edit(elParent, propsTreeRoot, oObj, lProps, sLegend, fRefiner=undefined, lTrapThese=undefined, fTrapper=undefined) {
257258
let typeDict = {
258259
"string": "text",
259260
"number": "number",
@@ -264,10 +265,11 @@ export function ui_show_obj_props_edit(elParent, oObj, lProps, sLegend, fRefiner
264265
elFS.appendChild(elLegend);
265266
elParent.appendChild(elFS);
266267
for(const k of lProps) {
267-
if (sTrapTag) {
268-
if (k.startsWith(sTrapTag)) {
268+
let propsTreeRootNew = `${propsTreeRoot}:${k}`
269+
if (lTrapThese) {
270+
if (propsTreeRootNew in lTrapThese) {
269271
if (fTrapper) {
270-
fTrapper(k, elFS)
272+
fTrapper(propsTreeRootNew, k, elFS)
271273
}
272274
continue
273275
}
@@ -294,12 +296,12 @@ export function ui_show_obj_props_edit(elParent, oObj, lProps, sLegend, fRefiner
294296
}
295297
elFS.appendChild(bbtn.div);
296298
} else if (type == "object") {
297-
ui_show_obj_props_edit(elFS, val, Object.keys(val), k, (prop, elProp)=>{
299+
ui_show_obj_props_edit(elFS, propsTreeRootNew, val, Object.keys(val), k, (prop, elProp)=>{
298300
if (fRefiner) {
299301
let theProp = `${k}:${prop}`
300302
fRefiner(theProp, elProp)
301303
}
302-
})
304+
}, lTrapThese, fTrapper)
303305
}
304306
}
305307
}

0 commit comments

Comments
 (0)