Support shared bid history and custom project opening
This commit is contained in:
@@ -55,14 +55,15 @@ For directory-backed collections, initialize the empty collection in the selecte
|
||||
|
||||
## Specialist viewers for shared data
|
||||
|
||||
The dashboard exposes two versioned datasets through ordinary workspace files. Each extension obtains its own launch-scoped grant through `openWorkspaceAsset`. A group supplies the requesting user's access context. The workspace owns the data and its checkpoints.
|
||||
The dashboard exposes versioned datasets through ordinary workspace files. Each extension obtains its own launch-scoped grant through `openWorkspaceAsset`. A group supplies the requesting user's access context. The workspace owns the data and its checkpoints.
|
||||
|
||||
| Asset | Canonical store | Contents |
|
||||
| --- | --- | --- |
|
||||
| `suppliers` | `/shared/suppliers/catalog.kv` | Stable supplier IDs, profiles, overrides, import history and enrichments. `catalog/meta.active` selects the generation. |
|
||||
| `prices` | `/shared/prices/prices.kv` | Comparable price observations, keyed by stable observation ID in the list `observations/v1`. |
|
||||
| `bid_history` | `/shared/bid_history/inschrijfhistorie.json` | Historical bids by ID and lot, with criterion scores and feedback. |
|
||||
|
||||
Declare `workspace_asset_suppliers_read` or `workspace_asset_prices_read`, plus `filesystem_read` and `kv_store_read`. Editors also need the corresponding asset write permission, `filesystem_write`, `kv_store_write` and effective write access to the folder. Store a supplier ID on a project line. Resolve the ID against the supplier asset when displaying current details. Keep original offers, recipients and sent messages in the project.
|
||||
Declare the asset’s `workspace_asset_<asset>_read` permission and `filesystem_read`. Editors also need its write permission, `filesystem_write` and effective write access to the folder. KV datasets additionally require `kv_store_read` and, for editing, `kv_store_write`. For JSON datasets, pass the snapshot from `createSharedFolderReader(...).readJson(relative)` to `writeWorkspaceAssetJson(context, relative, value, snapshot)` with a writable asset grant in `context.folder`. Store a supplier ID on a project line. Resolve the ID against the supplier asset when displaying current details. Keep original offers, recipients and sent messages in the project.
|
||||
|
||||
```js
|
||||
import { openWorkspaceAsset } from '@isa-warden/isa-project-format/shared-folder';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import ProjectWorkspace from './ProjectWorkspace.svelte';
|
||||
let {client,bridge,extensionName,locale='en',onImport,onExport,onOverview,beforeExport}=$props();
|
||||
let {client,bridge,extensionName,locale='en',onImport,onExport,onOverview,onOpen,beforeExport}=$props();
|
||||
</script>
|
||||
<ProjectWorkspace {client} {bridge} {extensionName} {locale} {beforeExport} {onImport} {onExport} {onOverview} mode="header" />
|
||||
<ProjectWorkspace {client} {bridge} {extensionName} {locale} {beforeExport} {onImport} {onExport} {onOverview} {onOpen} mode="header" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import ProjectWorkspace from './ProjectWorkspace.svelte';
|
||||
let {client,bridge,extensionName,locale='en',onImport,onExport,onOverview,showEmptyProjectMessage}=$props();
|
||||
let {client,bridge,extensionName,locale='en',onImport,onExport,onOverview,onOpen,showEmptyProjectMessage}=$props();
|
||||
</script>
|
||||
<ProjectWorkspace {client} {bridge} {extensionName} {locale} {onImport} {onExport} {onOverview} {showEmptyProjectMessage} mode="picker" />
|
||||
<ProjectWorkspace {client} {bridge} {extensionName} {locale} {onImport} {onExport} {onOverview} {onOpen} {showEmptyProjectMessage} mode="picker" />
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { mountProjectWorkspace } from '../dom.js';
|
||||
let {client,bridge,extensionName,locale='en',onImport,onExport,onOverview,beforeExport,showEmptyProjectMessage,mode='workspace'}=$props();
|
||||
let {client,bridge,extensionName,locale='en',onImport,onExport,onOverview,onOpen,beforeExport,showEmptyProjectMessage,mode='workspace'}=$props();
|
||||
let target;
|
||||
onMount(()=>{const view=mountProjectWorkspace(target,{client,bridge,extensionName,locale,mode,beforeExport,onImport,onExport,onOverview,showEmptyProjectMessage});return()=>view.destroy();});
|
||||
onMount(()=>{const view=mountProjectWorkspace(target,{client,bridge,extensionName,locale,mode,beforeExport,onImport,onExport,onOverview,onOpen,showEmptyProjectMessage});return()=>view.destroy();});
|
||||
</script>
|
||||
<div bind:this={target}></div>
|
||||
|
||||
Vendored
+2
-1
@@ -1,8 +1,9 @@
|
||||
import type { ProjectClient, ProjectBridge, ProjectSession } from './index.js';
|
||||
import type { ProjectClient, ProjectBridge, ProjectReference, ProjectSession } from './index.js';
|
||||
export interface ProjectMountOptions {
|
||||
extensionName?: string; client: ProjectClient; bridge?: ProjectBridge; locale?: 'en' | 'nl';
|
||||
showEmptyProjectMessage?: boolean;
|
||||
onOverview?: (actions: {refresh(): Promise<void>} | null) => void;
|
||||
onOpen?: (project: ProjectReference) => Promise<unknown>;
|
||||
onImport?: () => Promise<unknown>;
|
||||
onExport?: (session: ProjectSession) => Promise<unknown>;
|
||||
beforeExport?: (session: ProjectSession) => void | Promise<void>;
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ import { labels } from './labels.js';
|
||||
import { exportProjectToDialog, importProjectFromDialog } from './transfer.js';
|
||||
import { styles } from './styles.js';
|
||||
|
||||
export function mountProjectWorkspace(target, {client,bridge,locale='en',extensionName,mode='workspace',beforeExport,onOverview,onImport,onExport,showEmptyProjectMessage} = {}) {
|
||||
export function mountProjectWorkspace(target, {client,bridge,locale='en',extensionName,mode='workspace',beforeExport,onOverview,onOpen,onImport,onExport,showEmptyProjectMessage} = {}) {
|
||||
if (!target?.ownerDocument || !client) throw new TypeError('Mount target and project client required');
|
||||
const document = target.ownerDocument;
|
||||
const text = labels[locale] ?? labels.en;
|
||||
@@ -124,7 +124,7 @@ export function mountProjectWorkspace(target, {client,bridge,locale='en',extensi
|
||||
activeView ??= mountActive(active);
|
||||
if (activeView.title.textContent !== active.manifest.name) activeView.title.textContent = active.manifest.name;
|
||||
} else if (!removeOverview) {
|
||||
removeOverview = mountOverview(content, {client, extensionName, text, locale, onOverview, showEmptyProjectMessage,
|
||||
removeOverview = mountOverview(content, {client, extensionName, text, locale, onOverview, onOpen, showEmptyProjectMessage,
|
||||
onImport: onImport ?? (bridge && (() => importProjectFromDialog(client, {bridge})))});
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -2,7 +2,7 @@ import { workspaceElements } from './workspace-elements.js';
|
||||
|
||||
// A row identifies a folder accessible through the current launch's grants. Private
|
||||
// recents supply the activity order only, never the inventory or a grant.
|
||||
export function mountOverview(target, {client, extensionName, text, locale, onImport, onOverview, showEmptyProjectMessage = true}) {
|
||||
export function mountOverview(target, {client, extensionName, text, locale, onImport, onOverview, onOpen, showEmptyProjectMessage = true}) {
|
||||
const document = target.ownerDocument;
|
||||
const {icon} = workspaceElements(document);
|
||||
function element(tag, label, className) {
|
||||
@@ -172,7 +172,8 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
|
||||
const row = container.querySelector('[data-project-id="' + CSS.escape(project.id) + '"]');
|
||||
row?.setAttribute('aria-busy', 'true');
|
||||
}
|
||||
void run(() => client.openListed(project), alert, text.opening + ' ' + project.name);
|
||||
if (onOpen) void run(() => onOpen(project), alert, '');
|
||||
else void run(() => client.openListed(project), alert, text.opening + ' ' + project.name);
|
||||
}
|
||||
function refresh() {
|
||||
if (pendingRefresh) return pendingRefresh;
|
||||
|
||||
Vendored
+9
-4
@@ -1,11 +1,16 @@
|
||||
import type { ProjectBridge, ProjectScope, ProjectRead } from './index.js';
|
||||
export type WorkspaceAsset = 'suppliers' | 'prices';
|
||||
export type WorkspaceAsset = 'suppliers' | 'prices' | 'bid_history';
|
||||
export interface WorkspaceAssetGrant {
|
||||
readonly asset: WorkspaceAsset; readonly workspaceId: string; readonly groupId: string;
|
||||
readonly folderId: string; readonly path: string; readonly canWrite: boolean;
|
||||
}
|
||||
export function openWorkspaceAsset(options: {
|
||||
bridge: ProjectBridge; scope: ProjectScope; asset: WorkspaceAsset; access?: 'read' | 'read_write';
|
||||
assertCurrent?: () => void;
|
||||
}): Promise<Readonly<{
|
||||
asset: WorkspaceAsset; workspaceId: string; groupId: string; folderId: string; path: string; canWrite: boolean;
|
||||
}>>;
|
||||
}): Promise<WorkspaceAssetGrant>;
|
||||
export function writeWorkspaceAssetJson(options: {
|
||||
bridge: ProjectBridge; scope: ProjectScope; folder: WorkspaceAssetGrant; assertCurrent?: () => void;
|
||||
}, relative: string, value: unknown, base: ProjectRead): Promise<{fileId: string; path: string; [key: string]: unknown}>;
|
||||
export function createSharedFolderReader(options: {
|
||||
bridge: ProjectBridge;
|
||||
scope: ProjectScope;
|
||||
|
||||
+31
-1
@@ -1,13 +1,16 @@
|
||||
import { validateArchivePath } from './format.js';
|
||||
import { readAuthoritativeFile } from './shared-read.js';
|
||||
import { readKvSnapshot } from './kv-snapshot.js';
|
||||
import { confirmedWrite } from './proofs.js';
|
||||
|
||||
const workspaceAssets = ['suppliers', 'prices', 'bid_history'];
|
||||
|
||||
/** Obtain the calling extension's grant to a workspace-owned dataset. */
|
||||
export async function openWorkspaceAsset({bridge, scope, asset, access, assertCurrent = () => {}}) {
|
||||
if (typeof bridge?.invoke !== 'function' || !scope?.workspaceId || !scope?.groupId) {
|
||||
throw new TypeError('Host bridge and launch scope required');
|
||||
}
|
||||
if (!['suppliers', 'prices'].includes(asset) || (access !== undefined && !['read', 'read_write'].includes(access))) {
|
||||
if (!workspaceAssets.includes(asset) || (access !== undefined && !['read', 'read_write'].includes(access))) {
|
||||
throw new TypeError('Invalid workspace asset or access mode');
|
||||
}
|
||||
const {workspaceId, groupId} = scope;
|
||||
@@ -23,6 +26,33 @@ export async function openWorkspaceAsset({bridge, scope, asset, access, assertCu
|
||||
return Object.freeze({asset, workspaceId, groupId, path: folder.path, folderId: folder.folderId, canWrite: folder.canWrite});
|
||||
}
|
||||
|
||||
/** Conditionally create or replace one JSON file under an opened workspace asset. */
|
||||
export async function writeWorkspaceAssetJson({bridge, scope, folder, assertCurrent = () => {}}, relative, value, base) {
|
||||
if (folder?.canWrite !== true || !workspaceAssets.includes(folder.asset) ||
|
||||
folder.path !== '/shared/' + folder.asset || !folder.folderId || !scope?.workspaceId || !scope.groupId ||
|
||||
folder.workspaceId !== scope.workspaceId || folder.groupId !== scope.groupId) {
|
||||
throw new Error('A writable workspace asset grant for this launch is required');
|
||||
}
|
||||
const path = folder.path + '/' + validateArchivePath(relative);
|
||||
const replace = base?.status === 'found';
|
||||
if (base?.path !== path || (!replace && base.status !== 'absent') ||
|
||||
(replace && (!base.fileId || base.authoritative !== true || !Number.isSafeInteger(base.syncRevision) || base.syncRevision < 0))) {
|
||||
throw new TypeError('An authoritative read of the target file is required');
|
||||
}
|
||||
const file = {path, text:JSON.stringify(value), contentType:'application/json', replaceExisting:replace};
|
||||
if (replace) {
|
||||
file.expectedSyncRevision = base.syncRevision;
|
||||
const hash = base.serverContentHash || (base.contentHashVerified && base.contentHash);
|
||||
if (hash) file.expectedContentHash = hash;
|
||||
}
|
||||
assertCurrent();
|
||||
const reply = await bridge.invoke('filesystem_upload_files', {
|
||||
workspaceId:scope.workspaceId, groupId:scope.groupId, files:[file]
|
||||
});
|
||||
assertCurrent();
|
||||
return confirmedWrite(reply, path);
|
||||
}
|
||||
|
||||
/** Reads through the calling extension's own host grant. The folder can also
|
||||
* be the root of an open project session. No source is opened for writing. */
|
||||
export function createSharedFolderReader({bridge,scope,folder,assertCurrent = () => {}}) {
|
||||
|
||||
Reference in New Issue
Block a user