papegaaij commented on code in PR #1834:
URL: https://github.com/apache/wicket/pull/1834#discussion_r4523027529


##########
wicket-examples/src/main/java/org/apache/wicket/examples/islands/taskboard/EditCardPanel.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.examples.islands.taskboard;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;
+import org.apache.wicket.markup.html.form.ChoiceRenderer;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.panel.FeedbackPanel;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LambdaModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.validation.validator.StringValidator;
+
+/**
+ * The form of the edit dialog: classic Wicket fields next to two form 
islands, the description's
+ * rich-text editor and the due date's picker. All of them are validated and 
submitted together.
+ */
+public abstract class EditCardPanel extends Panel
+{
+       private static final long serialVersionUID = 1L;
+
+       /**
+        * @param id
+        *            the component id
+        * @param board
+        *            the board
+        * @param cardId
+        *            the card to edit
+        */
+       public EditCardPanel(String id, IModel<Board> board, String cardId)
+       {
+               super(id);
+
+               Board current = board.getObject();

Review Comment:
   Fixed in 3823a287ec: the panel reads the board through the page's model and 
keeps only the card id.



##########
wicket-examples/src/main/frontend/src/taskboard/RichTextField.tsx:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { RichTextEditor } from '@mantine/tiptap';
+import { useEditor } from '@tiptap/react';
+import StarterKit from '@tiptap/starter-kit';
+import { cspNonce, useFormState, useFormValue } from 'wicket-islands-react';
+import BoardTheme from './BoardTheme';
+import '@mantine/tiptap/styles.css';
+import './FormFields.css';
+
+/**
+ * The description editor of RichTextField.java. Its value is the editor's 
HTML, which the server
+ * sanitizes: nothing the browser sends is trusted.
+ */
+export default function RichTextField() {
+       const [value, setValue] = useFormValue<string>();
+       const { enabled, errors } = useFormState();
+       const editor = useEditor({

Review Comment:
   Fixed in 3823a287ec. StarterKit is configured to match the allowlist: 
headings 3 and 4, no horizontal rule, links without `target`. The editor also 
takes over the value when the server sends a different one.



##########
wicket-examples/src/main/frontend/src/taskboard/TaskBoard.tsx:
##########
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import {
+       DndContext, KeyboardSensor, PointerSensor, useDraggable, useDroppable, 
useSensor, useSensors,
+       type DragEndEvent
+} from '@dnd-kit/core';
+import { CSS } from '@dnd-kit/utilities';
+import { Alert, Avatar, Badge, Card, Group, Text, Title } from '@mantine/core';
+import { startTransition, useOptimistic, useState } from 'react';
+import { IslandCallError, useIsland, useStore } from 'wicket-islands-react';
+import BoardTheme from './BoardTheme';
+import {
+       applyMove, FILTER_STORE, matches, moveFor, type BoardFilter, type 
BoardProps, type CardProps,
+       type ColumnProps
+} from './shared';
+import './TaskBoard.css';
+
+/**
+ * The board. A dropped card moves at once (React's useOptimistic over the 
props); the server's
+ * answer decides: accepted, the new props show the move; refused, the 
optimistic state is dropped
+ * and the card is back where the props have it.
+ */
+export default function TaskBoard({ version, columns }: BoardProps) {
+       const { call } = useIsland<BoardProps>();
+       const [filter] = useStore<BoardFilter>(FILTER_STORE);
+       const [shown, showMove] = useOptimistic(columns, applyMove);
+       const [notice, setNotice] = useState<string | null>(null);
+       const sensors = useSensors(
+               useSensor(PointerSensor, { activationConstraint: { distance: 5 
} }),
+               useSensor(KeyboardSensor));
+
+       function onDragEnd({ active, over }: DragEndEvent) {
+               const move = over && moveFor(shown, String(active.id), 
String(over.id), version);
+               if (!move) {
+                       return;
+               }
+               setNotice(null);
+               startTransition(async () => {
+                       showMove(move);
+                       try {
+                               await call('move', move);
+                       } catch (e) {
+                               setNotice(e instanceof IslandCallError ? 
e.messages.join(' ') : String(e));
+                       }
+               });
+       }
+
+       function open(card: CardProps) {
+               call('open', { cardId: card.id }).catch((e: unknown) =>
+                       setNotice(e instanceof IslandCallError ? 
e.messages.join(' ') : String(e)));
+       }
+
+       return (
+               <BoardTheme>
+                       <div className="task-board">
+                               {notice && (
+                                       <Alert color="red" withCloseButton 
onClose={() => setNotice(null)} role="alert"
+                                               className="notice">
+                                               {notice}
+                                       </Alert>
+                               )}
+                               <DndContext sensors={sensors} 
onDragEnd={onDragEnd}>
+                                       <div className="columns">
+                                               {shown.map(column => (
+                                                       <BoardColumn 
key={column.id} column={column}
+                                                               
cards={column.cards.filter(card => matches(card, filter))} onOpen={open} />
+                                               ))}
+                                       </div>
+                               </DndContext>
+                       </div>
+               </BoardTheme>
+       );
+}
+
+function BoardColumn({ column, cards, onOpen }: {
+       column: ColumnProps;
+       cards: CardProps[];
+       onOpen(card: CardProps): void;
+}) {
+       const { setNodeRef, isOver } = useDroppable({ id: `column:${column.id}` 
});
+       const full = column.limit > 0 && column.cards.length >= column.limit;
+       return (
+               <section ref={setNodeRef} className={isOver ? 'column over' : 
'column'}
+                       data-column={column.id}>
+                       <Group justify="space-between" mb="xs">
+                               <Title order={4}>{column.title}</Title>
+                               {column.limit > 0 && (
+                                       <Badge color={full ? 'red' : 'gray'} 
variant="light">
+                                               {column.cards.length} / 
{column.limit}
+                                       </Badge>
+                               )}
+                       </Group>
+                       {cards.map(card => <BoardCard key={card.id} card={card} 
onOpen={onOpen} />)}
+               </section>
+       );
+}
+
+function BoardCard({ card, onOpen }: { card: CardProps; onOpen(card: 
CardProps): void }) {
+       const drag = useDraggable({ id: card.id });
+       const drop = useDroppable({ id: `card:${card.id}` });
+       return (
+               <Card ref={node => { drag.setNodeRef(node); 
drop.setNodeRef(node); }}
+                       {...drag.listeners} {...drag.attributes}
+                       className={drag.isDragging ? 'card dragging' : 'card'}
+                       style={{ transform: 
CSS.Translate.toString(drag.transform) }}
+                       withBorder padding="sm" mb="xs" data-card-id={card.id}
+                       onDoubleClick={() => onOpen(card)}>

Review Comment:
   Fixed in 3823a287ec. Each card has an Edit button. Its key events stop at 
the button, so Enter doesn't start a keyboard drag. Covered by 
`TaskBoardSeleniumTest.aCardOpensFromTheKeyboard`.



##########
wicket-examples/src/main/frontend/src/taskboard/BoardFilterBar.tsx:
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Group, Select, TextInput } from '@mantine/core';
+import { useState } from 'react';
+import { useIslandQuery, useStore } from 'wicket-islands-react';
+import BoardTheme from './BoardTheme';
+import { FILTER_STORE, type BoardFilter } from './shared';
+
+interface Member {
+       id: string;
+       name: string;
+}
+
+const NO_FILTER: BoardFilter = { assigneeId: null, text: '' };
+
+/**
+ * The filter above the board. It writes the client store the board reads, so 
filtering never
+ * involves the server; only the assignee suggestions come from the page-less 
members endpoint.
+ */
+export default function BoardFilterBar() {
+       const [stored, setFilter] = useStore<BoardFilter>(FILTER_STORE);
+       const filter = stored ?? NO_FILTER;
+       const [search, setSearch] = useState('');
+       const members = useIslandQuery<Member[]>('members', { prefix: search },

Review Comment:
   Fixed in 3823a287ec: the search is debounced by 250 ms.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to