Skip to content

Commit

Permalink
refactor: cleanup and fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Nov 6, 2024
1 parent 2022c83 commit c54fdc0
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/components/sectionedForm/SectionedFormLayout.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@value m-medium: (min-width: 768px);

/* The purpose of this wrappper is for the */
.layoutWrapper {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -31,15 +30,14 @@
background-color: #fff;
min-width: var(--sidebar-width);
height: 100%;
border-radius: 0;
border-inline-end: 1px solid var(--colors-grey300);
}

.footer {
grid-area: footer;
width: 100%;
background: var(--colors-white);
border-top: 1px solid var(--colors-grey300);
border-block-start: 1px solid var(--colors-grey300);
display: flex;
}

Expand Down
9 changes: 5 additions & 4 deletions src/lib/form/sectionedForm/SectionedFormContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { createContext, useState } from 'react'
import { SectionDescriptor, SectionedFormDescriptor } from './formDescriptor'
import { SectionDescriptor, SectionedFormDescriptor } from './types'

/* Some of the types in this file may look complex.
However they are here to help type-safety and autocommpletion for consumers.
Expand Down Expand Up @@ -50,6 +50,7 @@ function createContextValue<const T extends SectionedFormDescriptor>(
},
}
}

type SectionFormContextValue<T extends SectionedFormDescriptor> = ReturnType<
typeof createContextValue<T>
>
Expand All @@ -62,12 +63,12 @@ export const SectionedFormDescriptorProvider = <
T extends SectionedFormDescriptor
>({
children,
initialValue,
formDescriptor,
}: {
initialValue: T
formDescriptor: T
children: React.ReactNode
}) => {
const [contextValue] = useState(() => createContextValue(initialValue))
const [contextValue] = useState(() => createContextValue(formDescriptor))

return (
<SectionedFormContext.Provider value={contextValue}>
Expand Down
4 changes: 1 addition & 3 deletions src/lib/form/sectionedForm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ export type FieldDescriptor<T = unknown> = {
name: keyof T | (string & {})
}

export type SectionDescriptor<T> = {
export type SectionDescriptor<T = unknown> = {
label: string
name: string
// keyof T | (string & {}) allows auto-completion for fields, while also allowing
// any other string to be used as a key
fields: FieldDescriptor<T>[]
}

Expand Down
3 changes: 2 additions & 1 deletion src/pages/dataSets/New.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { initialValues, validate } from './form/dataSetFormSchema'
import { DataSetFormDescriptor } from './form/formDescriptor'

const section = SECTIONS_MAP.dataSet

export const Component = () => {
return (
<SectionedFormDescriptorProvider initialValue={DataSetFormDescriptor}>
<SectionedFormDescriptorProvider formDescriptor={DataSetFormDescriptor}>
<FormBase
onSubmit={useOnSubmitNew({ section })}
initialValues={initialValues}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataSets/form/DataSetFormContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
StandardFormField,
StandardFormSectionDescription,
StandardFormSectionTitle,
SectionedFormSectionRouter,
} from '../../../components'
import {
SectionedFormSection,
SectionedFormSections,
} from '../../../components/sectionedForm'
import { SectionedFormSectionRouter } from '../../../components/sectionedForm/SectionedFormSectionRouter'
import { SECTIONS_MAP, useSectionedFormDescriptor } from '../../../lib'
import { CategoryComboField } from '../../dataElements/fields'
import { DataSetFormDescriptor } from './formDescriptor'
Expand Down
6 changes: 1 addition & 5 deletions src/pages/dataSets/form/formDescriptor.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import i18n from '@dhis2/d2-i18n'
import {
createUseSelectedSection,
SectionedFormDescriptor,
useSelectedSection,
} from '../../../lib'
import { SectionedFormDescriptor } from '../../../lib'
import { DataSetFormValues } from './fieldFilters'

export const DataSetFormDescriptor = {
Expand Down

0 comments on commit c54fdc0

Please sign in to comment.