Skip to content

Commit 2e774df

Browse files
feat(question): group the add menu into questions and layout
The menu to add a question listed the content block among the questions, although it asks nothing. Split the menu into the captioned groups "Questions" and "Layout", the latter for types that only shape the form, so far the content block. Sections join the layout group when they land. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent 4caa254 commit 2e774df

2 files changed

Lines changed: 58 additions & 14 deletions

File tree

‎playwright/e2e/content-blocks.spec.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,26 @@ test.describe('Content blocks', () => {
178178
await form.fillTitle('Content blocks test form')
179179
})
180180

181+
test('Lists the content block in the layout group of the menu', async ({
182+
page,
183+
}) => {
184+
await page.getByRole('button', { name: 'Add a question' }).click()
185+
const menu = page.getByRole('menu')
186+
await expect(menu.getByRole('menuitem', { name: 'Content' })).toBeVisible()
187+
const entries = await menu
188+
.locator('li')
189+
.evaluateAll((items) =>
190+
items.map((item) => item.textContent?.trim() ?? ''),
191+
)
192+
193+
expect(entries.indexOf('Questions')).toBe(0)
194+
expect(entries.indexOf('Layout')).toBeGreaterThan(
195+
entries.indexOf('Short answer'),
196+
)
197+
expect(entries.indexOf('Content')).toBe(entries.indexOf('Layout') + 1)
198+
await expect(menu.getByRole('menuitem', { name: 'Layout' })).toHaveCount(0)
199+
})
200+
181201
test('Shows a block with only a title and a description', async ({
182202
page,
183203
form,

‎src/components/AddQuestionMenu.vue‎

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@
1818
</template>
1919

2020
<template v-if="!activeQuestionType">
21-
<NcActionButton
22-
v-for="(answer, type) in answerTypesFilter"
23-
:key="answer.label"
24-
:closeAfterClick="!hasSubtypes(answer)"
25-
:disabled="isLoadingQuestions"
26-
:isMenu="hasSubtypes(answer)"
27-
class="question-menu__question"
28-
@click="onPrimaryClick(answer, type, position)">
29-
<template #icon>
30-
<NcIconSvgWrapper :svg="answer.icon" />
31-
</template>
32-
{{ answer.label }}
33-
</NcActionButton>
21+
<template v-for="group in groups" :key="group.name">
22+
<NcActionCaption :name="group.name" />
23+
<NcActionButton
24+
v-for="(answer, type) in group.answerTypes"
25+
:key="answer.label"
26+
:closeAfterClick="!hasSubtypes(answer)"
27+
:disabled="isLoadingQuestions"
28+
:isMenu="hasSubtypes(answer)"
29+
class="question-menu__question"
30+
@click="onPrimaryClick(answer, type, position)">
31+
<template #icon>
32+
<NcIconSvgWrapper :svg="answer.icon" />
33+
</template>
34+
{{ answer.label }}
35+
</NcActionButton>
36+
</template>
3437
</template>
3538

3639
<template v-else>
@@ -75,8 +78,9 @@ import type { AnswerTypeConfig } from '../models/AnswerTypes.ts'
7578
import IconPlus from '@material-symbols/svg-400/outlined/add.svg?raw'
7679
import IconChevronLeft from '@material-symbols/svg-400/outlined/chevron_left.svg?raw'
7780
import { t } from '@nextcloud/l10n'
78-
import { defineComponent, ref, watch } from 'vue'
81+
import { computed, defineComponent, ref, watch } from 'vue'
7982
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
83+
import NcActionCaption from '@nextcloud/vue/components/NcActionCaption'
8084
import NcActions from '@nextcloud/vue/components/NcActions'
8185
import NcActionSeparator from '@nextcloud/vue/components/NcActionSeparator'
8286
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
@@ -88,6 +92,7 @@ export default defineComponent({
8892
components: {
8993
NcActions,
9094
NcActionButton,
95+
NcActionCaption,
9196
NcActionSeparator,
9297
NcIconSvgWrapper,
9398
NcLoadingIcon,
@@ -135,6 +140,24 @@ export default defineComponent({
135140
}
136141
})
137142
143+
const groups = computed(() => {
144+
const entries = Object.entries(props.answerTypesFilter)
145+
return [
146+
{
147+
name: t('forms', 'Questions'),
148+
answerTypes: Object.fromEntries(
149+
entries.filter(([, answer]) => !answer.layout),
150+
),
151+
},
152+
{
153+
name: t('forms', 'Layout'),
154+
answerTypes: Object.fromEntries(
155+
entries.filter(([, answer]) => answer.layout),
156+
),
157+
},
158+
].filter((group) => Object.keys(group.answerTypes).length > 0)
159+
})
160+
138161
const onPrimaryClick = (
139162
answer: AnswerTypeConfig,
140163
type: string,
@@ -175,6 +198,7 @@ export default defineComponent({
175198
176199
return {
177200
activeQuestionType,
201+
groups,
178202
openLocal,
179203
onPrimaryClick,
180204
onSubtypeClick,

0 commit comments

Comments
 (0)