Skip to content

Commit

Permalink
refactor: clean up old files tckt-310
Browse files Browse the repository at this point in the history
  • Loading branch information
kalasgarov committed Jan 10, 2025
1 parent 16072a2 commit d2a2581
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 63 deletions.
3 changes: 0 additions & 3 deletions apps/spotlight/src/components/SplashPage.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const PhoneNumberPattern: PatternComponent<PhoneNumberProps> = ({
})}
htmlFor={phoneId}
>
{label || 'Phone Number'}
{label}
{required && <span className="required-indicator">*</span>}
</label>
{hint && (
Expand Down
6 changes: 2 additions & 4 deletions packages/design/src/Form/components/RadioGroup/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ export const RadioGroupPattern: PatternComponent<RadioGroupProps> = props => {
{props.legend}
</legend>
{props.options.map((option, index) => {
const id = props.idSuffix ? `${option.id}${props.idSuffix}` : option.id;
const id = option.id;
return (
<div key={index} className="usa-radio">
<input
className="usa-radio__input"
type="radio"
id={`input-${id}`}
{...register(
`${props.groupId}${props.idSuffix ? props.idSuffix : ''}`
)}
{...register(`${props.groupId}`)}
value={option.id}
defaultChecked={option.defaultChecked}
/>
Expand Down
4 changes: 1 addition & 3 deletions packages/design/src/Form/components/TextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { type PatternComponent } from '../../../Form/index.js';

const TextInput: PatternComponent<TextInputProps> = props => {
const { register } = useFormContext();
const id = props.idSuffix
? `${props.inputId}${props.idSuffix}`
: props.inputId;
const id = props.inputId;
return (
<div className="usa-form-group-wrapper" key={props.inputId}>
<div
Expand Down
3 changes: 0 additions & 3 deletions packages/forms/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export type PackageDownloadProps = PatternProps<{
export type TextInputProps = PatternProps<{
type: 'input';
inputId: string;
idSuffix?: string;
value: string;
label: string;
required: boolean;
Expand Down Expand Up @@ -75,7 +74,6 @@ export type ZipcodeProps = PatternProps<{
export type CheckboxProps = PatternProps<{
type: 'checkbox';
id: string;
idSuffix?: string;
label: string;
defaultChecked: boolean;
}>;
Expand All @@ -95,7 +93,6 @@ export type RadioGroupProps = PatternProps<{
type: 'radio-group';
groupId: string;
legend: string;
idSuffix?: string;
options: {
id: string;
name: string;
Expand Down
6 changes: 1 addition & 5 deletions packages/forms/src/documents/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@ export const addDocumentFieldsToForm = (
maxLength: 128,
},
} satisfies InputPattern);
} else if (
field.type === 'Paragraph' ||
field.type === 'RichText' ||
field.type === 'Repeater'
) {
} else if (field.type === 'Paragraph' || field.type === 'RichText') {
// skip purely presentational fields
} else if (field.type === 'not-supported') {
console.error(`Skipping field: ${field.error}`);
Expand Down
6 changes: 1 addition & 5 deletions packages/forms/src/documents/pdf/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ const setFormFieldData = (
field.uncheck();
}
}
} else if (
fieldType === 'Paragraph' ||
fieldType === 'RichText' ||
fieldType === 'Repeater'
) {
} else if (fieldType === 'Paragraph' || fieldType === 'RichText') {
// do nothing
} else {
const exhaustiveCheck: never = fieldType;
Expand Down
1 change: 0 additions & 1 deletion packages/forms/src/documents/pdf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export type PDFFieldType =
| 'OptionList'
| 'RadioGroup'
| 'Paragraph'
| 'Repeater'
| 'RichText';

export type ParsePdf = (
Expand Down
19 changes: 1 addition & 18 deletions packages/forms/src/documents/pdf/parsing-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { type ParagraphPattern } from '../../patterns/paragraph.js';
import { type CheckboxPattern } from '../../patterns/checkbox.js';
import { type RadioGroupPattern } from '../../patterns/radio-group.js';
import { RichTextPattern } from '../../patterns/rich-text.js';
import { type RepeaterPattern } from '../../patterns/repeater/index.js';

import { uint8ArrayToBase64 } from '../../util/base64.js';
import { type DocumentFieldMap } from '../types.js';
Expand Down Expand Up @@ -80,26 +79,11 @@ const Fieldset = z.object({
page: z.union([z.number(), z.string()]),
});

const Repeater = z.object({
component_type: z.literal('repeater'),
legend: z.string(),
fields: z.union([TxInput, Checkbox]).array(),
page: z.union([z.number(), z.string()]),
});

const ExtractedObject = z.object({
raw_text: z.string(),
form_summary: FormSummary,
elements: z
.union([
TxInput,
Checkbox,
RadioGroup,
Paragraph,
Fieldset,
RichText,
Repeater,
])
.union([TxInput, Checkbox, RadioGroup, Paragraph, Fieldset, RichText])
.array(),
});

Expand Down Expand Up @@ -173,7 +157,6 @@ export const processApiResponse = async (json: any): Promise<ParsedPdf> => {

for (const element of extracted.elements) {
const fieldsetPatterns: PatternId[] = [];

// Add paragraph elements
if (element.component_type === 'paragraph') {
const paragraph = processPatternData<ParagraphPattern>(
Expand Down
8 changes: 0 additions & 8 deletions packages/forms/src/documents/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ export type DocumentFieldValue =
value: string;
required: boolean;
}
| {
type: 'Repeater';
name: string;
options: string[];
label: string;
value: string;
required: boolean;
}
| {
type: 'RichText';
name: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/forms/src/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const setNestedValue = (
}, obj);
};

const aggregateValuesByPrefix = (
export const aggregateValuesByPrefix = (
values: Record<string, any>
): Record<string, any> => {
const aggregatedValues: Record<string, any> = {};
Expand Down Expand Up @@ -204,7 +204,7 @@ export const aggregatePatternSessionValues = (
if (patternConfig.parseUserInput) {
const isRepeaterType = pattern.type === 'repeater';
const patternValues = aggregatedValues[pattern.id];
let parseResult: any = patternConfig.parseUserInput(
const parseResult: any = patternConfig.parseUserInput(
pattern,
patternValues,
config,
Expand Down
6 changes: 0 additions & 6 deletions packages/forms/src/patterns/input/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export const createPrompt: CreatePrompt<InputPattern> = (
}
}

console.group('input/createprompt');
console.log(session);
console.log(options);
console.log(pattern);
console.groupEnd();

return {
props: {
_patternId: pattern.id,
Expand Down
4 changes: 0 additions & 4 deletions packages/forms/src/patterns/input/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,5 @@ export const parseUserInput: ParseUserInput<
InputPattern,
InputPatternOutput
> = (pattern, obj) => {
console.group('parseUserInput');
console.log(pattern);
console.log(obj);
console.groupEnd();
return safeZodParseToFormError(createSchema(pattern['data']), obj);
};
2 changes: 2 additions & 0 deletions packages/forms/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
type PatternId,
type PatternValue,
type PatternValueMap,
aggregatePatternSessionValues,
aggregateValuesByPrefix,
getPatternConfig,
validatePattern,
} from './pattern.js';
Expand Down

0 comments on commit d2a2581

Please sign in to comment.