Skip to content

Commit e383e09

Browse files
refact: Convert blueprint sections to fields
1 parent 09a4ce5 commit e383e09

37 files changed

Lines changed: 1683 additions & 549 deletions

config/api/models/FileBlueprint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'fields' => [
1010
'name' => fn (FileBlueprint $blueprint) => $blueprint->name(),
1111
'options' => fn (FileBlueprint $blueprint) => $blueprint->options(),
12-
'tabs' => fn (FileBlueprint $blueprint) => $blueprint->tabs(),
12+
'tabs' => fn (FileBlueprint $blueprint) => array_values($blueprint->tabs()->toArray()),
1313
'title' => fn (FileBlueprint $blueprint) => $blueprint->title(),
1414
],
1515
'type' => FileBlueprint::class,

config/api/models/PageBlueprint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'options' => fn (PageBlueprint $blueprint) => $blueprint->options(),
1313
'preview' => fn (PageBlueprint $blueprint) => $blueprint->preview(),
1414
'status' => fn (PageBlueprint $blueprint) => $blueprint->status(),
15-
'tabs' => fn (PageBlueprint $blueprint) => $blueprint->tabs(),
15+
'tabs' => fn (PageBlueprint $blueprint) => array_values($blueprint->tabs()->toArray()),
1616
'title' => fn (PageBlueprint $blueprint) => $blueprint->title(),
1717
],
1818
'type' => PageBlueprint::class,

config/api/models/SiteBlueprint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'fields' => [
1010
'name' => fn (SiteBlueprint $blueprint) => $blueprint->name(),
1111
'options' => fn (SiteBlueprint $blueprint) => $blueprint->options(),
12-
'tabs' => fn (SiteBlueprint $blueprint) => $blueprint->tabs(),
12+
'tabs' => fn (SiteBlueprint $blueprint) => array_values($blueprint->tabs()->toArray()),
1313
'title' => fn (SiteBlueprint $blueprint) => $blueprint->title(),
1414
],
1515
'type' => SiteBlueprint::class,

config/api/models/UserBlueprint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'fields' => [
1010
'name' => fn (UserBlueprint $blueprint) => $blueprint->name(),
1111
'options' => fn (UserBlueprint $blueprint) => $blueprint->options(),
12-
'tabs' => fn (UserBlueprint $blueprint) => $blueprint->tabs(),
12+
'tabs' => fn (UserBlueprint $blueprint) => array_values($blueprint->tabs()->toArray()),
1313
'title' => fn (UserBlueprint $blueprint) => $blueprint->title(),
1414
],
1515
'type' => UserBlueprint::class,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { describe, expect, it } from "@test/unit";
2+
import { mount } from "@vue/test-utils";
3+
import ModelTabs from "./ModelTabs.vue";
4+
5+
const tabs = [
6+
{
7+
name: "main",
8+
fields: ["headline", "Text"]
9+
},
10+
{
11+
name: "meta",
12+
fields: ["seo"]
13+
}
14+
];
15+
16+
type Badge = { text: number } | undefined;
17+
18+
function badges(diff = {}): Badge[] {
19+
const wrapper = mount(ModelTabs, { props: { tab: "main", tabs, diff } });
20+
const withBadges = wrapper.vm.withBadges as { badge: Badge }[];
21+
return withBadges.map((tab) => tab.badge);
22+
}
23+
24+
describe("ModelTabs.vue", () => {
25+
describe("element", () => {
26+
it.rendersAs(() => mount(ModelTabs).find("k-tabs"), "K-TABS");
27+
});
28+
29+
describe("withBadges", () => {
30+
it("counts the changed fields of a tab", () => {
31+
expect(badges({ headline: "a", seo: "b" })).toStrictEqual([
32+
{ text: 1 },
33+
{ text: 1 }
34+
]);
35+
});
36+
37+
it("compares the field names case-insensitively", () => {
38+
expect(badges({ text: "a" })).toStrictEqual([{ text: 1 }, undefined]);
39+
});
40+
41+
it("has no badge without changes", () => {
42+
expect(badges()).toStrictEqual([undefined, undefined]);
43+
});
44+
});
45+
});

panel/src/components/Navigation/ModelTabs.vue

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,8 @@ export default {
2525
const changes = Object.keys(this.diff);
2626
2727
return this.tabs.map((tab) => {
28-
// collect all fields per tab
29-
const fields = [];
30-
31-
for (const column in tab.columns) {
32-
for (const section in tab.columns[column].sections) {
33-
if (tab.columns[column].sections[section].type === "fields") {
34-
for (const field in tab.columns[column].sections[section]
35-
.fields) {
36-
fields.push(field);
37-
}
38-
}
39-
}
40-
}
28+
// all field names of the tab
29+
const fields = tab.fields ?? [];
4130
4231
// get count of changed fields in this tab
4332
const changesInTab = fields.filter((field) =>

panel/src/components/Sections/FieldsSection.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
import SectionMixin from "@/mixins/section.js";
2727
2828
/**
29+
* A `fields` section is unwrapped into its fields on the
30+
* blueprint level and never reaches the Panel anymore.
31+
*
32+
* @deprecated 6.0.0
2933
* @copyright Bastian Allgeier
3034
* @license https://getkirby.com/license
3135
*/

panel/src/components/Sections/Sections.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151

5252
<script>
5353
/**
54+
* Sections are converted to fields on the blueprint level.
55+
* Model views render `k-model-form` instead.
56+
*
57+
* @deprecated 6.0.0
5458
* @copyright Bastian Allgeier
5559
* @license https://getkirby.com/license
5660
*/

panel/src/components/Views/Files/FileView.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@
4343

4444
<k-model-tabs :diff="diff" :tab="tab.name" :tabs="tabs" />
4545

46-
<k-sections
47-
:blueprint="blueprint"
46+
<k-model-form
47+
:api="api"
48+
:columns="tab.columns"
4849
:content="content"
50+
:diff="diff"
4951
:empty="
5052
$panel.config.debug
5153
? $panel.html($t('file.blueprint', { blueprint: $esc(blueprint) }))
5254
: null
5355
"
5456
:lock="lock"
55-
:parent="api"
56-
:tab="tab"
5757
@input="onInput"
5858
@submit="onSubmit"
5959
/>

panel/src/components/Views/Pages/PageView.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636

3737
<k-model-tabs :diff="diff" :tab="tab.name" :tabs="tabs" />
3838

39-
<k-sections
40-
:blueprint="blueprint"
39+
<k-model-form
40+
:api="api"
41+
:columns="tab.columns"
4142
:content="content"
43+
:diff="diff"
4244
:empty="
4345
$panel.config.debug
4446
? $panel.html($t('page.blueprint', { blueprint: $esc(blueprint) }))
4547
: null
4648
"
4749
:lock="lock"
48-
:parent="api"
49-
:tab="tab"
5050
@input="onInput"
5151
@submit="onSubmit"
5252
/>

0 commit comments

Comments
 (0)