Skip to content

Commit

Permalink
Initial demo flow improvements (#39)
Browse files Browse the repository at this point in the history
* Fix Form -> FormDefinition name mismatch

* Add ActionBar component and wire to prompts.

* Move FormManager/prompts into Form/PromptSegment.

* Simplify "create new form" workflow by initiating it via a PDF upload/extract operation.

* Cleaned up routing and navigation; added menu component.

* Add test and story modules for PDFFileSelect.

* Add available form list, so we have a separate entrypoint to the public/SRL version of forms.

* Wrap UI components with appropriate formService for client/service/test environments. This commit also fixes bugs that were identified through testing the UI with the complete workflow of pdf ingest, form save, form submit, download pdf.

* Add uswds import back into design package

* Add a debug tool to help clear local storage when it is incompatible with the current version.
  • Loading branch information
danielnaab authored Feb 2, 2024
1 parent c0997fd commit c61e56f
Show file tree
Hide file tree
Showing 69 changed files with 809 additions and 279 deletions.
1 change: 1 addition & 0 deletions apps/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"outDir": "./dist",
"emitDeclarationOnly": true
},
Expand Down
1 change: 1 addition & 0 deletions apps/spotlight/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const githubRepository = await getGithubRepository(process.env);

// https://astro.build/config
export default defineConfig({
trailingSlash: 'always',
base: addTrailingSlash(process.env.BASEURL || ''),
integrations: [
react({
Expand Down
3 changes: 2 additions & 1 deletion apps/spotlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"astro": "^3.5.4",
"cheerio": "1.0.0-rc.12",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.12"
},
"devDependencies": {
"@astrojs/check": "^0.3.1",
Expand Down
26 changes: 26 additions & 0 deletions apps/spotlight/src/components/AppAvailableFormList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { ErrorBoundary } from 'react-error-boundary';

import { AvailableFormList } from '@atj/design';
import { getAppContext } from '../context';
import { getFormUrl } from '../routes';
import DebugTools from './DebugTools';

export default () => {
const ctx = getAppContext();
return (
<ErrorBoundary
fallback={
<div>
There was an unexpected error rendering the form list.
<DebugTools />
</div>
}
>
<AvailableFormList
formService={ctx.formService}
urlForForm={getFormUrl}
/>
</ErrorBoundary>
);
};
9 changes: 9 additions & 0 deletions apps/spotlight/src/components/AppFormManager.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

import { FormManager } from '@atj/design';
import { getAppContext } from '../context';

export default function () {
const ctx = getAppContext();
return <FormManager formService={ctx.formService} baseUrl={ctx.baseUrl} />;
}
9 changes: 9 additions & 0 deletions apps/spotlight/src/components/AppFormRouter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

import { FormRouter } from '@atj/design';
import { getAppContext } from '../context';

export default function AppFormRouter() {
const ctx = getAppContext();
return <FormRouter formService={ctx.formService} />;
}
18 changes: 18 additions & 0 deletions apps/spotlight/src/components/DebugTools.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

export default function DebugTools() {
return (
<section>
<button
className="usa-button"
onClick={() => {
console.log('clearing');
window.localStorage.clear();
window.location.reload();
}}
>
Delete all demo data (clear browser local storage)
</button>
</section>
);
}
54 changes: 53 additions & 1 deletion apps/spotlight/src/components/Header.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
---
import closeSvg from '@atj/design/static/uswds/images/usa-icons/close.svg';
import closeSvg from '@atj/design/static/uswds/img/usa-icons/close.svg';
import * as routes from '../routes';
const getNavLinkClasses = (url: string) => {
if (url === Astro.url.pathname) {
return 'usa-nav-link usa-current';
} else {
return 'usa-nav-link';
}
};
---

<header class="usa-header usa-header--basic usa-header--megamenu"></header>
<div class="usa-overlay"></div>
<header class="usa-header usa-header--basic">
<div class="usa-nav-container">
<div class="usa-navbar">
<div class="usa-logo">
<em class="usa-logo__text">
<a href={routes.getHomeUrl()} title="10x Access to Justice">
10x Access to Justice
</a>
</em>
</div>
<button type="button" class="usa-menu-btn">Menu</button>
</div>
<nav aria-label="Primary navigation" class="usa-nav">
<button type="button" class="usa-nav__close">
<img src={closeSvg.src} role="img" alt="Close" />
</button>
<ul class="usa-nav__primary usa-accordion">
<li class="usa-nav__primary-item">
<a
href={routes.getHomeUrl()}
class={getNavLinkClasses(routes.getHomeUrl())}><span>Home</span></a
>
</li>
<li class="usa-nav__primary-item">
<a
href={routes.getManageUrl()}
class={getNavLinkClasses(routes.getManageUrl())}
><span>Manage forms</span></a
>
</li>
<li class="usa-nav__primary-item">
<a
href={routes.getStorybookUrl()}
class={getNavLinkClasses(routes.getStorybookUrl())}
><span>Storybook</span></a
>
</li>
</ul>
</nav>
</div>
</header>
17 changes: 16 additions & 1 deletion apps/spotlight/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import {
type FormService,
createBrowserFormService,
createTestFormService,
} from '@atj/form-service';
import { type GithubRepository } from './lib/github';

export type AppContext = {
baseUrl: `${string}/`;
github: GithubRepository;
formService: FormService;
};

let _context: AppContext | null = null;

export const getAppContext = (): AppContext => {
if (_context === null) {
_context = createAppContext((import.meta as any).env);
_context = createAppContext(import.meta.env);
}
return _context;
};
Expand All @@ -18,5 +24,14 @@ const createAppContext = (env: any) => {
return {
github: env.GITHUB,
baseUrl: env.BASE_URL,
formService: createAppFormService(),
};
};

const createAppFormService = () => {
if (globalThis.window) {
return createBrowserFormService();
} else {
return createTestFormService();
}
};
4 changes: 3 additions & 1 deletion apps/spotlight/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import '../styles.css';
import UsaBanner from '../components/UsaBanner.astro';
import { getAppContext } from '../context';
import Footer from '../components/Footer.astro';
import Header from '../components/Header.astro';
import { getAppContext } from '../context';
interface Props {
title: string;
Expand Down Expand Up @@ -49,6 +50,7 @@ const context = getAppContext();
</head>
<body>
<UsaBanner />
<Header />
<slot />
<Footer github={context.github} />
</body>
Expand Down
6 changes: 0 additions & 6 deletions apps/spotlight/src/lib/routes.ts

This file was deleted.

49 changes: 0 additions & 49 deletions apps/spotlight/src/pages/form-sample.astro

This file was deleted.

4 changes: 2 additions & 2 deletions apps/spotlight/src/pages/forms/index.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
import { FormManager } from '@atj/design';
import AppFormRouter from '../../components/AppFormRouter';
import ContentLayout from '../../layouts/ContentLayout.astro';
---

<ContentLayout title="10x Access to Justice Spotlight">
<FormManager client:only />
<AppFormRouter client:only />
</ContentLayout>
27 changes: 4 additions & 23 deletions apps/spotlight/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
---
import { DocumentAssembler } from '@atj/design/src/experiments/document-assembler';
import ContentLayout from '../layouts/ContentLayout.astro';
import AppAvailableFormList from '../components/AppAvailableFormList';
import DebugTools from '../components/DebugTools';
---

<ContentLayout title="10x Access to Justice Spotlight">
<h1>10x Access to Justice Spotlight</h1>
<ul>
<li>
<a href={`${import.meta.env.BASE_URL}design/index.html`}
>View frontend workshop</a
>
</li>
<li>
<a href={`${import.meta.env.BASE_URL}forms`}>Manage my forms</a>
</li>
<li>
<a href={`${import.meta.env.BASE_URL}form-sample`}>Sample form</a>
</li>
<li>
<a href={`${import.meta.env.BASE_URL}ud105-evicition-form`}
>UD 105 - Unlawful Detainment Eviction Form</a
>
</li>
<li>
<a href={`${import.meta.env.BASE_URL}forms/import-pdf`}>Import PDF</a>
</li>
</ul>
<DocumentAssembler client:load />
<AppAvailableFormList client:only />
<DebugTools client:only />
</ContentLayout>
8 changes: 8 additions & 0 deletions apps/spotlight/src/pages/manage/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
import AppFormManager from '../../components/AppFormManager';
import ContentLayout from '../../layouts/ContentLayout.astro';
---

<ContentLayout title="10x Access to Justice Spotlight">
<AppFormManager client:only />
</ContentLayout>
10 changes: 0 additions & 10 deletions apps/spotlight/src/pages/ud105-evicition-form.astro

This file was deleted.

21 changes: 21 additions & 0 deletions apps/spotlight/src/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getAppContext } from './context';

export const getFormUrl = (formId: string) => {
const context = getAppContext();
return `${context.baseUrl}forms/#${formId}`;
};

export const getManageUrl = () => {
const context = getAppContext();
return `${context.baseUrl}manage/`;
};

export const getHomeUrl = () => {
const context = getAppContext();
return context.baseUrl;
};

export const getStorybookUrl = () => {
const context = getAppContext();
return `${context.baseUrl}design/index.html`;
};
1 change: 1 addition & 0 deletions apps/spotlight/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// https://github.com/withastro/astro/blob/main/packages/astro/tsconfigs/base.json
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"noEmit": true,
"jsx": "react",
"resolveJsonModule": true
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"build": "turbo run build",
"clean": "turbo run clean",
"dev": "turbo run dev",
"dev": "turbo run dev --concurrency 12",
"format": "prettier --write \"packages/**/*.{js,jsx,ts,tsx}\"",
"lint": "turbo run lint",
"pages": "rm -rf node_modules && npm i -g pnpm turbo && pnpm i && pnpm build && ln -sf ./apps/spotlight/dist _site",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Meta, StoryObj } from '@storybook/react';

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

export default {
title: 'AvailableFormList',
component: AvailableFormList,
args: {
formService: createTestFormService({
'form-1': createForm({
title: 'Form 1',
description: 'Use this form to...',
}),
'form-2': createForm({
title: 'Form 2',
description: 'Use this form to...',
}),
}),
urlForForm: () => `#`,
},
tags: ['autodocs'],
} satisfies Meta<typeof AvailableFormList>;

export const AvailableFormListDemo = {} satisfies StoryObj<
typeof AvailableFormList
>;
Loading

0 comments on commit c61e56f

Please sign in to comment.