From b63c83006495effe890fa143d848c41cb7297881 Mon Sep 17 00:00:00 2001 From: kbrandt-hs Date: Fri, 13 Nov 2026 09:25:20 +0200 Subject: [PATCH 1/7] fix: add base refactored ingest procedures --- .../RuleOrderList/BlockRow.tsx | 70 +++++++ .../RuleOrderList/RbacOrderList.tsx | 32 ++++ .../RuleOrderList/RuleOrderList.helpers.ts | 18 ++ .../IngestProcedures/RuleOrderList/index.tsx | 172 ++++++++++++++++++ .../components/IngestProcedures/index.tsx | 132 ++++++++++++++ .../components/SourcesToolbar/index.tsx | 2 +- .../src/Sources/scenes/IngestRules/index.tsx | 14 +- 7 files changed, 427 insertions(+), 13 deletions(-) create mode 100644 apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/BlockRow.tsx create mode 100644 apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/RbacOrderList.tsx create mode 100644 apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/RuleOrderList.helpers.ts create mode 100644 apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/index.tsx create mode 100644 apps/dfe-core-ui/src/Sources/components/IngestProcedures/index.tsx diff --git a/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/BlockRow.tsx b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/BlockRow.tsx new file mode 100644 index 000000000..d95f27675 --- /dev/null +++ b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/BlockRow.tsx @@ -0,0 +1,70 @@ +import { Tooltip } from '@/core/components/Tooltip'; +import { TRuleBlock } from '@/Sources/hooks/useFetchRuleBlocks/types'; +import { IconAlertTriangle } from '@repo/dfe-icons'; +import { Tag } from 'antd'; +import Link from 'next/link'; +import { KIND_LABEL } from './RuleOrderList.helpers'; + +export const BlockRow = ({ + block, + title, +}: { + block: TRuleBlock; + title: string; +}) => { + const rows = block.rules.length; + const warnings = block.warnings ?? []; + return ( +
+ {block.kind === 'source' ? ( + + {title} + + ) : ( + {title} + )} + {block.kind !== 'default' && ( + + {KIND_LABEL[block.kind]} + + )} + {block.version && ( + + {`version ${block.version}`} + + )} + {!block.compiled && ( + + Not in the receiver's rules + + )} + {warnings.length > 0 && ( + + {warnings.map((warning) => ( +
  • {warning}
  • + ))} + + } + > + 1 ? 's' : ''}: ${warnings.join(' ')}`} + className="flex text-warning" + > + + +
    + )} + + {block.kind === 'default' + ? 'Takes what no block above matched' + : `${rows} rule row${rows === 1 ? '' : 's'}`} + +
    + ); +}; diff --git a/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/RbacOrderList.tsx b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/RbacOrderList.tsx new file mode 100644 index 000000000..35c480b39 --- /dev/null +++ b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/RbacOrderList.tsx @@ -0,0 +1,32 @@ +import { RbacProtected } from '@/core/components/RbacProtected'; +import { SortableRuleList } from '@/Sources/components/SortableRuleList'; +import { TRuleBlock } from '@/Sources/hooks/useFetchRuleBlocks/types'; +import { BlockRow } from './BlockRow'; + +export const RbacOrderList = ({ + label, + ordered, + titleOf, + isPending, + onMove, +}: { + label: string; + ordered: TRuleBlock[]; + titleOf: (block: TRuleBlock) => string; + isPending: boolean; + onMove: (from: number, to: number) => void; +}) => { + const { isAuthorized } = RbacProtected.useRbac({ + action: RbacProtected.rbacActions.source_write, + }); + return ( + } + /> + ); +}; diff --git a/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/RuleOrderList.helpers.ts b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/RuleOrderList.helpers.ts new file mode 100644 index 000000000..59756e86e --- /dev/null +++ b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/RuleOrderList.helpers.ts @@ -0,0 +1,18 @@ +import { TRuleBlock } from '@/Sources/hooks/useFetchRuleBlocks/types'; + +export const sameOrder = (left: string[], right: string[]) => + left.length === right.length && + left.every((id, index) => id === right[index]); + +export const KIND_LABEL: Record = { + source: 'Source', + profile: 'Compatibility profile', + default: 'Default', +}; + +export const moveId = (ids: string[], from: number, to: number) => { + const next = [...ids]; + const [moved] = next.splice(from, 1); + if (moved !== undefined) next.splice(to, 0, moved); + return next; +}; diff --git a/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/index.tsx b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/index.tsx new file mode 100644 index 000000000..4269aa03a --- /dev/null +++ b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/index.tsx @@ -0,0 +1,172 @@ +'use client'; + +import { CustomScrollbar } from '@/core/components/CustomScrollbar'; +import { NotificationCard } from '@/core/components/NotificationCard'; +import { useSetComponentHeight } from '@/core/hooks/useSetComponentHeight'; +import { IngestWriteRefusal } from '@/Sources/components/IngestRules/IngestWriteRefusal'; +import { IngestWriteResult } from '@/Sources/components/IngestRules/IngestWriteResult'; +import { + TRuleBlock, + TRuleTarget, +} from '@/Sources/hooks/useFetchRuleBlocks/types'; +import { useReorderRuleBlocks } from '@/Sources/hooks/useReorderRuleBlocks'; +import { Button } from 'antd'; +import { useMemo, useState } from 'react'; +import { RbacOrderList } from './RbacOrderList'; +import { moveId, sameOrder } from './RuleOrderList.helpers'; + +interface RuleOrderListProps { + target: TRuleTarget; + title: string; + description: string; + blocks: TRuleBlock[]; + etag: string | null; + titleOf: (block: TRuleBlock) => string; + nameOf: (id: string) => string; + onReload: () => Promise; + isReloading: boolean; + componentHeight?: { + initialOffset: number; + }; +} + +export const RuleOrderList = ({ + target, + title, + description, + blocks, + etag, + titleOf, + nameOf, + onReload, + isReloading, + componentHeight: componentHeightProp = { + initialOffset: 0, + }, +}: RuleOrderListProps) => { + const serverIds = useMemo(() => blocks.map((block) => block.id), [blocks]); + const [draft, setDraft] = useState(null); + const [sentIds, setSentIds] = useState([]); + const { mutate, isPending, error, reset, data } = useReorderRuleBlocks({ + etag, + onSuccess: () => setDraft(null), + }); + + // A draft only stands while it names the blocks the engine has. + const draftIds = + draft && + draft.length === serverIds.length && + draft.every((id) => serverIds.includes(id)) + ? draft + : serverIds; + const byId = new Map(blocks.map((block) => [block.id, block])); + const ordered = draftIds + .map((id) => byId.get(id)) + .filter((block): block is TRuleBlock => !!block); + const isDirty = !sameOrder(draftIds, serverIds); + const movable = ordered.filter((block) => !block.pinned); + + const handleReload = () => { + void onReload().then(() => { + setDraft(null); + reset(); + }); + }; + + const handleSave = () => { + const ids = movable.map((block) => block.id); + setSentIds(ids); + mutate({ target, blocks: ids }); + }; + + const dirtyHeightOffset = isDirty ? 50 : 0; + const errorHeightOffset = error ? 100 : 0; + const resultHeightOffset = data && !isDirty ? 62 : 0; + + const { componentHeight } = useSetComponentHeight({ + offset: + componentHeightProp?.initialOffset + + dirtyHeightOffset + + errorHeightOffset + + resultHeightOffset, + }); + return ( +
    +
    +

    + {title} +

    +

    + {description} +

    +
    + + {isDirty && ( + + + + + } + /> + )} + + {error ? ( + + ) : ( + data && + !isDirty && + )} + + {movable.length === 0 && ( +

    + No block here can move: only the default runs. +

    + )} + + + { + reset(); + setDraft(moveId(draftIds, from, to)); + }} + /> + +
    + ); +}; diff --git a/apps/dfe-core-ui/src/Sources/components/IngestProcedures/index.tsx b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/index.tsx new file mode 100644 index 000000000..785f29708 --- /dev/null +++ b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/index.tsx @@ -0,0 +1,132 @@ +import { NotificationCard } from '@/core/components/NotificationCard'; +import { RuleOrderList } from './RuleOrderList'; + +import { GenericErrorCard } from '@/core/components/GenericError'; +import { DeploymentCompatibility } from '@/Sources/components/IngestRules/DeploymentCompatibility'; +import { useFetchCompatProfiles } from '@/Sources/hooks/useFetchCompatProfiles'; +import { useFetchRuleBlocks } from '@/Sources/hooks/useFetchRuleBlocks'; +import { + TRuleBlock, + TRuleTarget, +} from '@/Sources/hooks/useFetchRuleBlocks/types'; +import { IconAlertTriangle } from '@repo/dfe-icons'; +import { Spin } from 'antd'; + +const TARGETS: { target: TRuleTarget; title: string; description: string }[] = [ + { + target: '_source', + title: 'Source rules', + description: + 'Which source a record belongs to. The receiver tries each block from the top, and the first that matches decides.', + }, + { + target: '_org_id', + title: 'Org rules', + description: + 'Which org a record belongs to, tried the same way once its source is known.', + }, +]; + +export const IngestProcedures = () => { + const { data, isLoading, isFetching, error, refetch } = useFetchRuleBlocks(); + const { profiles } = useFetchCompatProfiles(); + + const titleOf = (block: TRuleBlock) => { + if (block.kind === 'default') return 'Default'; + if (block.kind === 'profile') { + return ( + profiles?.find((profile) => profile.id === block.name)?.title ?? + block.name + ); + } + return block.name; + }; + + // Ids are source., compat. or default, and a refusal can name one this page has not read. + const nameOf = (id: string) => { + const [kind, ...rest] = id.split('.'); + const name = rest.join('.'); + if (kind === 'source') return name; + if (kind === 'compat') { + return profiles?.find((profile) => profile.id === name)?.title ?? name; + } + return id === 'default' ? 'Default' : id; + }; + return ( +
    + + {isLoading && ( + <> + Loading rule blocks + + )} + {error && ( + + )} + {data && !data.etag && ( + } + title="This order is read only here" + description="The engine answered without a revision the browser may read, which a save has to send back. The console reaches the engine on another origin that does not expose the ETag header." + /> + )} + +
    + {data ? ( + block.target === TARGETS[0].target, + )} + etag={data.etag} + titleOf={titleOf} + nameOf={nameOf} + onReload={refetch} + isReloading={isFetching} + /> + ) : ( +
    + )} + +
    + + {data ? ( + block.target === TARGETS[1].target, + )} + etag={data.etag} + titleOf={titleOf} + nameOf={nameOf} + onReload={refetch} + isReloading={isFetching} + /> + ) : ( +
    + )} +
    +
    +
    + ); +}; diff --git a/apps/dfe-core-ui/src/Sources/components/SourcesToolbar/index.tsx b/apps/dfe-core-ui/src/Sources/components/SourcesToolbar/index.tsx index b3e46d423..99b7f5a1b 100644 --- a/apps/dfe-core-ui/src/Sources/components/SourcesToolbar/index.tsx +++ b/apps/dfe-core-ui/src/Sources/components/SourcesToolbar/index.tsx @@ -18,7 +18,7 @@ export const SourcesToolbar = () => { }, { path: '/sources/ingest-rules', - label: 'Ingest rules', + label: 'Ingest Procedures', disabled: false, }, ]; diff --git a/apps/dfe-core-ui/src/Sources/scenes/IngestRules/index.tsx b/apps/dfe-core-ui/src/Sources/scenes/IngestRules/index.tsx index a49585978..682cc4720 100644 --- a/apps/dfe-core-ui/src/Sources/scenes/IngestRules/index.tsx +++ b/apps/dfe-core-ui/src/Sources/scenes/IngestRules/index.tsx @@ -1,26 +1,16 @@ 'use client'; import { MainContentCard } from '@/core/components/ContentCard'; -import { CustomScrollbar } from '@/core/components/CustomScrollbar'; import { RbacProtected } from '@/core/components/RbacProtected'; -import { useSetComponentHeight } from '@/core/hooks/useSetComponentHeight'; -import { DeploymentCompatibility } from '@/Sources/components/IngestRules/DeploymentCompatibility'; -import { RuleOrder } from '@/Sources/components/IngestRules/RuleOrder'; +import { IngestProcedures } from '@/Sources/components/IngestProcedures'; /** The order the receiver's rules run in, and the compatibility profiles they include. */ export const IngestRulesScene = () => { - const { componentHeight } = useSetComponentHeight({ offset: 100 }); - return ( - -
    - - -
    -
    +
    From a28b6bd493a1ce187375deb8ee1198254ce75bfc Mon Sep 17 00:00:00 2001 From: kbrandt-hs Date: Fri, 13 Nov 2026 09:27:24 +0200 Subject: [PATCH 2/7] fix: open source in new tab - hover on block row shows cursor grab --- .../components/IngestProcedures/RuleOrderList/BlockRow.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/BlockRow.tsx b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/BlockRow.tsx index d95f27675..d54a739e7 100644 --- a/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/BlockRow.tsx +++ b/apps/dfe-core-ui/src/Sources/components/IngestProcedures/RuleOrderList/BlockRow.tsx @@ -15,11 +15,13 @@ export const BlockRow = ({ const rows = block.rules.length; const warnings = block.warnings ?? []; return ( -
    +
    {block.kind === 'source' ? ( {title} From 5cf5dbf0e30d55fa523745a94e8a1b5cd1bafe4b Mon Sep 17 00:00:00 2001 From: kbrandt-hs Date: Fri, 13 Nov 2026 09:42:42 +0200 Subject: [PATCH 3/7] fix: convert buttons to SearchSelect --- .../SortableRuleList.test.tsx | 11 +++- .../components/SortableRuleList/index.tsx | 54 +++++++++++++++---- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/apps/dfe-core-ui/src/Sources/components/SortableRuleList/SortableRuleList.test.tsx b/apps/dfe-core-ui/src/Sources/components/SortableRuleList/SortableRuleList.test.tsx index fc2d7256b..fca7aaed8 100644 --- a/apps/dfe-core-ui/src/Sources/components/SortableRuleList/SortableRuleList.test.tsx +++ b/apps/dfe-core-ui/src/Sources/components/SortableRuleList/SortableRuleList.test.tsx @@ -123,14 +123,21 @@ describe('SortableRuleList', () => { ).toHaveFocus(); }); - it('moves to a chosen position from the menu', async () => { + it('moves to a position chosen from the search', async () => { const user = userEvent.setup(); render(, { wrapper }); await user.click( screen.getByRole('button', { name: 'Move alpha to position' }), ); - await user.click(await screen.findByText('Position 3')); + const search = await screen.findByRole('combobox', { + name: 'Search positions for alpha', + }); + await user.type(search, '3'); + expect( + screen.queryByRole('option', { name: 'Position 1' }), + ).not.toBeInTheDocument(); + await user.click(screen.getByRole('option', { name: 'Position 3' })); expect(order().slice(0, 3)).toEqual([ 'rule-block-b', diff --git a/apps/dfe-core-ui/src/Sources/components/SortableRuleList/index.tsx b/apps/dfe-core-ui/src/Sources/components/SortableRuleList/index.tsx index 8c07582f7..fbc8bb73e 100644 --- a/apps/dfe-core-ui/src/Sources/components/SortableRuleList/index.tsx +++ b/apps/dfe-core-ui/src/Sources/components/SortableRuleList/index.tsx @@ -9,7 +9,7 @@ import { IconGripVertical, IconPin, } from '@repo/dfe-icons'; -import { Button, Dropdown } from 'antd'; +import { Button, Dropdown, Select } from 'antd'; import { useEffect, useId, useRef, useState } from 'react'; export type SortableRuleItem = { @@ -27,7 +27,7 @@ type DropTarget = { index: number; after: boolean }; * A first-match list whose order is edited by drag, by keyboard and by menu. * * Dragging is pointer-only, so every move it offers is also a button (WCAG 2.2 - * SC 2.5.7): Move up, Move down and a move-to-position menu on each row, and + * SC 2.5.7): Move up, Move down and a move-to-position search on each row, and * the arrow keys on its handle. Each move is announced in a live region as * "Moved to position N of M", and focus stays on the control that made * it. Pinned rows sit where the engine keeps them and are never a drop target @@ -54,6 +54,7 @@ export function SortableRuleList({ // The count re-keys the message, so a repeat of the same words is announced again. const [announcement, setAnnouncement] = useState({ text: '', count: 0 }); const [dragIndex, setDragIndex] = useState(null); + const [positionMenuId, setPositionMenuId] = useState(null); const [dropTarget, setDropTarget] = useState(null); const pendingFocus = useRef<{ id: string; control: Control } | null>(null); const controls = useRef(new Map()); @@ -254,14 +255,47 @@ export function SortableRuleList({ ({ - key: String(to), - label: `Position ${to + 1}`, - disabled: to === index, - })), - onClick: ({ key }) => move(index, Number(key), 'menu'), - }} + destroyOnHidden + open={positionMenuId === item.id} + onOpenChange={(next) => + setPositionMenuId(next ? item.id : null) + } + popupRender={() => ( +
    event.preventDefault()} + > + + String(option?.label ?? '') + .toLowerCase() + .includes(input.trim().toLowerCase()), + }} + virtual={false} + className="w-44" + placeholder="Search position" + aria-label={`Search positions for ${ruleName}`} + options={options} + onChange={(to) => { + onChange(to); + }} + getPopupContainer={(trigger) => + trigger.parentElement ?? document.body + } + /> +
    + )} + > +