MCPcopy
hub / github.com/tinyplex/tinybase / NewId

Function NewId

src/ui-solid-inspector/index.tsx:242–303  ·  view source on GitHub ↗
(
  props: OnDoneProp & {
    readonly suggestedId: Id;
    readonly has: (id: Id) => boolean;
    readonly set: (newId: Id) => void;
    readonly prompt?: string;
  },
)

Source from the content-addressed store, hash-verified

240};
241
242const NewId = (
243 props: OnDoneProp & {
244 readonly suggestedId: Id;
245 readonly has: (id: Id) => boolean;
246 readonly set: (newId: Id) => void;
247 readonly prompt?: string;
248 },
249) => {
250 const [newId, setNewId] = createSignal<Id>(props.suggestedId);
251 const [newIdOk, setNewIdOk] = createSignal(true);
252 const [previousSuggestedId, setPreviousSuggestedNewId] = createSignal<Id>(
253 props.suggestedId,
254 );
255
256 const handleNewIdChange = (
257 event: Event & {currentTarget: HTMLInputElement},
258 ) => {
259 const id = event.currentTarget.value;
260 setNewId(id);
261 setNewIdOk(!props.has(id));
262 };
263 const handleClick = () => {
264 const id = newId();
265 if (props.has(id)) {
266 setNewIdOk(false);
267 } else {
268 props.set(id);
269 props.onDone();
270 }
271 };
272 const handleKeyDown = (event: KeyboardEvent) => {
273 if (event.key == 'Enter') {
274 event.preventDefault();
275 handleClick();
276 }
277 };
278
279 createEffect(() => {
280 if (props.suggestedId != previousSuggestedId()) {
281 setNewId(props.suggestedId);
282 setPreviousSuggestedNewId(props.suggestedId);
283 }
284 });
285
286 return (
287 <>
288 {(props.prompt ?? 'New Id') + ': '}
289 <input
290 type="text"
291 value={newId()}
292 onInput={handleNewIdChange}
293 onKeyDown={handleKeyDown}
294 autofocus
295 />{' '}
296 <img
297 onClick={handleClick}
298 title={newIdOk() ? 'Confirm' : 'Id already exists'}
299 class={newIdOk() ? 'ok' : 'okDis'}

Callers 7

AddTableFunction · 0.70
AddRowFunction · 0.70
CloneTableFunction · 0.70
AddCellFunction · 0.70
CloneRowFunction · 0.70
AddValueFunction · 0.70
CloneValueFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…