Repository navigation
feat(app): SLO objective, details and editing in the builder #3804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import SloEditorPage from '@/components/Slos/SloEditorPage'; | ||
|
|
||
| export default SloEditorPage; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { useEffect, useRef } from 'react'; | ||
| import dynamic from 'next/dynamic'; | ||
| import Head from 'next/head'; | ||
| import Link from 'next/link'; | ||
|
|
@@ -21,38 +22,57 @@ import { usePageTitle } from '@/brand'; | |
| import { InlineNameInputControlled } from '@/components/InlineNameInput/InlineNameInput'; | ||
| import { PageHeader } from '@/components/PageHeader'; | ||
| import { withAppNavForSurface } from '@/layout'; | ||
| import { useSaveSlo, useSlosEnabledGuard } from '@/slo'; | ||
| import { useSaveSlo, useSlo, useSlosEnabledGuard } from '@/slo'; | ||
| import { useSource } from '@/source'; | ||
| import { getApiErrorMessage } from '@/utils/apiErrors'; | ||
|
|
||
| import { SloIndicatorFields } from './SloDefinitionFields'; | ||
| import { | ||
| SloDetailsFields, | ||
| SloIndicatorFields, | ||
| SloObjectiveFields, | ||
| } from './SloDefinitionFields'; | ||
| import { | ||
| DEFAULT_SLO_FORM_VALUES, | ||
| sloFormResolver, | ||
| type SloFormValues, | ||
| sloToFormValues, | ||
| toSloInput, | ||
| } from './sloForm'; | ||
| import { SloFormSection } from './SloFormLayout'; | ||
|
|
||
| function SloEditorPage() { | ||
| const enabled = useSlosEnabledGuard(); | ||
| const router = useRouter(); | ||
| const title = usePageTitle('New SLO'); | ||
| const editId = | ||
| typeof router.query.sloId === 'string' ? router.query.sloId : undefined; | ||
| const { data: existing } = useSlo(editId); | ||
| const title = usePageTitle(editId ? 'Edit SLO' : 'New SLO'); | ||
|
|
||
| const { control, handleSubmit, setValue, getValues } = useForm<SloFormValues>( | ||
| { | ||
| const { control, handleSubmit, reset, setValue, getValues } = | ||
| useForm<SloFormValues>({ | ||
| defaultValues: DEFAULT_SLO_FORM_VALUES, | ||
| resolver: sloFormResolver, | ||
| }, | ||
| ); | ||
| }); | ||
| const { errors } = useFormState({ control, name: 'name' }); | ||
| const sourceId = useWatch({ control, name: 'source' }); | ||
| const { data: source } = useSource({ id: sourceId || undefined }); | ||
|
|
||
| // Load the SLO being edited, once. | ||
| const initializedRef = useRef(false); | ||
| useEffect(() => { | ||
| if (initializedRef.current || !router.isReady) return; | ||
| if (editId) { | ||
| if (!existing) return; | ||
| reset(sloToFormValues(existing)); | ||
| } | ||
| initializedRef.current = true; | ||
| }, [router.isReady, editId, existing, reset]); | ||
|
|
||
| const save = useSaveSlo(); | ||
| const onSave = handleSubmit(async values => { | ||
| try { | ||
| const saved = await save.mutateAsync({ | ||
| id: editId, | ||
| slo: toSloInput(values, source), | ||
| }); | ||
| notifications.show({ color: 'green', message: `Saved ${saved.name}` }); | ||
|
|
@@ -79,6 +99,16 @@ function SloEditorPage() { | |
| <Anchor component={Link} href="/slos" fz="sm" c="dimmed"> | ||
| SLOs | ||
| </Anchor> | ||
| {editId && existing && ( | ||
| <Anchor | ||
| component={Link} | ||
| href={`/slos/${editId}`} | ||
| fz="sm" | ||
| c="dimmed" | ||
| > | ||
| {existing.name} | ||
| </Anchor> | ||
| )} | ||
| </Breadcrumbs> | ||
| } | ||
| > | ||
|
|
@@ -102,7 +132,11 @@ function SloEditorPage() { | |
| )} | ||
| </Box> | ||
| <Group gap="xs" wrap="nowrap"> | ||
| <Button component={Link} href="/slos" variant="secondary"> | ||
| <Button | ||
| component={Link} | ||
| href={editId ? `/slos/${editId}` : '/slos'} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 — In edit mode, Cancel and the SLO-name breadcrumb link to /slos/, which has no page in this PR At this commit Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond |
||
| variant="secondary" | ||
| > | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
|
|
@@ -111,7 +145,7 @@ function SloEditorPage() { | |
| loading={save.isPending} | ||
| data-testid="slo-save" | ||
| > | ||
| Create SLO | ||
| {editId ? 'Save SLO' : 'Create SLO'} | ||
| </Button> | ||
| </Group> | ||
| </Flex> | ||
|
|
@@ -132,6 +166,12 @@ function SloEditorPage() { | |
| source={source} | ||
| /> | ||
| </SloFormSection> | ||
| <SloFormSection title="Objective"> | ||
| <SloObjectiveFields control={control} setValue={setValue} /> | ||
| </SloFormSection> | ||
| <SloFormSection title="Details"> | ||
| <SloDetailsFields control={control} /> | ||
| </SloFormSection> | ||
| </Stack> | ||
| </Grid.Col> | ||
| </Grid> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 P2 — Edit page shows an editable default form while loading, then overwrites any input; a failed fetch leaves a blank 'Save SLO' form
useSlois read only fordata, so while it loads the page shows the defaults (Untitled SLO, 99.9%, 30d) as an editable form. Anything typed before the response arrives is thrown away byreset(sloToFormValues(existing)). If the fetch fails (for example a 404 for a deleted id), the page stays on the empty form forever and Save PUTs to a missing id. Show a loader untilexistingis loaded, and an error or not-found state (usingEmptyState) whenisError.Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond