From 616941b087ac5959732e23bf9ff03ca2419aa2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20G=C3=B3mez?= Date: Wed, 25 Nov 2026 23:12:06 +0100 Subject: [PATCH] feat(frontend): import and creation from pasted configuration over in-memory ports --- frontend/lint/layers.js | 5 +- frontend/src/app/adapters/memory/overrides.ts | 25 +++- frontend/src/app/adapters/memory/pasted.ts | 92 +++++++++++++ .../src/app/adapters/memory/pastedBoards.ts | 97 ++++++++++++++ .../src/app/adapters/memory/pastedSeveral.ts | 79 +++++++++++ frontend/src/app/test/StoryMessages.tsx | 8 +- frontend/src/app/test/StoryScreens.tsx | 26 ++-- frontend/src/app/test/pasted.ts | 29 ++++ frontend/src/app/test/pastedRoutes.tsx | 60 +++++++++ frontend/src/app/test/storyRoutes.tsx | 2 + frontend/src/console.css | 19 +++ .../src/design-system/Disclosure.stories.tsx | 10 ++ frontend/src/design-system/Disclosure.tsx | 5 +- .../src/domain/authsources/AddAuthsource.tsx | 25 ++-- .../domain/entities/editor/EntityEditor.tsx | 6 +- .../domain/entities/editor/FilledEntity.tsx | 34 +++++ .../src/domain/entities/editor/useEditor.ts | 5 +- frontend/src/domain/entities/index.ts | 3 + .../src/domain/overrides/ExternalList.tsx | 3 +- .../src/domain/overrides/ImportConfirm.tsx | 84 ++++++++++++ frontend/src/domain/overrides/index.ts | 2 + frontend/src/domain/overrides/port.ts | 7 + .../src/domain/overrides/selection.test.ts | 28 ++++ frontend/src/domain/overrides/selection.ts | 56 ++++++++ .../src/domain/overrides/useExternalList.ts | 8 ++ frontend/src/domain/pasted/AddFromPaste.tsx | 91 +++++++++++++ .../src/domain/pasted/CreationMessage.tsx | 65 +++++++++ frontend/src/domain/pasted/Held.tsx | 61 +++++++++ frontend/src/domain/pasted/PasteArea.tsx | 101 ++++++++++++++ frontend/src/domain/pasted/PastedReview.tsx | 97 ++++++++++++++ frontend/src/domain/pasted/PickSeveral.tsx | 102 ++++++++++++++ frontend/src/domain/pasted/Problems.tsx | 60 +++++++++ frontend/src/domain/pasted/Replace.tsx | 73 ++++++++++ frontend/src/domain/pasted/Report.tsx | 60 +++++++++ frontend/src/domain/pasted/Saving.tsx | 27 ++++ frontend/src/domain/pasted/detect.test.ts | 22 +++ frontend/src/domain/pasted/detect.ts | 30 +++++ frontend/src/domain/pasted/hold.tsx | 40 ++++++ frontend/src/domain/pasted/index.ts | 20 +++ frontend/src/domain/pasted/port.ts | 39 ++++++ frontend/src/domain/pasted/types.ts | 81 ++++++++++++ frontend/src/domain/pasted/usePaste.ts | 81 ++++++++++++ frontend/src/domain/pasted/useSavePasted.ts | 55 ++++++++ frontend/src/domain/session/failure.ts | 6 +- .../src/pages/AddFromPastePage.stories.tsx | 105 +++++++++++++++ frontend/src/pages/AddFromPastePage.tsx | 15 +++ frontend/src/pages/AddSeveralPage.stories.tsx | 68 ++++++++++ frontend/src/pages/ExternalPage.stories.tsx | 2 +- frontend/src/pages/ImportPage.stories.tsx | 92 +++++++++++++ frontend/src/pages/ImportPage.tsx | 5 + frontend/src/pages/ManagedCopyPage.tsx | 6 + frontend/src/pages/PastedFlow.test.tsx | 75 +++++++++++ .../src/pages/PastedReviewPage.stories.tsx | 125 ++++++++++++++++++ .../src/pages/ReplaceFromPage.stories.tsx | 93 +++++++++++++ frontend/src/pages/ReplaceFromPage.tsx | 10 ++ frontend/src/pages/ReviewAuthsourcePage.tsx | 5 + public/assets/app/.vite/manifest.json | 4 +- ...sole-DYrERFfZ.css => console-BcXLqj55.css} | 2 +- .../{main-B7Kz8kOX.js => main-BgnzQrvq.js} | 4 +- 59 files changed, 2393 insertions(+), 47 deletions(-) create mode 100644 frontend/src/app/adapters/memory/pasted.ts create mode 100644 frontend/src/app/adapters/memory/pastedBoards.ts create mode 100644 frontend/src/app/adapters/memory/pastedSeveral.ts create mode 100644 frontend/src/app/test/pasted.ts create mode 100644 frontend/src/app/test/pastedRoutes.tsx create mode 100644 frontend/src/domain/entities/editor/FilledEntity.tsx create mode 100644 frontend/src/domain/overrides/ImportConfirm.tsx create mode 100644 frontend/src/domain/overrides/selection.test.ts create mode 100644 frontend/src/domain/overrides/selection.ts create mode 100644 frontend/src/domain/pasted/AddFromPaste.tsx create mode 100644 frontend/src/domain/pasted/CreationMessage.tsx create mode 100644 frontend/src/domain/pasted/Held.tsx create mode 100644 frontend/src/domain/pasted/PasteArea.tsx create mode 100644 frontend/src/domain/pasted/PastedReview.tsx create mode 100644 frontend/src/domain/pasted/PickSeveral.tsx create mode 100644 frontend/src/domain/pasted/Problems.tsx create mode 100644 frontend/src/domain/pasted/Replace.tsx create mode 100644 frontend/src/domain/pasted/Report.tsx create mode 100644 frontend/src/domain/pasted/Saving.tsx create mode 100644 frontend/src/domain/pasted/detect.test.ts create mode 100644 frontend/src/domain/pasted/detect.ts create mode 100644 frontend/src/domain/pasted/hold.tsx create mode 100644 frontend/src/domain/pasted/index.ts create mode 100644 frontend/src/domain/pasted/port.ts create mode 100644 frontend/src/domain/pasted/types.ts create mode 100644 frontend/src/domain/pasted/usePaste.ts create mode 100644 frontend/src/domain/pasted/useSavePasted.ts create mode 100644 frontend/src/pages/AddFromPastePage.stories.tsx create mode 100644 frontend/src/pages/AddFromPastePage.tsx create mode 100644 frontend/src/pages/AddSeveralPage.stories.tsx create mode 100644 frontend/src/pages/ImportPage.stories.tsx create mode 100644 frontend/src/pages/ImportPage.tsx create mode 100644 frontend/src/pages/ManagedCopyPage.tsx create mode 100644 frontend/src/pages/PastedFlow.test.tsx create mode 100644 frontend/src/pages/PastedReviewPage.stories.tsx create mode 100644 frontend/src/pages/ReplaceFromPage.stories.tsx create mode 100644 frontend/src/pages/ReplaceFromPage.tsx create mode 100644 frontend/src/pages/ReviewAuthsourcePage.tsx rename public/assets/app/assets/{console-DYrERFfZ.css => console-BcXLqj55.css} (95%) rename public/assets/app/assets/{main-B7Kz8kOX.js => main-BgnzQrvq.js} (52%) diff --git a/frontend/lint/layers.js b/frontend/lint/layers.js index 916076c..dd86b8b 100644 --- a/frontend/lint/layers.js +++ b/frontend/lint/layers.js @@ -10,9 +10,10 @@ const SLICES = { publication: ['session', 'entities'], nodes: ['session'], audit: ['session'], - overrides: ['session', 'entities'], + pasted: ['session', 'entities', 'publication'], + overrides: ['session', 'entities', 'publication', 'pasted'], overview: ['session', 'entities', 'publication', 'nodes', 'overrides'], - authsources: ['session', 'entities'], + authsources: ['session', 'entities', 'pasted'], }; const types = (...names) => ({ element: { types: names } }); diff --git a/frontend/src/app/adapters/memory/overrides.ts b/frontend/src/app/adapters/memory/overrides.ts index 0e34924..0a2eaf6 100644 --- a/frontend/src/app/adapters/memory/overrides.ts +++ b/frontend/src/app/adapters/memory/overrides.ts @@ -1,6 +1,8 @@ -import type { ExternalPage, ExternalSource, OverrideComparison, OverridesPort } from '../../../domain/overrides'; +import type { ExternalPage, ExternalSource, ImportPreview, ImportSelection, OverrideComparison, OverridesPort } from '../../../domain/overrides'; +import type { CreationReport } from '../../../domain/pasted'; import type { Failed } from '../../../lib/result'; import { boardSources, copiesOf, type SourceFixture } from './external'; +import { boardImport } from './pastedSeveral'; const ACS = 'catalogue.library.example.edu/Shibboleth.sso/SAML2/POST'; @@ -26,6 +28,8 @@ export interface MemoryOverrides { review?: Failed | 'pending'; sources?: SourceFixture[]; perPage?: number; + // What an Import answers; by default the ImportResult board. + imported?: CreationReport; } const PER_PAGE = 25; @@ -36,7 +40,22 @@ function matches(q: string) { return (row: { entityId: string; name: string | null }) => row.entityId.toLowerCase().includes(needle) || (row.name ?? '').toLowerCase().includes(needle); } -export function memoryOverrides({ comparison = boardComparison, failure, review, sources = boardSources, perPage = PER_PAGE }: MemoryOverrides = {}): OverridesPort { +// The ticked entities of each source, the managed ones left out as Import leaves them. +function preview(sources: SourceFixture[], { set, sources: picked }: ImportSelection): ImportPreview { + return { + sources: picked.flatMap(({ position, all, entityIds }) => { + const fixture = sources[position]; + const rows = (fixture?.sets[set] ?? []).filter((row) => !row.managed && (all || entityIds.includes(row.entityId))); + + return fixture && rows.length > 0 + ? [{ heading: fixture.heading, location: fixture.location, entities: rows.map(({ entityId, name }) => ({ entityId, name })) }] + : []; + }), + }; +} + +export function memoryOverrides(more: MemoryOverrides = {}): OverridesPort { + const { comparison = boardComparison, failure, review, sources = boardSources, perPage = PER_PAGE, imported = boardImport } = more; const answer = async (data: () => T) => (failure ? { ok: false as const, ...failure } : { ok: true as const, data: data() }); return { @@ -62,6 +81,8 @@ export function memoryOverrides({ comparison = boardComparison, failure, review, return answer(() => ({ set, entityId, name, copies })); }, compare: () => answer(() => comparison), + importPreview: (selection) => answer(() => preview(sources, selection)), + runImport: () => answer(() => imported), markReviewed: async () => { if (review === 'pending') { return new Promise(() => undefined); diff --git a/frontend/src/app/adapters/memory/pasted.ts b/frontend/src/app/adapters/memory/pasted.ts new file mode 100644 index 0000000..33a77a7 --- /dev/null +++ b/frontend/src/app/adapters/memory/pasted.ts @@ -0,0 +1,92 @@ +import type { PastedObject, PastedPort, Reading, Target } from '../../../domain/pasted'; +import type { Failed, Result } from '../../../lib/result'; +import { boardSources, copiesOf } from './external'; +import { hrSelfService, noReport, travelbooker } from './pastedBoards'; +import { HOSPITAL, moodleReplacement, severalCandidates } from './pastedSeveral'; + +export interface MemoryPasted { + // What reading answers in place of what the text gives. + reading?: Reading; + failure?: Failed; +} + +const AUTHSOURCE: PastedObject = { + id: 'university-ldap', + name: null, + php: "$config['university-ldap'] = [\n 'ldap:Ldap',\n 'hostname' => 'ldaps://ldap.example.edu',\n];", + report: { ...noReport, understood: ['0', 'hostname'] }, +}; + +// The boards' readings, told apart by what the text holds. +export function boardReading(target: Target, text: string, entityId?: string): Reading { + if (target.kind === 'authsource') { + return { kind: 'one', object: AUTHSOURCE }; + } + const line = text.split('\n').findIndex((at) => at.includes('file_get_contents(')); + if (line >= 0) { + return { kind: 'unreadable', problems: [{ line: line + 1, message: 'file_get_contents(…) is a function call. Paste the certificate itself, as a string.' }] }; + } + if (text.includes('IDPSSODescriptor') && target.set === 'saml20-sp-remote') { + return { kind: 'other-set', set: 'saml20-idp-remote', entityId: HOSPITAL }; + } + const picked = severalCandidates.find((candidate) => candidate.entityId === entityId); + if (picked) { + const php = `$metadata['${picked.entityId}'] = [\n 'name' => ['en' => '${picked.name ?? ''}'],\n];`; + + return { kind: 'one', object: { id: picked.entityId, name: picked.name, php, report: { ...noReport, understood: ['entityid', 'name'] } } }; + } + if ((text.match(/\$metadata\s*\[|<(?:md:)?EntityDescriptor\b/g) ?? []).length > 1) { + return { kind: 'several', candidates: severalCandidates }; + } + if (text.includes('sharedkey')) { + return { kind: 'one', object: hrSelfService }; + } + + return { kind: 'one', object: travelbooker }; +} + +function copyOf(set: Parameters[0], entityId: string, source: number): PastedObject | null { + const copy = copiesOf(boardSources, set, entityId).copies.find(({ position }) => position === source); + + return copy + ? { + id: entityId, + name: copiesOf(boardSources, set, entityId).name, + php: copy.php, + report: { ...noReport, converted: [{ option: 'expire', note: 'Dropped: managed entities do not expire' }] }, + } + : null; +} + +export function memoryPasted({ reading, failure }: MemoryPasted = {}): PastedPort { + const answer = (data: T): Result => (failure ? { ok: false, ...failure } : { ok: true, data }); + + return { + read: async (target, text, _format, entityId) => answer(reading ?? boardReading(target, text, entityId)), + copy: async (set, entityId, source) => { + const found = copyOf(set, entityId, source); + + return found ? answer(found) : { ok: false, status: 404, body: null }; + }, + createSeveral: async (set, _text, _format, entityIds) => + answer({ + set, + created: severalCandidates + .filter((candidate) => entityIds.includes(candidate.entityId)) + .map(({ entityId, name, collision }) => ({ entityId, name, collision })), + skipped: [], + converted: [], + removable: [], + shadowing: [], + pending: 7 + entityIds.length, + }), + replace: async (_set, entityId, xml) => + answer( + reading ?? + (xml.includes(`entityID="${entityId}"`) + ? { kind: 'replaced', replacement: moodleReplacement } + : { kind: 'mismatch', entityId: /entityID="([^"]*)"/.exec(xml)?.[1] ?? '' }), + ), + createAuthsource: async () => answer({ id: AUTHSOURCE.id }), + }; +} diff --git a/frontend/src/app/adapters/memory/pastedBoards.ts b/frontend/src/app/adapters/memory/pastedBoards.ts new file mode 100644 index 0000000..a32a2ff --- /dev/null +++ b/frontend/src/app/adapters/memory/pastedBoards.ts @@ -0,0 +1,97 @@ +import type { PastedObject, PastedReport } from '../../../domain/pasted'; + +const TRAVELBOOKER = 'https://sso.travelbooker.example.com/saml2/metadata/7f3a9c21'; +const POST = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'; +const PERSISTENT = 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'; + +export const noReport: PastedReport = { needs: [], understood: [], converted: [], extra: [], ignored: [] }; + +// The metadata the AddReview board reads. +export const travelbookerXml = [ + ``, + ' ', + ` ${PERSISTENT}`, + ` `, + ' ', + '', +].join('\n'); + +// AddReview. +export const travelbooker: PastedObject = { + id: TRAVELBOOKER, + name: 'Travelbooker', + php: [ + `$metadata['${TRAVELBOOKER}'] = [`, + " 'name' => ['en' => 'Travelbooker'],", + " 'AssertionConsumerService' => [", + ' [', + ` 'Binding' => '${POST}',`, + " 'Location' => 'https://sso.travelbooker.example.com/saml2/acs/7f3a9c21',", + ' ],', + ' ],', + ` 'NameIDFormat' => '${PERSISTENT}',`, + " 'certData' => 'MIIDXTCCAkWgAwIBAgIJAL3f…',", + " 'validate.authnrequest' => true,", + " 'OrganizationName' => ['en' => 'Travelbooker'],", + '];', + ].join('\n'), + report: { + ...noReport, + understood: ['entityid', 'AssertionConsumerService', 'NameIDFormat', 'certData', 'validate.authnrequest', 'OrganizationName'], + converted: [ + { option: 'name', note: 'Taken from OrganizationName' }, + { option: 'certData', note: 'Line breaks removed' }, + ], + ignored: [ + { option: 'validUntil', note: 'Managed entities do not expire' }, + { option: 'index="0"', note: 'Single endpoint' }, + ], + }, +}; + +const HR = 'https://hr.example.edu/sp'; + +// The PHP the AddUnreadable board pastes; line 5 is a function call. +export const hrPhp = [ + `$metadata['${HR}'] = [`, + " 'name' => ['en' => 'HR self-service'],", + " 'AssertionConsumerService' => 'https://hr.example.edu/saml/acs',", + " 'NameIDFormat' => Constants::NAMEID_PERSISTENT,", + " 'certData' => file_get_contents('/etc/ssl/hr.pem'),", + " 'attributes' => ['uid', 'mail'],", + '];', +].join('\n'); + +// ReviewNeeds. +export const hrSelfService: PastedObject = { + id: HR, + name: 'HR self-service', + php: [ + `$metadata['${HR}'] = [`, + " 'name' => ['en' => 'HR self-service'],", + " 'AssertionConsumerService' => [", + ' [', + ` 'Binding' => '${POST}',`, + " 'Location' => 'https://hr.example.edu/saml/acs',", + ' ],', + ' ],', + ` 'NameIDFormat' => '${PERSISTENT}',`, + " 'attributes' => ['uid', 'mail'],", + " 'sharedkey' => 'k3y-in-clear-text',", + " 'vendor.tenant' => 'example-edu',", + '];', + ].join('\n'), + report: { + needs: [ + { option: 'sharedkey', note: 'Secret in clear text. Use a Secret reference.', severity: 'warning' }, + { option: 'certData', note: 'Was a function call. Paste the certificate.', severity: 'error' }, + ], + understood: ['entityid', 'name', 'NameIDFormat', 'attributes'], + converted: [ + { option: 'AssertionConsumerService', note: 'One URL became an endpoint list' }, + { option: 'NameIDFormat', note: 'Constant became its value' }, + ], + extra: [{ option: 'vendor.tenant', note: 'Not a known option' }], + ignored: [{ option: '// comments', note: 'Comments are not kept' }], + }, +}; diff --git a/frontend/src/app/adapters/memory/pastedSeveral.ts b/frontend/src/app/adapters/memory/pastedSeveral.ts new file mode 100644 index 0000000..cbd8db0 --- /dev/null +++ b/frontend/src/app/adapters/memory/pastedSeveral.ts @@ -0,0 +1,79 @@ +import type { Candidate, CreationReport, Replacement } from '../../../domain/pasted'; +import { MOODLE } from './edited'; + +// The four entities the AddSeveral board pastes. +export const severalCandidates: Candidate[] = [ + { entityId: 'https://hr.example.edu/sp', name: 'HR self-service', managed: true, collision: null }, + { entityId: 'https://print.example.edu/saml2/service-provider-metadata/campus', name: 'Print service', managed: true, collision: null }, + { entityId: 'https://timetable.example.edu/sp', name: 'Timetable', managed: false, collision: 'override' }, + { entityId: 'https://parking.example.edu/saml/metadata', name: 'Parking permits', managed: false, collision: null }, +]; + +export const severalPhp = severalCandidates + .map(({ entityId, name }) => `$metadata['${entityId}'] = [\n 'name' => ['en' => '${name ?? ''}'],\n];`) + .join('\n'); + +// The identity provider the AddWrongKind board pastes as a service provider. +export const HOSPITAL = 'https://idp.hospital.example.org/idp/shibboleth'; + +export const hospitalXml = [ + ``, + ' ', + ' …', + ' ', + '', +].join('\n'); + +const CERT_OLD = " 'certData' => 'MIIDXTCCAkWgAwIBAgIJAL3f…',"; +const CERT_NEW = " 'certData' => 'MIIDdzCCAl+gAwIBAgIEbq9…',"; + +// ReplaceFrom: Moodle from its new metadata. +export const moodleReplacement: Replacement = { + entityId: MOODLE, + name: 'Moodle', + version: 4, + removed: 4, + php: [ + `$metadata['${MOODLE}'] = [`, + " 'name' => ['en' => 'Moodle'],", + " 'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',", + " 'certData' => 'MIIDdzCCAl+gAwIBAgIEbq9…',", + " 'validate.authnrequest' => true,", + '];', + ].join('\n'), + diff: [ + { kind: 'same', text: " 'name' => [" }, + { kind: 'same', text: " 'en' => 'Moodle'," }, + { kind: 'del', text: " 'es' => 'Campus virtual'," }, + { kind: 'same', text: ' ],' }, + { kind: 'same', text: " 'AssertionConsumerService' => [ … ]," }, + { kind: 'del', text: " 'SingleLogoutService' => [ … ]," }, + { kind: 'same', text: " 'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'," }, + { kind: 'del', text: " 'attributes' => ['uid', 'mail', 'displayName']," }, + { kind: 'del', text: " 'attributes.NameFormat' => 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri'," }, + { kind: 'del', text: CERT_OLD }, + { kind: 'add', text: CERT_NEW }, + { kind: 'same', text: " 'validate.authnrequest' => true," }, + { kind: 'del', text: " 'assertion.encryption' => false," }, + ], +}; + +export const moodleXml = `\n …\n`; + +// ImportResult. +export const boardImport: CreationReport = { + set: 'saml20-sp-remote', + created: [ + { entityId: 'https://journals.publisher.example.com/shibboleth', name: 'E-journals', collision: 'override' }, + { entityId: 'https://labs.partner.example.org/Shibboleth.sso/Metadata', name: 'Lab booking', collision: 'override' }, + { entityId: 'https://meet.vendor.example.com/saml2/sp', name: 'Video conferencing', collision: 'override' }, + ], + skipped: [{ entityId: 'https://card.example.edu/sp', name: 'Campus card', reason: 'Already managed' }], + converted: [ + { option: 'expire', note: 'Dropped: managed entities do not expire' }, + { option: 'certFingerprint', note: 'Kept as an extra option' }, + ], + removable: [{ location: 'metadata/saml20-sp-remote.php', entityIds: [] }], + shadowing: [], + pending: 10, +}; diff --git a/frontend/src/app/test/StoryMessages.tsx b/frontend/src/app/test/StoryMessages.tsx index 7f50ba5..33ff54d 100644 --- a/frontend/src/app/test/StoryMessages.tsx +++ b/frontend/src/app/test/StoryMessages.tsx @@ -6,11 +6,11 @@ import { ReportMessage } from '../../domain/session'; // The Console's one-shot message in a story: shown on the page it moves to, which loads afresh. export function StoryMessages({ children }: { children: ReactNode }) { - const [said, setSaid] = useState<{ text: string; round: number } | null>(null); + const [said, setSaid] = useState<{ text: string; shown: ReactNode; round: number } | null>(null); const navigate = useNavigate(); const announce = useCallback( - (text: string, to?: string) => { - setSaid((last) => ({ text, round: (last?.round ?? 0) + 1 })); + (text: string, to?: string, shown?: ReactNode) => { + setSaid((last) => ({ text, shown, round: (last?.round ?? 0) + 1 })); if (to !== undefined) { void navigate(to, { replace: true }); } @@ -20,7 +20,7 @@ export function StoryMessages({ children }: { children: ReactNode }) { return ( - }> + )}> {children} diff --git a/frontend/src/app/test/StoryScreens.tsx b/frontend/src/app/test/StoryScreens.tsx index d3a4159..692f36c 100644 --- a/frontend/src/app/test/StoryScreens.tsx +++ b/frontend/src/app/test/StoryScreens.tsx @@ -6,6 +6,7 @@ import type { EntitySet } from '../../domain/entities'; import { NodesPortContext, type NodeList } from '../../domain/nodes'; import { OverridesPortContext } from '../../domain/overrides'; import { OverviewPortContext } from '../../domain/overview'; +import { PastedHold, PastedPortContext, type Held } from '../../domain/pasted'; import { HistoryPortContext } from '../../domain/publication'; import type { Counts } from '../../domain/session'; import type { Failed } from '../../lib/result'; @@ -18,6 +19,7 @@ import { hostedRows, idpRows } from '../adapters/memory/idps'; import { memoryNodes } from '../adapters/memory/nodes'; import { memoryOverrides, type MemoryOverrides } from '../adapters/memory/overrides'; import { memoryOverview, type MemoryOverview } from '../adapters/memory/overview'; +import { memoryPasted, type MemoryPasted } from '../adapters/memory/pasted'; import { boardList } from '../adapters/memory/rows'; import { StoryFrame } from './StoryFrame'; import { StoryMessages } from './StoryMessages'; @@ -30,6 +32,9 @@ export interface ScreenPorts { overrides?: MemoryOverrides; overview?: MemoryOverview; authsources?: MemoryAuthsources; + pasted?: MemoryPasted; + // What an earlier step read. + held?: Held | null; sets?: Partial>; pending?: number; counts?: Counts; @@ -43,7 +48,7 @@ const SET_ROWS: Record = { type Ports = ReturnType; -function portsOf({ history, nodes, audit, overrides, overview, authsources, sets }: ScreenPorts) { +function portsOf({ history, nodes, audit, overrides, overview, authsources, pasted, sets }: ScreenPorts) { return { history: memoryHistory(history), nodes: memoryNodes(nodes), @@ -51,6 +56,7 @@ function portsOf({ history, nodes, audit, overrides, overview, authsources, sets overrides: memoryOverrides(overrides), overview: memoryOverview(overview), authsources: memoryAuthsources(authsources), + pasted: memoryPasted(pasted), sets: { 'saml20-sp-remote': memoryEntities({ ...SET_ROWS['saml20-sp-remote'], ...sets?.['saml20-sp-remote'] }), 'saml20-idp-remote': memoryEntities({ ...SET_ROWS['saml20-idp-remote'], ...sets?.['saml20-idp-remote'] }), @@ -87,13 +93,17 @@ export function StoryScreens({ pending = 7, counts, ...more }: ScreenPorts) { - - - {routes.map((route) => ( - } /> - ))} - - + + + + + {routes.map((route) => ( + } /> + ))} + + + + diff --git a/frontend/src/app/test/pasted.ts b/frontend/src/app/test/pasted.ts new file mode 100644 index 0000000..2fe51e5 --- /dev/null +++ b/frontend/src/app/test/pasted.ts @@ -0,0 +1,29 @@ +import { userEvent, within } from 'storybook/test'; +import type { Held, PastedObject, Reading } from '../../domain/pasted'; +import { hrSelfService, travelbooker, travelbookerXml } from '../adapters/memory/pastedBoards'; +import { moodleReplacement, moodleXml, severalCandidates, severalPhp } from '../adapters/memory/pastedSeveral'; + +export const SP_ADD = '/entities/saml20-sp-remote/new'; +export const SP_REVIEW = `${SP_ADD}/review`; +export const SP_SEVERAL = `${SP_ADD}/several`; +export const ENTITY_TEXT = 'Metadata XML or PHP array'; + +export function heldOne(object: PastedObject = travelbooker, at = SP_REVIEW): Held { + return { at, text: object === hrSelfService ? hrSelfService.php : travelbookerXml, format: 'xml', reading: { kind: 'one', object } }; +} + +export const heldSeveral: Held = { at: SP_SEVERAL, text: severalPhp, format: 'php', reading: { kind: 'several', candidates: severalCandidates } }; + +export function heldReplacement(at: string): Held { + const reading: Reading = { kind: 'replaced', replacement: moodleReplacement }; + + return { at, text: moodleXml, format: 'xml', reading }; +} + +// Pastes the text into the text area named by label, with the focus left elsewhere. +export async function pasteInto(canvasElement: HTMLElement, label: string, text: string): Promise { + const area = await within(canvasElement).findByRole('textbox', { name: label }); + await userEvent.click(area); + await userEvent.paste(text); + area.blur(); +} diff --git a/frontend/src/app/test/pastedRoutes.tsx b/frontend/src/app/test/pastedRoutes.tsx new file mode 100644 index 0000000..2ac61f0 --- /dev/null +++ b/frontend/src/app/test/pastedRoutes.tsx @@ -0,0 +1,60 @@ +import { AUTHSOURCE_NEW, AUTHSOURCES } from '../../domain/authsources'; +import { editPath, listRoute, SET_WORDS, SP_EDIT, SP_LIST, type EntitySet } from '../../domain/entities'; +import { EXTERNAL, IMPORT } from '../../domain/overrides'; +import { addPath, AUTHSOURCE_REVIEW } from '../../domain/pasted'; +import { AddFromPastePage, AddSeveralPage, PastedReviewPage } from '../../pages/AddFromPastePage'; +import { EditServiceProviderPage } from '../../pages/EditServiceProviderPage'; +import { ImportPage } from '../../pages/ImportPage'; +import { ManagedCopyPage } from '../../pages/ManagedCopyPage'; +import { ReplaceFromPage, ReplaceReviewPage } from '../../pages/ReplaceFromPage'; +import { ReviewAuthsourcePage } from '../../pages/ReviewAuthsourcePage'; +import { MOODLE } from '../adapters/memory/edited'; +import type { Crumb } from '../Shell'; +import type { StoryRoute } from './storyRoutes'; + +const SETS = Object.keys(SET_WORDS) as EntitySet[]; +const at = (...crumbs: Crumb[]) => () => crumbs; +const noop = () => undefined; + +function named(search: URLSearchParams): Crumb { + const entityId = search.get('entityid') ?? ''; + + return { label: entityId === MOODLE ? 'Moodle' : entityId, to: editPath(entityId) }; +} + +// The steps of creating from pasted configuration, of "Replace from…" and of Import (SPEC 9.5 to 9.7). +export function pastedRoutes(external: (search: URLSearchParams, set: string | undefined) => Crumb[]): StoryRoute[] { + return [ + ...SETS.flatMap((set) => { + const list = { label: SET_WORDS[set].title, to: listRoute(set) }; + + return [ + { path: addPath(set), crumbs: at(list, { label: 'Add' }), page: , set }, + { path: addPath(set, '/review'), crumbs: at(list, { label: 'Add', to: addPath(set) }, { label: 'Review' }), page: , set }, + { path: addPath(set, '/several'), crumbs: at(list, { label: 'Add' }), page: , set }, + ]; + }), + { + path: `${SP_LIST}/replace`, + crumbs: (search) => [{ label: 'Service providers', to: SP_LIST }, named(search), { label: 'Replace' }], + page: , + }, + { + path: `${SP_LIST}/replace/review`, + crumbs: (search) => [{ label: 'Service providers', to: SP_LIST }, named(search), { label: 'Replace' }], + page: , + }, + { + path: SP_EDIT, + crumbs: (search) => [{ label: 'Service providers', to: SP_LIST }, { label: named(search).label }], + page: , + }, + { path: IMPORT, crumbs: at({ label: 'External entities', to: EXTERNAL }, { label: 'Import' }), page: }, + { path: `${EXTERNAL}/:set/copy`, crumbs: (search, set) => [...external(search, set), { label: 'Copy' }], page: }, + { + path: AUTHSOURCE_REVIEW, + crumbs: at({ label: 'Authsources', to: AUTHSOURCES }, { label: 'Add', to: AUTHSOURCE_NEW }, { label: 'Review' }), + page: , + }, + ]; +} diff --git a/frontend/src/app/test/storyRoutes.tsx b/frontend/src/app/test/storyRoutes.tsx index f24e42f..31b36cc 100644 --- a/frontend/src/app/test/storyRoutes.tsx +++ b/frontend/src/app/test/storyRoutes.tsx @@ -18,6 +18,7 @@ import { RollbackPage } from '../../pages/RollbackPage'; import { copiesOf, type SourceFixture } from '../adapters/memory/external'; import { boardComparison } from '../adapters/memory/overrides'; import type { Crumb } from '../Shell'; +import { pastedRoutes } from './pastedRoutes'; export interface StoryRoute { path: string; @@ -55,5 +56,6 @@ export function storyRoutes(sources: SourceFixture[]): StoryRoute[] { crumbs: at({ label: 'Service providers', to: SP_LIST }, { label: compared, to: editPath(boardComparison.entityId) }, { label: 'Compare' }), page: , }, + ...pastedRoutes(external), ]; } diff --git a/frontend/src/console.css b/frontend/src/console.css index 8f69f60..787be11 100644 --- a/frontend/src/console.css +++ b/frontend/src/console.css @@ -474,6 +474,25 @@ textarea.input-code{line-height:1.65;white-space:pre;overflow-x:auto} .add-detected{display:flex;align-items:center;gap:8px;flex:1 1 auto} .add-detected .input{width:auto;height:32px;font-size:13px} +/* Pasted configuration and Import (AddEmpty, AddUnreadable, AddWrongKind, AddReview, ReviewNeeds, AddSeveral, ReplaceFrom, ImportResult) */ +.add-link{align-self:flex-start} +.examples{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(240px,100%),1fr));gap:12px} +.grp-body:has(>.examples){padding:0 16px 16px} +.example{display:flex;flex-direction:column;gap:6px;min-width:0} +.example-title{font-weight:600} +.rev{display:flex;flex-wrap:wrap;align-items:flex-start;gap:24px 32px} +.rep-groups{display:flex;flex-direction:column;gap:12px;flex:1 1 380px;min-width:0} +.rev-php{display:flex;flex-direction:column;gap:8px;flex:1 1 460px;min-width:0} +.rep{overflow:hidden} +.rep-warn{border-color:var(--warning-border)} +.rep-head{display:flex;align-items:baseline;gap:8px;padding:12px 16px} +.rep-row{padding:8px 16px;gap:12px;align-items:baseline;flex-wrap:wrap} +.rep-name{flex:0 1 230px;overflow-wrap:anywhere} +.rep-note{flex:1 1 160px} +.rep-id{display:block;overflow-wrap:anywhere} +.pick-row{flex-wrap:wrap;gap:4px 24px} +.bar-start{margin-inline-end:auto} + /* last, so it wins over .input's font */ .mono{font-family:var(--mono);font-size:12.5px} .input.mono{font-size:13px} diff --git a/frontend/src/design-system/Disclosure.stories.tsx b/frontend/src/design-system/Disclosure.stories.tsx index 895b0b9..85c41f6 100644 --- a/frontend/src/design-system/Disclosure.stories.tsx +++ b/frontend/src/design-system/Disclosure.stories.tsx @@ -72,3 +72,13 @@ export const Keyboard: Story = { await expect(trigger).toHaveFocus(); }, }; + +export const Open: Story = { + args: { card: true, defaultExpanded: true }, + play: async ({ canvasElement }) => { + const page = within(canvasElement); + + await expect(page.getByRole('button', { name: 'Technical detail' })).toHaveAttribute('aria-expanded', 'true'); + await expect(page.getByLabelText('Technical detail', { selector: 'pre' })).toBeVisible(); + }, +}; diff --git a/frontend/src/design-system/Disclosure.tsx b/frontend/src/design-system/Disclosure.tsx index 02863f1..23433af 100644 --- a/frontend/src/design-system/Disclosure.tsx +++ b/frontend/src/design-system/Disclosure.tsx @@ -5,12 +5,13 @@ interface DisclosureProps { summary: string; // A card of its own, as the warnings on Publish, rather than a fold inside another surface. card?: boolean; + defaultExpanded?: boolean; children: ReactNode; } -export function Disclosure({ summary, card, children }: DisclosureProps) { +export function Disclosure({ summary, card, defaultExpanded = false, children }: DisclosureProps) { return ( - + diff --git a/frontend/src/domain/authsources/AddAuthsource.tsx b/frontend/src/domain/authsources/AddAuthsource.tsx index 00b9288..931c934 100644 --- a/frontend/src/domain/authsources/AddAuthsource.tsx +++ b/frontend/src/domain/authsources/AddAuthsource.tsx @@ -1,12 +1,10 @@ -import { useState } from 'react'; import { useNavigate, useSearchParams } from 'react-router'; -import { Button } from '../../design-system/Button'; import { Card } from '../../design-system/Card'; import { FileButton } from '../../design-system/FileButton'; import { ChevronIcon } from '../../design-system/icons'; import { Row } from '../../design-system/Row'; import { LinkSegmented } from '../../design-system/Segmented'; -import { TextArea } from '../../design-system/TextArea'; +import { AUTHSOURCE_REVIEW, PasteArea, usePaste, usePastedPort } from '../pasted'; import { AUTHSOURCE_NEW, startPath } from './port'; // SPEC 6.5: the five Authsource types, each with what it is for. @@ -45,9 +43,15 @@ export function AddAuthsource() { const navigate = useNavigate(); const wanted = useSearchParams()[0].get('source'); const source = SOURCES.find(({ key }) => key === wanted)?.key ?? 'paste'; - const [text, setText] = useState(''); + const port = usePastedPort(); + const paste = usePaste({ + at: AUTHSOURCE_NEW, + read: (text, format) => port.read({ kind: 'authsource' }, text, format), + next: (reading) => (reading.kind === 'one' ? AUTHSOURCE_REVIEW : null), + formats: ['php'], + }); const loaded = (read: string) => { - setText(read); + paste.setText(read); void navigate(AUTHSOURCE_NEW); }; @@ -60,16 +64,7 @@ export function AddAuthsource() { )} - {source === 'paste' && ( - <> -