Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/editor/src/ui/editor/EditorCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1789,8 +1789,6 @@ export default function EditorCanvas({ onBack, onSaveToServer, onPlanAlignmentSt
adoptionStatus: loadedFramework?.metadata?.adoptionStatus,
readOnly,
publicAccess: loadedFramework?.metadata?.publicAccess === true,
sourcePackageURI: mirrorStatus?.sourcePackageURI,
isModifiedFromSource: mirrorStatus?.isModifiedFromSource,
}}
userName={userName ?? undefined}
tenantId={tenantId ?? undefined}
Expand Down
5 changes: 3 additions & 2 deletions apps/editor/src/ui/editor/components/CanvasHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ describe('CanvasHeader', () => {
<CanvasHeader
frameworkTitle="Skills-First Product Managers Skill Taxonomy"
frameworkSubtitle="Competency"
frameworkLabels={{ adoptionStatus: 'Derived', publicAccess: true, isModifiedFromSource: false }}
frameworkLabels={{ adoptionStatus: 'Derived', publicAccess: true }}
/>,
)
expect(screen.getByText('Skills-First Product Managers Skill Taxonomy')).toBeInTheDocument()
expect(screen.getByText('Competency')).toBeInTheDocument()
expect(screen.getByText('Derived')).toBeInTheDocument()
expect(screen.getByText('Public')).toBeInTheDocument()
expect(screen.getByText('Mirrored')).toBeInTheDocument()
expect(screen.queryByText('Mirrored')).not.toBeInTheDocument()
expect(screen.queryByText('Forked')).not.toBeInTheDocument()
})

it('shows no labels when none are given', () => {
Expand Down
6 changes: 0 additions & 6 deletions apps/editor/src/ui/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,6 @@ export default function HomeScreen({
frameworkType: doc.frameworkType,
adoptionStatus: doc.adoptionStatus,
}}
sourcePackageURI={doc.extensions?.['ext:opencase']?.sourcePackageURI}
isModifiedFromSource={doc.extensions?.['ext:opencase']?.isModifiedFromSource}
readOnly={doc.readOnly === true}
publicAccess={doc.extensions?.['ext:opencase']?.publicAccess === true}
rightHint={isArchiving ? 'Archiving' : hint}
Expand Down Expand Up @@ -902,8 +900,6 @@ export default function HomeScreen({
frameworkType: doc.frameworkType,
adoptionStatus: doc.adoptionStatus,
}}
sourcePackageURI={doc.extensions?.['ext:opencase']?.sourcePackageURI}
isModifiedFromSource={doc.extensions?.['ext:opencase']?.isModifiedFromSource}
readOnly
publicAccess={doc.extensions?.['ext:opencase']?.publicAccess === true}
rightHint={isArchiving ? 'Archiving' : hint}
Expand Down Expand Up @@ -955,8 +951,6 @@ export default function HomeScreen({
frameworkType: doc.frameworkType,
adoptionStatus: doc.adoptionStatus,
}}
sourcePackageURI={doc.extensions?.['ext:opencase']?.sourcePackageURI}
isModifiedFromSource={doc.extensions?.['ext:opencase']?.isModifiedFromSource}
readOnly={doc.readOnly === true}
publicAccess={doc.extensions?.['ext:opencase']?.publicAccess === true}
rightHint={isDeleting ? 'Deleting' : (isRestoring ? 'Restoring' : undefined)}
Expand Down
8 changes: 0 additions & 8 deletions apps/editor/src/ui/shared/components/FrameworkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ type Props = {
children?: ReactNode
/** ISO date string for the last change — shown in the card footer */
lastChanged?: string
/** URL the framework was imported from, if known — shown in the Mirrored/Forked badge tooltip */
sourcePackageURI?: string
/** Set (true or false) once a framework has been imported/mirrored; true once it's been locally modified (forked) */
isModifiedFromSource?: boolean
/** Read-only cached remote framework (CGE cache) */
readOnly?: boolean
/** CASE API readable without signing in */
Expand All @@ -66,8 +62,6 @@ export function FrameworkCard({
className,
children,
lastChanged,
sourcePackageURI,
isModifiedFromSource,
readOnly,
publicAccess,
}: Readonly<Props>) {
Expand Down Expand Up @@ -178,8 +172,6 @@ export function FrameworkCard({
adoptionStatus={adoptionStatus}
readOnly={readOnly}
publicAccess={publicAccess}
sourcePackageURI={sourcePackageURI}
isModifiedFromSource={isModifiedFromSource}
/>

{relDate ? (
Expand Down
19 changes: 8 additions & 11 deletions apps/editor/src/ui/shared/components/FrameworkLabels.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,16 @@ describe('FrameworkLabels', () => {
expect(screen.getByText('Public')).toHaveAttribute('title', 'Anyone can read this framework without signing in')
})

it('shows Mirrored for an unmodified import, with the source in the tooltip', () => {
render(<FrameworkLabels isModifiedFromSource={false} sourcePackageURI="https://example.org/pkg" />)
expect(screen.getByText('Mirrored')).toHaveAttribute('title', 'Mirrored from https://example.org/pkg')
})

it('shows Forked for a locally modified import', () => {
render(<FrameworkLabels isModifiedFromSource />)
expect(screen.getByText('Forked')).toHaveAttribute('title', 'Forked — originally mirrored, now locally modified')
})
it.each([false, true, undefined])('does not show import status when isModifiedFromSource is %s', (isModifiedFromSource) => {
const provenance = { isModifiedFromSource, sourcePackageURI: 'https://example.org/pkg' }
const { container } = render(<FrameworkLabels {...provenance} adoptionStatus="Draft" readOnly publicAccess />)

it('shows no mirror badge for a framework that was never imported', () => {
render(<FrameworkLabels adoptionStatus="Draft" />)
expect(screen.queryByText('Mirrored')).not.toBeInTheDocument()
expect(screen.queryByText('Forked')).not.toBeInTheDocument()
expect(screen.queryByTitle(/mirrored|forked/i)).not.toBeInTheDocument()
expect(container.querySelector('svg')).not.toBeInTheDocument()
expect(screen.getByText('Draft')).toBeInTheDocument()
expect(screen.getByText('Read-only')).toBeInTheDocument()
expect(screen.getByText('Public')).toBeInTheDocument()
})
})
27 changes: 1 addition & 26 deletions apps/editor/src/ui/shared/components/FrameworkLabels.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CloudArrowDownIcon } from '@heroicons/react/24/solid'
import { cn } from '@/lib/utils'
import { normalizeAdoptionStatus } from '@/domain/framework/model/adoptionStatus'

Expand Down Expand Up @@ -33,23 +32,17 @@ type Props = {
readOnly?: boolean
/** CASE API readable without signing in */
publicAccess?: boolean
/** URL the framework was imported from, if known — shown in the Mirrored/Forked badge tooltip */
sourcePackageURI?: string
/** Set (true or false) once a framework has been imported/mirrored; true once it's been locally modified (forked) */
isModifiedFromSource?: boolean
className?: string
}

/**
* Framework status badges (adoption status, Read-only, Public, Mirrored/Forked),
* Framework status badges (adoption status, Read-only, Public),
* shared by the home screen's framework cards and the editor header.
*/
export function FrameworkLabels({
adoptionStatus,
readOnly,
publicAccess,
sourcePackageURI,
isModifiedFromSource,
className,
}: Readonly<Props>) {
const statusInfo = adoptionStatus ? STATUS_STYLE[normalizeAdoptionStatus(adoptionStatus) ?? adoptionStatus] : undefined
Expand Down Expand Up @@ -77,24 +70,6 @@ export function FrameworkLabels({
Public
</span>
) : null}
{isModifiedFromSource !== undefined ? (
<span
className={cn(
'inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-xs font-semibold',
isModifiedFromSource
? 'bg-violet-100 text-violet-700'
: 'bg-sky-100 text-sky-700',
)}
title={
isModifiedFromSource
? sourcePackageURI ? `Forked — originally mirrored from ${sourcePackageURI}` : 'Forked — originally mirrored, now locally modified'
: sourcePackageURI ? `Mirrored from ${sourcePackageURI}` : 'Mirrored — kept in sync with its imported source'
}
>
<CloudArrowDownIcon className="h-3 w-3" />
{isModifiedFromSource ? 'Forked' : 'Mirrored'}
</span>
) : null}
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ export class CreateFramework {
const doc = CFDocument.fromRaw(tenantId, caseVersion, docPayload, uriOptions)
const dId = doc.sourcedId
const dURI = doc.toJSON().uri
const items = itemsPayload.map((i: any) => CFItem.fromRaw(tenantId, caseVersion, i, dId, dURI, uriOptions))
const localNodeIdentifiers = new Set([dId, ...items.map(i => i.sourcedId)])
return {
document: doc,
items: itemsPayload.map((i: any) => CFItem.fromRaw(tenantId, caseVersion, i, dId, dURI, uriOptions)),
associations: assocPayload.map((a: any) => CFAssociation.fromRaw(tenantId, caseVersion, a, { ...uriOptions, documentIdentifiers: [dId] })),
items,
associations: assocPayload.map((a: any) => CFAssociation.fromRaw(tenantId, caseVersion, a, { ...uriOptions, documentIdentifiers: [dId], localNodeIdentifiers })),
rubrics: rubricsPayload.map((r: any) => CFRubric.fromRaw(tenantId, caseVersion, r, uriOptions))
}
}
Expand Down Expand Up @@ -304,8 +306,9 @@ export class CreateFramework {
const items = cfItemsPayload.map((i: any) =>
CFItem.fromRaw(tenantId, caseVersion, i, docId, docURI, preserveUris)
)
const localNodeIdentifiers = new Set([docId, ...items.map(i => i.sourcedId)])
const associations = cfAssociationsPayload.map((a: any) =>
CFAssociation.fromRaw(tenantId, caseVersion, a, { ...preserveUris, documentIdentifiers: [docId] })
CFAssociation.fromRaw(tenantId, caseVersion, a, { ...preserveUris, documentIdentifiers: [docId], localNodeIdentifiers })
)
const rubrics = cfRubricsPayload.map((r: any) =>
CFRubric.fromRaw(tenantId, caseVersion, r, preserveUris)
Expand Down
27 changes: 13 additions & 14 deletions apps/opencase/src/application/case/endpoints/ImportFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CFPackage } from '../../../domain/case/entities/CFPackage'
import { logger } from '../../../infrastructure/logging/Logger'
import { OPENCASE_EXT_KEY, stripOpenCaseExtensions } from '../services/openCaseExtensions'
import { deriveSourcePackageURI } from '../services/packageUri'
import { mintForkedIdentifiers } from '../services/mirrorFork'
import { coerceMistypedStrings } from '../services/coerceMistypedStrings'
import type { ImportDocumentFlags } from '../types/ImportDocumentFlags'

Expand All @@ -36,11 +37,8 @@ export interface ImportFrameworkResult {
}

/**
* Create the `ext:opencase` extension on a CFDocument payload, marking it as a
* pristine mirror of the source. The payload must already have had any incoming
* `ext:opencase` discarded (see execute) — OpenCASE's own state is never taken
* from an import source. `endpointUrl` is the import URL, or for pasted JSON
* whatever source could be derived from the document (may be unknown).
* Record source provenance after incoming OpenCASE state has been removed.
* Editable imports get local identities. Read-only caches keep source identities.
*/
function injectSourceProvenance (
docPayload: any,
Expand All @@ -54,7 +52,7 @@ function injectSourceProvenance (
// can't be derived has none, so the field is left off entirely rather
// than written as undefined.
...(endpointUrl ? { sourcePackageURI: endpointUrl } : {}),
isModifiedFromSource: false,
isModifiedFromSource: documentFlags?.readOnly !== true,
importedAt: new Date().toISOString(),
// An imported CFPackage carries its associations to other frameworks inline,
// and there is no way to import alignment frameworks.
Expand Down Expand Up @@ -121,7 +119,7 @@ export class ImportFramework {
}

// Use CFPackage format directly (matches API response format)
const payload = {
let payload = {
CFDocument: sourceCFPackage.CFDocument,
CFItems: sourceCFPackage.CFItems ?? [],
CFAssociations: sourceCFPackage.CFAssociations ?? [],
Expand All @@ -130,10 +128,7 @@ export class ImportFramework {
extensions: sourceCFPackage.extensions
}

// Saves are strictly validated against the CFPackage schema, so numbers the
// publisher sent where a string belongs are turned into strings now — otherwise
// the framework imports fine but can never be saved (CGE-183). This is a type
// correction of the source's own values, so the import is still a pristine mirror.
// Convert numeric values to strings where the save schema requires strings.
const packageSchemaName = caseVersion === '1.1' ? 'case-v1p1-cfpackage' : 'case-v1p0-cfpackage'
const coercedPaths = coerceMistypedStrings(this.validator, packageSchemaName, payload)
if (coercedPaths.length > 0) {
Expand All @@ -155,9 +150,13 @@ export class ImportFramework {
}
}

// Create domain entities from CFPackage format. Mirrored imports preserve the
// source's identifiers/URIs as-is rather than rewriting them onto this instance —
// they're only regenerated once the framework is edited and forked (a later task).
// Keep publisher identities for read-only remote references and cache refreshes.
if (documentFlags?.readOnly !== true) {
const { bundle } = mintForkedIdentifiers(payload, tenantId, caseVersion)
payload = { ...payload, ...bundle }
}

// Local identities are already set. Cache identities must stay unchanged.
const preserveUris = { preserveUris: true }
const document = CFDocument.fromRaw(tenantId, caseVersion, payload.CFDocument, preserveUris)
const docId = document.sourcedId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class UpdateCFAssociation {

// Update the specific association
const updatedAssociation = CFAssociation.fromRaw(tenantId, caseVersion, payload, {
documentIdentifiers: [existingPkg.document.sourcedId]
documentIdentifiers: [existingPkg.document.sourcedId],
localNodeIdentifiers: new Set([existingPkg.document.sourcedId, ...existingPkg.items.map(i => i.sourcedId)])
})

// Replace the association in the associations array
Expand Down
Loading
Loading