Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/36898-list-changed-column.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@object-ui/data-objectstack': patch
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(console): the metadata list shows when each item last changed and marks items with unpublished changes

Clause-②: yes (widening)
Metadata-protocol: none

The generic metadata list (Setup's catalog lists and Studio's "All metadata" area) gains a 「修改时间」 / "Modified" column, read off the list answer's `changedAt` sibling. Only an item served from a stored row has a time; a code-shipped item shows an empty cell. The sort control gains "Modified (newest first)" and "Modified (oldest first)", which ride the address as `sort=-changed` / `sort=changed`; items without a time sort last either way, and the item page's ‹ › follow the same order.

Beneath the time, an item with a pending draft on the existing `GET /api/v1/meta/_drafts` ledger is marked 「有未发布的改动」 / "Unpublished changes", including drafts that existed before this change. A draft the AI assistant wrote (any of its recorded changes made by the AI copilot or through the MCP build door, the rule the item page's AI line uses) is marked 「AI 的改动未发布」 / "Unpublished AI changes" instead. A publish removes the mark.

`MetadataClient.listResponse` now returns the list's `changedAt` beside the items (each entry read with the spec's own rule; an entry that does not parse is dropped, and absence stays absence). `list` is unchanged.

New locale keys in the studio catalogue (en, zh): `engine.list.sort.changed.asc`, `engine.list.sort.changed.desc`, `engine.list.col.changedAt`, `engine.list.draftMark.human`, `engine.list.draftMark.humanTitle`, `engine.list.draftMark.ai`, `engine.list.draftMark.aiTitle`.
56 changes: 56 additions & 0 deletions ui/packages/app-shell/src/views/metadata-admin/ListChangedCell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* The metadata list's 「修改时间」 cell (objectstack#36898): the item's change
* time (`listChangedAt.ts`), empty for an item with none, and beneath it the
* 「有未发布的改动」 mark when the item has a pending draft
* (`listDraftMarks.ts`) — the AI's draft marked apart from anyone else's.
*/

import * as React from 'react';
import { Sparkles } from 'lucide-react';
import { EmptyValue, cn } from '@object-ui/components';
import { formatChangedAt } from './listChangedAt.js';
import type { ListDraftMarkKind } from './listDraftMarks.js';
import { t } from './i18n.js';

export function ListChangedCell({
changedAt,
draft,
locale,
}: {
/** The item's change time (ISO-8601); `undefined` for none. */
changedAt: string | undefined;
/** The item's pending-draft mark; `null` for none. */
draft: ListDraftMarkKind | null;
locale: string;
}): React.ReactElement {
const text = formatChangedAt(changedAt, locale);
return (
<span className="inline-flex flex-col items-start gap-0.5" data-testid="metadata-changed-cell">
{text ? (
<time dateTime={changedAt} title={changedAt} className="whitespace-nowrap text-xs text-muted-foreground">
{text}
</time>
) : (
<EmptyValue />
)}
{draft && (
<span
data-testid="metadata-draft-mark"
data-draft-by={draft}
title={t(`engine.list.draftMark.${draft}Title`, locale)}
className={cn(
'inline-flex items-center gap-1 whitespace-nowrap rounded-full border px-1.5 text-[10px] font-medium leading-4',
draft === 'ai'
? 'border-violet-400/60 bg-violet-50 text-violet-700 dark:border-violet-400/40 dark:bg-violet-500/10 dark:text-violet-300'
: 'border-amber-400/60 bg-amber-50 text-amber-800 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-200',
)}
>
{draft === 'ai' && <Sparkles className="h-3 w-3 shrink-0" aria-hidden="true" />}
{t(`engine.list.draftMark.${draft}`, locale)}
</span>
)}
</span>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* objectstack#36898 — the generic metadata list's 「修改时间」 column and its
* 「有未发布的改动」 mark, on the real page. The metadata client and the
* pending-drafts ledger it reads are stubbed. Pinned, each with its control:
*
* - an item served from a stored row shows its time; a code-shipped item an
* empty cell, with no error;
* - `?sort=-changed` draws newest first, code-shipped items last;
* - an item on the `_drafts` ledger is marked, the AI's draft apart from a person's;
* an item off the ledger (published) carries no mark.
*/
import '@testing-library/jest-dom/vitest';
import * as React from 'react';
import { describe, it, expect, vi, afterEach } from 'vitest';
import { render, cleanup, screen, within } from '@testing-library/react';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
// Dynamic imports the page's anchors and editors reach, paid at collection
// rather than inside a case's clocked window.
import '@object-ui/plugin-detail';
import '@objectstack/lint';

const ITEMS: Record<string, unknown>[] = [
{ name: 'shipped', label: 'Shipped', _packageId: 'crm' },
{ name: 'by_person', label: 'By person', _packageId: 'crm' },
{ name: 'by_ai', label: 'By AI', _packageId: 'crm' },
];
const CHANGED_AT = { by_person: '2026-11-20T08:00:00Z', by_ai: '2026-11-24T10:15:00Z' };
const DRAFT_CHANGES: Record<string, unknown[]> = {
by_person: [{ path: ['label'], by: 'studio', actor: 'u1', at: '2026-11-24T09:00:00Z' }],
by_ai: [{ path: ['label'], by: 'copilot', actor: 'u1', at: '2026-11-24T09:30:00Z' }],
};

const CLIENT = {
list: async (type: string) => (type === 'skill' ? ITEMS : []),
listResponse: async (type: string) =>
type === 'skill' ? { items: ITEMS, changedAt: CHANGED_AT } : { items: [] },
listDrafts: async () => ledger.entries,
getDraft: async (_type: string, name: string) => ({ type: 'skill', name, item: {}, draftChanges: DRAFT_CHANGES[name] }),
};
const SKILL_ENTRY = { type: 'skill', label: 'Skill', allowEnvironmentOverlay: false, allowRuntimeCreate: true };

const ledger = vi.hoisted(() => ({ entries: [] as Array<{ type: string; name: string; packageId: string | null }> }));

vi.mock('./useMetadata', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useMetadataClient: () => CLIENT,
useMetadataTypes: () => ({ loading: false, error: null, entries: [SKILL_ENTRY] }),
}));
vi.mock('./i18n', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useMetadataLocale: () => 'en-US',
}));
vi.mock('../../hooks/useCanAuthorMetadata', () => ({ useCanAuthorMetadata: () => true }));
vi.mock('../../hooks/useTenancyPosture', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useTenancyPosture: () => 'single',
}));

// Imported AFTER the mocks so the page picks them up.
import { MetadataResourceListPage } from './ResourceListPage';
import { registerBuiltinAnchors } from './anchors';
import '../../services/builtinComponents';

registerBuiltinAnchors();

afterEach(() => {
cleanup();
ledger.entries = [];
});

function mount(search = '') {
return render(
<MemoryRouter initialEntries={[`/apps/setup/metadata/skill?scope=environment${search}`]}>
<Routes>
<Route path="/apps/:appName/metadata/:type" element={<MetadataResourceListPage />} />
</Routes>
</MemoryRouter>,
);
}

const cellOf = (name: string) => within(screen.getByTestId(`metadata-row-${name}`)).getByTestId('metadata-changed-cell');

describe('the 「修改时间」 column (objectstack#36898)', () => {
it('an item with a stored row shows its time; a code-shipped item an empty cell', async () => {
mount();
await screen.findByRole('table');
expect(await screen.findByRole('columnheader', { name: 'Modified' })).toBeInTheDocument();
const time = await within(screen.getByTestId('metadata-row-by_ai')).findByText(
new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'short' }).format(Date.parse(CHANGED_AT.by_ai)),
);
expect(time.closest('time')).toHaveAttribute('dateTime', CHANGED_AT.by_ai);
expect(cellOf('shipped').querySelector('time')).toBeNull();
});

it('`?sort=-changed` draws newest first, the code-shipped item last', async () => {
mount('&sort=-changed');
await within(await screen.findByTestId('metadata-row-by_ai')).findByText(/2026/);
const order = screen
.getAllByTestId(/^metadata-row-/)
.filter((el) => el.tagName === 'TR')
.map((tr) => tr.getAttribute('data-testid'));
expect(order).toEqual(['metadata-row-by_ai', 'metadata-row-by_person', 'metadata-row-shipped']);
});
});

describe('the 「有未发布的改动」 mark (objectstack#36898)', () => {
it('marks each item on the ledger, the AI\'s draft apart from a person\'s', async () => {
ledger.entries = [
{ type: 'skill', name: 'by_person', packageId: 'crm' },
{ type: 'skill', name: 'by_ai', packageId: 'crm' },
];
mount();
await screen.findByRole('table');
const ai = await within(cellOf('by_ai')).findByTestId('metadata-draft-mark');
await vi.waitFor(() => expect(ai).toHaveAttribute('data-draft-by', 'ai'));
expect(ai).toHaveTextContent('Unpublished AI changes');
const person = within(cellOf('by_person')).getByTestId('metadata-draft-mark');
expect(person).toHaveAttribute('data-draft-by', 'human');
expect(person).toHaveTextContent('Unpublished changes');
expect(within(cellOf('shipped')).queryByTestId('metadata-draft-mark')).toBeNull();
});

it('an item off the ledger — published — carries no mark (control)', async () => {
mount();
await screen.findByRole('table');
await within(screen.getByTestId('metadata-row-by_ai')).findByText(/2026/);
expect(screen.queryByTestId('metadata-draft-mark')).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ import {
type MetadataListState,
} from './metadataListState.js';
import { useListScrollRestore } from './useListScrollRestore.js';
import { useListChangedAt } from './listChangedAt.js';
import { useListDraftMarks } from './listDraftMarks.js';
import { ListChangedCell } from './ListChangedCell.js';

/**
* objectui#12982 — the Clone dialog of a declaration-only catalog
Expand Down Expand Up @@ -625,6 +628,9 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
cancelled = true;
};
}, [client, type, refreshKey, listInclude]);
// objectstack#36898 — each item's change time and its pending-draft mark.
const changedAt = useListChangedAt(client, type, listInclude ? { include: listInclude } : undefined, refreshKey);
const draftMarkOf = useListDraftMarks(client, type, refreshKey);

const searchableFields = config.searchableFields ?? ['name', 'label', 'description'];
// Structural scope — every row this package could ever show for this
Expand Down Expand Up @@ -701,6 +707,7 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
// one implementation the detail's ‹ › order reads too (`metadataListState.ts`).
const rowReader: ListRowReader<ItemRow> = {
name: (row) => String(row.item[config.primaryKey ?? 'name'] ?? ''),
changedAt: (row) => changedAt?.[String(row.item[config.primaryKey ?? 'name'] ?? '')],
label: (row) => (typeof row.item.label === 'string' ? row.item.label : undefined),
matches: (row, q) => matchesQuery(row.item, q, searchableFields),
source: (row) => row.source,
Expand Down Expand Up @@ -1080,6 +1087,7 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
{localizeColumnLabel(ci === 0 && labelColumn ? labelColumn : c)}
</th>
))}
<th className={cn('px-3 text-left font-medium', inSetup ? 'h-9 py-0' : 'py-2')}>{t('engine.list.col.changedAt', locale)}</th>
<th className={cn('px-3 text-right font-medium w-[80px]', inSetup ? 'h-9 py-0' : 'py-2')}>{t('engine.list.col.source', locale)}</th>
{activation && (
<th className={cn('px-3 text-left font-medium w-[90px]', inSetup ? 'h-9 py-0' : 'py-2', activeCellPin)}>
Expand Down Expand Up @@ -1241,6 +1249,13 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
</td>
);
})}
<td className={cellClass}>
<ListChangedCell
changedAt={changedAt?.[name]}
draft={draftMarkOf({ name, packageId: rowPkg, member: rowMember })}
locale={locale}
/>
</td>
<td className={cn(cellClass, 'text-right')}>
{(row.item._lock as string | undefined) && row.item._lock !== 'none' && (
<span
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* objectstack#36898 — the metadata list's 「修改时间」 and its `changed` sort:
* a code-shipped item has no time and an empty cell, sorts after every item
* that has one in both directions, and the detail's ‹ › order
* (`orderedListNames`) is the order the list draws.
*/

import { describe, it, expect } from 'vitest';
import { compareChangedAt, formatChangedAt } from './listChangedAt';
import {
applyListState,
decodeListSort,
encodeListSort,
orderedListNames,
DEFAULT_LIST_STATE,
type ListRowReader,
type MetadataListState,
} from './metadataListState';

interface Row {
name: string;
at?: string;
}

const ROWS: Row[] = [
{ name: 'shipped_a' },
{ name: 'old', at: '2026-11-01T08:00:00Z' },
{ name: 'new', at: '2026-11-24T10:15:00.000Z' },
{ name: 'shipped_b' },
{ name: 'tie_b', at: '2026-11-10T00:00:00Z' },
{ name: 'tie_a', at: '2026-11-10T00:00:00Z' },
];

const READ: ListRowReader<Row> = {
name: (row) => row.name,
label: () => undefined,
matches: (row, q) => row.name.includes(q),
source: (row) => (row.at ? 'runtime' : 'artifact'),
changedAt: (row) => row.at,
};

const sorted = (dir: 'asc' | 'desc'): MetadataListState => ({ ...DEFAULT_LIST_STATE, sort: { key: 'changed', dir } });
const names = (rows: Row[]) => rows.map((row) => row.name);

describe('the `changed` sort (objectstack#36898)', () => {
it('newest first; ties by name; items without a time last', () => {
expect(names(applyListState(ROWS, sorted('desc'), READ, 'en-US'))).toEqual([
'new', 'tie_a', 'tie_b', 'old', 'shipped_a', 'shipped_b',
]);
});

it('oldest first; items without a time still last', () => {
expect(names(applyListState(ROWS, sorted('asc'), READ, 'en-US'))).toEqual([
'old', 'tie_a', 'tie_b', 'new', 'shipped_a', 'shipped_b',
]);
});

it('the detail ‹ › order is the drawn order, under a filter too', () => {
for (const state of [sorted('desc'), sorted('asc'), { ...sorted('desc'), query: 'i' }]) {
expect(orderedListNames(ROWS, state, READ, 'en-US')).toEqual(names(applyListState(ROWS, state, READ, 'en-US')));
}
});

it('a reader with no times sorts by name (control: the time is what moved them)', () => {
const { changedAt: _ignored, ...noTimes } = READ;
expect(names(applyListState(ROWS, sorted('desc'), noTimes, 'en-US'))).toEqual([
'new', 'old', 'shipped_a', 'shipped_b', 'tie_a', 'tie_b',
]);
});

it('rides the address as `changed` / `-changed`', () => {
expect(encodeListSort({ key: 'changed', dir: 'desc' })).toBe('-changed');
expect(decodeListSort('-changed')).toEqual({ key: 'changed', dir: 'desc' });
expect(decodeListSort('changed')).toEqual({ key: 'changed', dir: 'asc' });
});

it('a time that does not parse counts as none', () => {
expect(compareChangedAt('not a time', '2026-11-01T00:00:00Z', 'desc')).toBeGreaterThan(0);
expect(compareChangedAt(undefined, undefined, 'asc')).toBe(0);
});
});

describe('the 「修改时间」 cell text (objectstack#36898)', () => {
it('an item with a time shows it in the reader\'s locale; one without shows none', () => {
const at = '2026-11-24T10:15:00.000Z';
expect(formatChangedAt(at, 'en-US')).toBe(
new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'short' }).format(Date.parse(at)),
);
expect(formatChangedAt(undefined, 'zh-CN')).toBeNull();
expect(formatChangedAt('garbage', 'zh-CN')).toBeNull();
});
});
Loading
Loading