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
10 changes: 10 additions & 0 deletions .changeset/37615-init-item-field-placement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/cli': patch
---

fix(cli): `objectstack init -t app` places the item's fields through the group's `fields` list, as `objectstack generate object` does

Clause-②: no
Metadata-protocol: none

The item object of the `app` template now writes `fieldGroups: [{ key: 'details', label: 'Details', fields: ['name', 'description', 'status'] }]` after the field map, and its fields no longer carry `group: 'details'`. That is how `objectstack generate object` and the `npm create objectstack` starter place fields, so a new project meets one style. Both spellings mean the same placement: the form and detail page show the same Details section, and `objectstack validate` and `objectstack lint` report nothing new. A project scaffolded by an earlier release keeps working unchanged. When you add a field to the item, list its name in the group's `fields` too.
28 changes: 14 additions & 14 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,28 +1060,15 @@ ${starterObjectExportsNote(['src/apps/main.app.ts', `src/views/${namespace}_item
export const ${toCamelCase(namespace)}Item = ObjectSchema.create({
name: '${namespace}_item',
label: '${toTitleCase(namespace)} Item',
// Field groups: the sections an item's form and detail page draw, top to
// bottom in this order. A field joins one by naming its \`key\` in \`group\`.
// That placement is what displays \`description\` and \`status\`.
// \`objectstack validate\` and \`objectstack lint\` report a field that
// nothing displays or reads (\`field-no-consumers\`) once the project holds
// a view, flow, dashboard or anything else that could read it, so give each
// field you add a \`group\` as well. Field groups versus a view's own form
// sections: https://objectstack.ai/docs/ui/field-grouping-and-order
fieldGroups: [
{ key: 'details', label: 'Details' },
],
fields: {
// Each field through a \`Field.*\` builder (Field.textarea, Field.select,
// Field.lookup, …), the way \`objectstack generate object\` writes them.
name: Field.text({
label: 'Name',
required: true,
group: 'details',
}),
description: Field.textarea({
label: 'Description',
group: 'details',
}),
status: Field.select({
label: 'Status',
Expand All @@ -1091,9 +1078,22 @@ export const ${toCamelCase(namespace)}Item = ObjectSchema.create({
{ label: 'Archived', value: 'archived' },
],
defaultValue: 'draft',
group: 'details',
}),
},

// Field groups: the Details sections of an item's record page and of its
// create and edit form, top to bottom in this order; a section's \`fields\`
// list names its fields in display order. That placement is what displays
// \`description\` and \`status\`. \`objectstack validate\` and
// \`objectstack lint\` report a field that nothing displays or reads
// (\`field-no-consumers\`) once the project holds a view, flow, dashboard or
// anything else that could read it, so list each field you add in a section
// too. Field groups versus a view's own form sections:
// https://objectstack.ai/docs/ui/field-grouping-and-order
fieldGroups: [
{ key: 'details', label: 'Details', fields: ['name', 'description', 'status'] },
],

// Org-wide default (OWD): who can see records they don't own. 'private' is
// owner-only until access is widened by a permission grant or a sharing
// rule. Declaring it is required, deliberately: \`objectstack build\`
Expand Down
45 changes: 45 additions & 0 deletions packages/cli/test/init-item-field-placement.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* PIN (#37615) — `os init -t app` places its item's fields the way
* `os g object` and the `npm create objectstack` starter do: through the
* `details` group's own `fields` list, after the field map, and never through
* a per-field `group`.
*
* #32153 promised a newcomer one field-placement dialect. After `os g object`
* moved to the group's `fields` list, the `app` template's item object still
* wrote `fieldGroups: [{ key: 'details', label: 'Details' }]` and
* `group: 'details'` on each field, so the CLI wrote two dialects. Both
* spellings mean the same placement; this file pins the one the scaffolds
* teach.
*/

import { describe, it, expect } from 'vitest';
import { TEMPLATES } from '../src/commands/init';

const ITEM_OBJECT = 'src/objects/__name___item.object.ts';

function renderItemObject(): string {
const render = TEMPLATES.app.srcFiles[ITEM_OBJECT];
expect(render, `the app template renders ${ITEM_OBJECT}`).toBeTypeOf('function');
return render('my-app', 'my_app');
}

describe('[#37615] `os init -t app` item object field placement', () => {
it('writes no per-field `group`', () => {
expect(renderItemObject()).not.toMatch(/^ +group: '/m);
});

it("lists every declared field in the details group's `fields`, after the field map", () => {
const source = renderItemObject();
const declared = [...source.matchAll(/^ {4}([a-z_][a-z0-9_]*): Field\./gm)].map((m) => m[1]);
expect(declared).toEqual(['name', 'description', 'status']);

const group = source.match(/\{ key: 'details', label: 'Details', fields: \[([^\]]*)\] \}/);
expect(group, 'the details group carries a `fields` list').not.toBeNull();
const listed = [...group![1].matchAll(/'([^']+)'/g)].map((m) => m[1]);
expect(listed).toEqual(declared);

expect(source.indexOf('fieldGroups:')).toBeGreaterThan(source.indexOf('fields: {'));
});
});
Loading