Skip to content
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

Support customizable content types #44

Merged
merged 5 commits into from
Feb 13, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ coverage/
html/
node_modules/
NOTES.md
tsconfig.tsbuildinfo
14 changes: 12 additions & 2 deletions apps/spotlight/src/components/AppFormManager.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import React from 'react';

import { FormManager } from '@atj/design';
import { FormManager, defaultFormElementComponent } from '@atj/design';

import { getAppContext } from '../context';

export default function () {
const ctx = getAppContext();
return <FormManager formService={ctx.formService} baseUrl={ctx.baseUrl} />;
return (
<FormManager
context={{
config: ctx.formConfig,
components: defaultFormElementComponent,
}}
formService={ctx.formService}
baseUrl={ctx.baseUrl}
/>
);
}
2 changes: 1 addition & 1 deletion apps/spotlight/src/components/AppFormRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import { getAppContext } from '../context';

export default function AppFormRouter() {
const ctx = getAppContext();
return <FormRouter formService={ctx.formService} />;
return <FormRouter config={ctx.formConfig} formService={ctx.formService} />;
}
17 changes: 3 additions & 14 deletions apps/spotlight/src/components/Footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,14 @@ const { github } = Astro.props;
<nav class="usa-footer__nav" aria-label="Footer navigation,">
<ul class="grid-row grid-gap">
<li
class="
mobile-lg:grid-col-6
desktop:grid-col-auto
usa-footer__primary-content
"
class="mobile-lg:grid-col-6 desktop:grid-col-auto usa-footer__primary-content"
>
<a
class="usa-footer__primary-link"
href="https://10x.gsa.gov/"
>
<a class="usa-footer__primary-link" href="https://10x.gsa.gov/">
10x
</a>
</li>
<li
class="
mobile-lg:grid-col-6
desktop:grid-col-auto
usa-footer__primary-content
"
class="mobile-lg:grid-col-6 desktop:grid-col-auto usa-footer__primary-content"
>
<a
class="usa-footer__primary-link"
Expand Down
5 changes: 5 additions & 0 deletions apps/spotlight/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { FormConfig } from '@atj/forms';
import { defaultFormConfig } from '@atj/forms';
import {
type FormService,
createBrowserFormService,
createTestFormService,
} from '@atj/form-service';

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

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

Expand All @@ -24,6 +28,7 @@ const createAppContext = (env: any) => {
return {
github: env.GITHUB,
baseUrl: env.BASE_URL,
formConfig: defaultFormConfig,
formService: createAppFormService(),
};
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"devDependencies": {
"@types/node": "^20.11.16",
"@vitest/coverage-c8": "^0.33.0",
"@vitest/coverage-v8": "^1.2.2",
"@vitest/ui": "^1.2.2",
"eslint": "^8.56.0",
Expand Down
62 changes: 29 additions & 33 deletions packages/design/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
env: {
browser: true,
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
],
overrides: [
{
env: {
node: true,
},
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
sourceType: 'script',
},
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
],
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"react"
],
"rules": {
}
}
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['@typescript-eslint', 'react'],
rules: {
'react/prop-types': 'off',
},
};
3 changes: 2 additions & 1 deletion packages/design/src/Form/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';

import Form from '.';
import { createTestForm } from '../test-form';
import { createTestForm, createTestFormConfig } from '../test-form';

export default {
title: 'Form',
component: Form,
decorators: [(Story, args) => <Story {...args} />],
args: {
config: createTestFormConfig(),
form: createTestForm(),
},
tags: ['autodocs'],
Expand Down
5 changes: 4 additions & 1 deletion packages/design/src/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ import { FormProvider, useForm } from 'react-hook-form';
import {
createFormSession,
createPrompt,
type FormConfig,
type FormDefinition,
} from '@atj/forms';

import PromptSegment from './PromptSegment';
import ActionBar from './ActionBar';

export default function Form({
config,
form,
onSubmit,
}: {
config: FormConfig;
form: FormDefinition;
onSubmit?: (data: Record<string, string>) => void;
}) {
const session = createFormSession(form);
const prompt = createPrompt(session);
const prompt = createPrompt(config, session);

const formMethods = useForm<Record<string, string>>({});
return (
Expand Down
9 changes: 8 additions & 1 deletion packages/design/src/FormManager/DocumentImporter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ import { useNavigate } from 'react-router-dom';

import { addDocument, addDocumentFieldsToForm } from '@atj/documents';
import { type FormService } from '@atj/form-service';
import { type DocumentFieldMap, type FormDefinition } from '@atj/forms';
import {
type FormConfig,
type DocumentFieldMap,
type FormDefinition,
} from '@atj/forms';

import { onFileInputChangeGetFile } from '../FormList/PDFFileSelect/file-input';
import Form from '../../Form';

const DocumentImporter = ({
baseUrl,
formId,
config,
form,
formService,
}: {
baseUrl: string;
formId: string;
config: FormConfig;
form: FormDefinition;
formService: FormService;
}) => {
Expand Down Expand Up @@ -146,6 +152,7 @@ const DocumentImporter = ({
return (
<>
<Form
config={config}
form={previewForm}
onSubmit={data => {
//handleFormSubmission(formId, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Meta, StoryObj } from '@storybook/react';
import { createTestFormService } from '@atj/form-service';

import FormEdit from '.';
import { createTestForm } from '../../test-form';
import { createTestForm, createTestFormContext } from '../../test-form';

export default {
title: 'FormManager/FormEdit',
Expand All @@ -18,6 +18,7 @@ export default {
),
],
args: {
context: createTestFormContext(),
formId: 'test-form',
formService: createTestFormService({
'test-form': createTestForm(),
Expand Down

This file was deleted.

Loading
Loading