Skip to content

Commit

Permalink
Flatten forms-service (#159)
Browse files Browse the repository at this point in the history
* Add defaultChecked back to radio and checkbox patterns

* Move form-service into the forms package

* In-progress work on end-to-end test for marijuana pardon application form

* Comment out in-progress test

* Update lockfile

* Linting
  • Loading branch information
danielnaab authored Jun 5, 2024
1 parent 6616eb5 commit 0b502f6
Show file tree
Hide file tree
Showing 46 changed files with 99 additions and 127 deletions.
1 change: 0 additions & 1 deletion apps/doj-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@astrojs/node": "^8.2.3",
"@astrojs/react": "^3.0.9",
"@atj/design": "workspace:*",
"@atj/form-service": "workspace:*",
"@atj/forms": "workspace:*",
"astro": "^4.4.11",
"react": "^18.2.0",
Expand Down
12 changes: 4 additions & 8 deletions apps/doj-demo/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { FormConfig } from '@atj/forms';
import { defaultFormConfig } from '@atj/forms';
import {
type FormService,
createBrowserFormService,
createTestFormService,
} from '@atj/form-service';
import { service } from '@atj/forms';

export type AppContext = {
baseUrl: `${string}/`;
formConfig: FormConfig;
formService: FormService;
formService: service.FormService;
uswdsRoot: `${string}/`;
};

Expand All @@ -33,8 +29,8 @@ const createAppContext = (env: any): AppContext => {

const createAppFormService = () => {
if (globalThis.window) {
return createBrowserFormService();
return service.createBrowserFormService();
} else {
return createTestFormService();
return service.createTestFormService();
}
};
2 changes: 1 addition & 1 deletion apps/rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "tsup src/* --watch"
},
"dependencies": {
"@atj/form-service": "workspace:*"
"@atj/forms": "workspace:*"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.109",
Expand Down
1 change: 0 additions & 1 deletion apps/spotlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"dependencies": {
"@astrojs/react": "^3.0.9",
"@atj/design": "workspace:*",
"@atj/form-service": "workspace:*",
"@atj/forms": "workspace:*",
"astro": "^4.3.3",
"react": "^18.2.0",
Expand Down
12 changes: 4 additions & 8 deletions apps/spotlight/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { FormConfig } from '@atj/forms';
import { defaultFormConfig } from '@atj/forms';
import {
type FormService,
createBrowserFormService,
createTestFormService,
} from '@atj/form-service';
import { service } from '@atj/forms';

import { type GithubRepository } from './lib/github';

export type AppContext = {
baseUrl: `${string}/`;
github: GithubRepository;
formConfig: FormConfig;
formService: FormService;
formService: service.FormService;
uswdsRoot: `${string}/`;
};

Expand All @@ -37,8 +33,8 @@ const createAppContext = (env: any): AppContext => {

const createAppFormService = () => {
if (globalThis.window) {
return createBrowserFormService();
return service.createBrowserFormService();
} else {
return createTestFormService();
return service.createTestFormService();
}
};
1 change: 0 additions & 1 deletion packages/design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
},
"dependencies": {
"@atj/common": "workspace:*",
"@atj/form-service": "workspace:*",
"@atj/forms": "workspace:*",
"@dnd-kit/core": "^6.1.0",
"@dnd-kit/sortable": "^8.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import type { Meta, StoryObj } from '@storybook/react';

import AvailableFormList from '.';
import { createTestFormService } from '@atj/form-service';
import { service } from '@atj/forms';
import { createForm, nullSession } from '@atj/forms';
import { MemoryRouter } from 'react-router-dom';
import { FormManagerProvider } from '../FormManager/store';
import {
createTestFormManagerContext,
createTwoPatternTestForm,
} from '../test-form';
import { createTestFormManagerContext } from '../test-form';
import React from 'react';

const meta: Meta<typeof AvailableFormList> = {
title: 'FormManager/AvailableFormList',
component: AvailableFormList,
args: {
formService: createTestFormService({
formService: service.createTestFormService({
'form-1': createForm({
title: 'Form 1',
description: 'Use this form to...',
Expand All @@ -33,7 +30,6 @@ const meta: Meta<typeof AvailableFormList> = {
<MemoryRouter initialEntries={['/']}>
<FormManagerProvider
context={createTestFormManagerContext()}
form={createTwoPatternTestForm()}
session={nullSession}
>
<Story {...args} />
Expand All @@ -50,7 +46,7 @@ export const Empty = {
title: 'Empty form list',
component: AvailableFormList,
args: {
formService: createTestFormService({}),
formService: service.createTestFormService({}),
urlForForm: () => `#`,
urlForFormManager: () => `#`,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/design/src/AvailableFormList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { FormService } from '@atj/form-service';
import { service } from '@atj/forms';
import * as AppRoutes from '../FormManager/routes';
import { Link } from 'react-router-dom';

Expand All @@ -16,7 +16,7 @@ export default function AvailableFormList({
urlForForm,
urlForFormManager,
}: {
formService: FormService;
formService: service.FormService;
urlForForm: UrlForForm;
urlForFormManager: UrlForFormManager;
}) {
Expand Down
1 change: 1 addition & 0 deletions packages/design/src/Form/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const CheckboxPattern: PatternComponent<CheckboxProps> = props => {
id={props.id}
type="checkbox"
className="usa-checkbox__input"
defaultChecked={props.defaultChecked}
{...register(props.id)}
/>
<label className="usa-checkbox__label" htmlFor={props.id}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const RadioGroupPattern: PatternComponent<RadioGroupProps> = props => {
id={option.id}
{...register(props.groupId)}
value={option.id}
defaultChecked={option.defaultChecked}
/>
<label htmlFor={option.id} className="usa-radio__label">
{option.label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import type { Meta, StoryObj } from '@storybook/react';

import { createTestFormService } from '@atj/form-service';
import { service } from '@atj/forms';

import FormDelete from '.';
import { createTwoPatternTestForm } from '../../test-form';
Expand All @@ -19,7 +19,7 @@ const meta: Meta<typeof FormDelete> = {
],
args: {
formId: 'test-form',
formService: createTestFormService({
formService: service.createTestFormService({
'test-form': createTwoPatternTestForm(),
}),
},
Expand Down
4 changes: 2 additions & 2 deletions packages/design/src/FormManager/FormDelete/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import { useNavigate } from 'react-router-dom';

import type { FormService } from '@atj/form-service';
import { service } from '@atj/forms';

export default function FormDelete({
formId,
formService,
}: {
formId: string;
formService: FormService;
formService: service.FormService;
}) {
const navigate = useNavigate();
const result = formService.getForm(formId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
addDocumentFieldsToForm,
createFormSession,
} from '@atj/forms';
import { type FormService } from '@atj/form-service';
import { service } from '@atj/forms';

import Form, { FormUIContext } from '../../../Form';
import { onFileInputChangeGetFile } from '../../FormList/CreateNew/file-input';
Expand All @@ -24,7 +24,7 @@ const DocumentImporter = ({
formId: string;
context: FormUIContext;
form: Blueprint;
formService: FormService;
formService: service.FormService;
}) => {
const { state, actions } = useDocumentImporter(formService, form, baseUrl);

Expand Down Expand Up @@ -131,7 +131,7 @@ type State = {
};

const useDocumentImporter = (
formService: FormService,
formService: service.FormService,
form: Blueprint,
baseUrl: string
) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/design/src/FormManager/FormDocumentImport/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { type FormService } from '@atj/form-service';
import { service } from '@atj/forms';

import { type FormUIContext } from '../../Form';
import DocumentImporter from './DocumentImporter';
Expand All @@ -14,7 +14,7 @@ export const FormDocumentImport = ({
baseUrl: string;
context: FormUIContext;
formId: string;
formService: FormService;
formService: service.FormService;
}) => {
// Fallback to hardcoded data if a magic ID is chosen.
const result = formService.getForm(formId);
Expand Down
4 changes: 2 additions & 2 deletions packages/design/src/FormManager/FormList/FormList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import type { Meta, StoryObj } from '@storybook/react';

import { createTestFormService } from '@atj/form-service';
import { service } from '@atj/forms';

import FormList from '.';
import {
Expand All @@ -28,7 +28,7 @@ const meta: Meta<typeof FormList> = {
),
],
args: {
formService: createTestFormService({
formService: service.createTestFormService({
'test-form': createTwoPatternTestForm(),
}),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Link } from 'react-router-dom';

import { FormListItem } from '@atj/form-service/src/operations/get-form-list';
import { type FormListItem } from '@atj/forms/src/service/operations/get-form-list';

type ManageFormsTableProps = {
formListItems: FormListItem[];
Expand Down
4 changes: 2 additions & 2 deletions packages/design/src/FormManager/FormList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { FormService } from '@atj/form-service';
import { service } from '@atj/forms';

import CreateNew from './CreateNew';

export default function FormList({
formService,
}: {
formService: FormService;
formService: service.FormService;
}) {
const result = formService.getFormList();
if (!result.success) {
Expand Down
4 changes: 2 additions & 2 deletions packages/design/src/FormManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'react-router-dom';

import { type FormConfig, createFormSession, nullSession } from '@atj/forms';
import { FormService } from '@atj/form-service';
import { service } from '@atj/forms';

import { type ComponentForPattern } from '../Form';

Expand All @@ -32,7 +32,7 @@ export type FormManagerContext = {
components: ComponentForPattern;
config: FormConfig;
editComponents: EditComponentForPattern;
formService: FormService;
formService: service.FormService;
uswdsRoot: `${string}/`;
urlForForm: UrlForForm;
urlForFormManager: UrlForFormManager;
Expand Down
4 changes: 2 additions & 2 deletions packages/design/src/FormRouter/FormRouter.stories.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Meta, StoryObj } from '@storybook/react';

import { createTestFormService } from '@atj/form-service';
import { service } from '@atj/forms';

import FormRouter from '.';

export default {
title: 'Form',
component: FormRouter,
args: {
formService: createTestFormService(),
formService: service.createTestFormService(),
},
tags: ['autodocs'],
} satisfies Meta<typeof FormRouter>;
Expand Down
4 changes: 2 additions & 2 deletions packages/design/src/FormRouter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { useParams, HashRouter, Route, Routes } from 'react-router-dom';

import { type FormService } from '@atj/form-service';
import { service } from '@atj/forms';
import { createFormSession } from '@atj/forms';

import Form, { type FormUIContext } from '../Form';
Expand All @@ -13,7 +13,7 @@ export default function FormRouter({
formService,
}: {
context: FormUIContext;
formService: FormService;
formService: service.FormService;
}) {
return (
<HashRouter>
Expand Down
4 changes: 2 additions & 2 deletions packages/design/src/test-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@atj/forms';
import { type SequencePattern } from '@atj/forms/src/patterns/sequence';
import { type InputPattern } from '@atj/forms/src/patterns/input';
import { createTestFormService } from '@atj/form-service';
import { service } from '@atj/forms';

import { type FormUIContext } from './Form';
import { defaultPatternComponents } from './Form/components';
Expand Down Expand Up @@ -209,7 +209,7 @@ export const createTestFormManagerContext = (): FormManagerContext => {
components: defaultPatternComponents,
config: defaultFormConfig,
editComponents: defaultPatternEditComponents,
formService: createTestFormService(),
formService: service.createTestFormService(),
uswdsRoot: `/static/uswds/`,
urlForForm: mockGetUrl,
urlForFormManager: mockGetUrl,
Expand Down
1 change: 0 additions & 1 deletion packages/form-service/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions packages/form-service/README.md

This file was deleted.

17 changes: 0 additions & 17 deletions packages/form-service/package.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/form-service/tsconfig.json

This file was deleted.

5 changes: 0 additions & 5 deletions packages/form-service/vitest.config.ts

This file was deleted.

Loading

0 comments on commit 0b502f6

Please sign in to comment.