add an updatemetadata call to objectservice

This commit is contained in:
sawka 2024-05-28 12:18:26 -07:00
parent 6e6b5178c1
commit 5edb882955
5 changed files with 37 additions and 0 deletions

View File

@ -272,6 +272,10 @@ export function CloseTab(tabId: string): Promise<void> {
return wrapObjectServiceCall("CloseTab", tabId);
}
export function UpdateBlockMeta(blockId: string, meta: MetadataType): Promise<void> {
return wrapObjectServiceCall("UpdateBlockMeta", blockId, meta);
}
export {
cleanWaveObjectCache,
clearWaveObjectCache,

View File

@ -7,6 +7,8 @@ declare global {
activetabid: string;
};
type MetadataType = { [key: string]: any };
type ORef = {
otype: string;
oid: string;

View File

@ -16,6 +16,8 @@ loadFonts();
console.log("Wave Starting");
(window as any).WOS = WOS;
document.addEventListener("DOMContentLoaded", async () => {
console.log("DOMContentLoaded");
// ensures client/window are loaded into the cache before rendering

View File

@ -179,3 +179,14 @@ func (svc *ObjectService) CloseTab(uiContext wstore.UIContext, tabId string) (an
}
return updatesRtn(ctx, nil)
}
func (svc *ObjectService) UpdateBlockMeta(uiContext wstore.UIContext, blockId string, meta map[string]any) (any, error) {
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancelFn()
ctx = wstore.ContextWithUpdates(ctx)
err := wstore.UpdateBlockMeta(ctx, blockId, meta)
if err != nil {
return nil, fmt.Errorf("error merging block meta: %w", err)
}
return updatesRtn(ctx, nil)
}

View File

@ -395,6 +395,24 @@ func CloseTab(ctx context.Context, workspaceId string, tabId string) error {
})
}
func UpdateBlockMeta(ctx context.Context, blockId string, meta map[string]any) error {
return WithTx(ctx, func(tx *TxWrap) error {
block, _ := DBGet[*Block](tx.Context(), blockId)
if block == nil {
return fmt.Errorf("block not found: %q", blockId)
}
for k, v := range meta {
if v == nil {
delete(block.Meta, k)
continue
}
block.Meta[k] = v
}
DBUpdate(tx.Context(), block)
return nil
})
}
func EnsureInitialData() error {
// does not need to run in a transaction since it is called on startup
ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)