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
26 changes: 26 additions & 0 deletions plugin/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
LlmSettingsUpdate,
PipelineStatusResponse,
PipelineSummaryItem,
QuestionnaireChangesResponse,
TemplateDetail,
TemplateOption,
TemplateScope,
Expand Down Expand Up @@ -243,6 +244,31 @@ export const getLatestQuestionnaireEventUuid = async (
return latest.uuid
}

export const getQuestionnaireChanges = async (
runId: string,
): Promise<QuestionnaireChangesResponse> => {
const url = `${getApiBaseUrl()}/pipelines/status/${encodeURIComponent(runId)}/changes`
const response = await apiFetch(url)
const data = await readApiResponse<QuestionnaireChangesResponse | { detail?: string }>(
response,
url,
)

if (!response.ok) {
throw new Error(
'detail' in data && data.detail
? data.detail
: 'Failed to load the changes of the questionnaire.',
)
}

if (!('tree' in data) || !Array.isArray(data.tree)) {
throw new Error('Invalid questionnaire changes returned.')
}

return data
}

export const deletePipeline = async (runId: string): Promise<void> => {
const url = `${getApiBaseUrl()}/pipelines/status/${encodeURIComponent(runId)}`
const response = await apiFetch(url, { method: 'DELETE' })
Expand Down
9 changes: 9 additions & 0 deletions plugin/src/components/Modal.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
color: var(--ui-text);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The visualisation of the changed replies is awesome. I have one suggestion, we could add a link to the question that would open in another tab. When the user opens the change list, they might notice that they made a mistake or make their answer clearer in the questionnaire.

}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, the warning about the change in the questionnaire is caused also by unrelated changes - like adding a TODO. Maybe we should find out what else can provoke the warning, just to be sure, we don't show it with the empty change list


/* The body takes the height the header and footer leave, so the dialog does not resize with its content. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I don’t like that much is that we store replies in our DB even though they are already stored in the DSW. However, I really like the change list, and we need the replies for that. I looked into the DB, and I think we store a whole snapshot of the replies for every run? It is a lot of data, maybe we could store only the changes from the last version? Maybe that would be an issue when we delete a run?

.fullHeight {
height: calc(100vh - 3.5rem);
}

.fullHeight .body {
flex: 1;
}

.content:focus {
outline: none;
}
Expand Down
7 changes: 6 additions & 1 deletion plugin/src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type ModalProps = {
initialFocusRef?: RefObject<HTMLElement | null>
/** Blocks closing, e.g. while the content is being saved. */
closeDisabled?: boolean
/** As tall as the window allows the whole time, so content that grows or shrinks does not resize it. */
fullHeight?: boolean
}

/**
Expand All @@ -38,6 +40,7 @@ export function Modal({
busy,
initialFocusRef,
closeDisabled = false,
fullHeight = false,
}: ModalProps) {
return (
<Dialog.Root
Expand All @@ -47,7 +50,9 @@ export function Modal({
<Dialog.Portal>
<Dialog.Overlay className={styles.overlay} />
<Dialog.Content
className={styles.content}
className={
fullHeight ? `${styles.content} ${styles.fullHeight}` : styles.content
}
aria-describedby={descriptionId}
aria-busy={busy}
onOpenAutoFocus={(event) => {
Expand Down
35 changes: 0 additions & 35 deletions plugin/src/components/QuestionnaireChangeBadge.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions plugin/src/components/QuestionnaireChangeNote.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* The alert's content fills the row, so the button can sit at the end. */
.note :global(.ui-alert__content) {
flex: 1;
min-width: 0;
}
46 changes: 46 additions & 0 deletions plugin/src/components/QuestionnaireChangeNote.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Alert } from '@ds-wizard/plugin-sdk/ui/Alert'
import { Button } from '@ds-wizard/plugin-sdk/ui/Button'
import { Inline } from '@ds-wizard/plugin-sdk/ui/Layout'
import { useState } from 'react'

import styles from '@/components/QuestionnaireChangeNote.module.css'
import { QuestionnaireChangesModal } from '@/components/QuestionnaireChangesModal'
import type { RunRecord } from '@/hooks/useGenerationHistory'
import {
isQuestionnaireChanged,
type LatestQuestionnaireEvent,
} from '@/hooks/useLatestQuestionnaireEvent'

type QuestionnaireChangeNoteProps = {
run: Pick<RunRecord, 'runId' | 'status' | 'sourceEventUuid'>
latestEvent: LatestQuestionnaireEvent
}

/**
* A note, shown when the questionnaire answers may have changed since the document was generated, that lists
* what changed when clicked.
*/
export function QuestionnaireChangeNote({ run, latestEvent }: QuestionnaireChangeNoteProps) {
const [isOpen, setIsOpen] = useState(false)

if (run.status !== 'succeeded') return null

// Still checking, unchanged, or not verifiable (older run, DSW unreachable): nothing to show.
if (!isQuestionnaireChanged(run.sourceEventUuid, latestEvent)) return null

return (
<>
<Alert tone="warning" className={styles.note}>
<Inline align="between">
<span>DMP is outdated</span>
<Button size="small" variant="secondary" onClick={() => setIsOpen(true)}>
Show changes
</Button>
</Inline>
</Alert>
{isOpen && (
<QuestionnaireChangesModal runId={run.runId} onClose={() => setIsOpen(false)} />
)}
</>
)
}
112 changes: 112 additions & 0 deletions plugin/src/components/QuestionnaireChangesModal.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
.tree {
--tree-indent: 1.25rem;
--tree-line: var(--ui-border-strong);
/* Where a line of text is cut by its connector, about the middle of the first line. */
--tree-elbow: 0.75em;

font-size: 0.875rem;
line-height: 1.5;
}

.root,
.level {
margin: 0;
padding: 0;
list-style: none;
}

/* Chapters start at the left edge; everything under them hangs off guide lines. */
.level {
margin-left: 0.35rem;
}

.level > .node {
position: relative;
padding-left: var(--tree-indent);
}

/* The vertical guide, running down past every sibling but the last. */
.level > .node::before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
border-left: 1px solid var(--tree-line);
}

/* The last sibling's guide stops at its own connector, drawing an elbow. */
.level > .node:last-child::before {
bottom: auto;
height: calc(var(--tree-elbow) + 0.15rem);
}

/* The horizontal connector into the node's line. */
.level > .node::after {
content: '';
position: absolute;
top: calc(var(--tree-elbow) + 0.15rem);
left: 0;
width: calc(var(--tree-indent) - 0.35rem);
border-top: 1px solid var(--tree-line);
}

.line {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 0.25rem var(--ui-space-2);
padding: 0.15rem 0;
overflow-wrap: anywhere;
}

.root > .node + .node {
margin-top: var(--ui-space-2);
}

.chapter {
font-weight: 700;
}

.question {
font-weight: 600;
}

.item {
color: var(--ui-text-muted);
font-style: italic;
}

.values {
display: inline-flex;
flex-wrap: wrap;
align-items: baseline;
gap: 0.25rem var(--ui-space-2);
min-width: 0;
}

.removed,
.added,
.answer {
padding: 0 0.25rem;
border-radius: var(--ui-radius-control);
white-space: pre-wrap;
}

.removed {
background: var(--ui-danger-subtle);
color: var(--ui-danger-on-subtle);
text-decoration: line-through;
}

.added {
background: var(--ui-success-subtle);
color: var(--ui-success-on-subtle);
text-decoration: none;
}

/* The answer an unchanged options question has, which its changed follow-up questions follow from. */
.answer {
background: var(--ui-surface-sunken);
color: var(--ui-text-muted);
}
Loading