Skip to content

Commit 95d5771

Browse files
committed
fix: display slice type for mapped slices in todo component
1 parent 2277f87 commit 95d5771

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

src/components/SliceZone.ts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -260,40 +260,33 @@ export const TODOSliceComponent = __PRODUCTION__
260260
props: [],
261261
inheritAttrs: false,
262262
setup(_props, { attrs }) {
263-
const type = computed(() =>
264-
attrs.slice && typeof attrs.slice === "object"
265-
? "slice_type" in attrs.slice
263+
const type = computed(() => {
264+
// API slices
265+
if (attrs.slice && typeof attrs.slice === "object") {
266+
return "slice_type" in attrs.slice
266267
? (attrs.slice as Record<string, unknown>).slice_type
267-
: "type" in attrs.slice
268-
? (attrs.slice as Record<string, unknown>).type
269-
: null
270-
: null,
271-
);
268+
: (attrs.slice as Record<string, unknown>).type;
269+
}
270+
271+
// Mapped slices
272+
return "slice_type" in attrs ? attrs.slice_type : attrs.type;
273+
});
272274

273275
watchEffect(() => {
274-
type.value
275-
? console.warn(
276-
`[SliceZone] Could not find a component for Slice type "${type.value}"`,
277-
attrs.slice,
278-
)
279-
: console.warn(
280-
"[SliceZone] Could not find a component for mapped Slice",
281-
attrs,
282-
);
276+
console.warn(
277+
`[SliceZone] Could not find a component for Slice type "${type.value}"`,
278+
attrs.slice || attrs,
279+
);
283280
});
284281

285282
return () => {
286283
return h(
287284
"section",
288285
{
289286
"data-slice-zone-todo-component": "",
290-
"data-slice-type": type.value ? type.value : null,
287+
"data-slice-type": type.value,
291288
},
292-
[
293-
type.value
294-
? `Could not find a component for Slice type "${type.value}"`
295-
: "Could not find a component for mapped Slice",
296-
],
289+
[`Could not find a component for Slice type "${type.value}"`],
297290
);
298291
};
299292
},

test/components-SliceZone.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ it("renders TODO component if component mapping is missing", () => {
325325
expect(wrapper.html()).toBe(
326326
`<div class="wrapperComponentFoo"></div>
327327
<section data-slice-zone-todo-component="" data-slice-type="bar">Could not find a component for Slice type "bar"</section>
328-
<section data-slice-zone-todo-component="">Could not find a component for mapped Slice</section>`,
328+
<section data-slice-zone-todo-component="" data-slice-type="baz">Could not find a component for Slice type "baz"</section>`,
329329
);
330330
expect(console.warn).toHaveBeenCalledTimes(2);
331331
expect(vi.mocked(console.warn).mock.calls[0]).toMatch(

0 commit comments

Comments
 (0)