Skip to content

Commit

Permalink
Merge pull request #25 from FRC2713/preserveDataOnReset
Browse files Browse the repository at this point in the history
add preserveDataOnReset to each field
  • Loading branch information
tytremblay authored Feb 23, 2024
2 parents 2994874 + fae3d95 commit e335d89
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 32 deletions.
7 changes: 4 additions & 3 deletions config/2024/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"sections": [
{
"name": "Prematch",
"preserveDataOnReset": true,
"fields": [
{
"title": "Scouter Initials",
"type": "text",
"required": true,
"code": "scouter"
"code": "scouter",
"preserveDataOnReset": true
},
{
"title": "Match Number",
Expand All @@ -32,7 +32,8 @@
"B2": "Blue 2",
"B3": "Blue 3"
},
"defaultValue": "R1"
"defaultValue": "R1",
"preserveDataOnReset": true
},
{
"title": "Team Number",
Expand Down
4 changes: 4 additions & 0 deletions config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"disabled": {
"type": "boolean"
},
"preserveDataOnReset": {
"type": "boolean",
"description": "If true, field data will not be cleared when the scouting form is reset."
},
"value": {},
"choices": {
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion src/components/QR/CloseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type CloseButtonProps = {
export function CloseButton(props: CloseButtonProps) {
return (
<button
className="focus:shadow-outline rounded-full text-gray-800 absolute top-0 right-0 m-2 p-2 hover:bg-gray-200 "
className="focus:shadow-outline rounded-full text-gray-500 absolute top-0 right-0 m-2 p-2 hover:text-gray-800 "
type="button"
onClick={props.onClick}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/QR/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function CopyButton(props: CopyButtonProps) {
return (
<div onClick={props.onCopy} className={props.className}>
<svg
className="text-gray-500 hover:text-gray-800 "
className="text-gray-400 hover:text-gray-800 "
width="24"
height="24"
viewBox="0 0 24 24"
Expand Down
6 changes: 3 additions & 3 deletions src/components/QR/PreviewText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export type PreviewTextProps = {
export function PreviewText(props: PreviewTextProps) {
const chunks = props.data.split('\t');
return (
<div className="flex flex-col items-end gap-2">
<div className="text-left p-2 bg-gray-100 rounded-md shadow-md dark:bg-gray-600 mt-2">
<p className=" font-mono text-wrap break-all text-gray-800 dark:text-gray-200">
<div className="flex flex-col items-center gap-2 shadow-md bg-gray-600 m-2 p-2 rounded-md">
<div className="text-justify p-2 rounded bg-gray-600 ">
<p className=" font-mono text-wrap break-all text-gray-200 ">
{chunks.map((c, i) => (
<>
<span key={i + c}>{c}</span>
Expand Down
7 changes: 3 additions & 4 deletions src/components/QR/QRModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ export function QRModal(props: QRModalProps) {
/>
<div
ref={modalRef}
className="fixed top-20 rounded-md bg-white border p-5 shadow-lg w-96"
className="fixed top-20 rounded-md bg-white border shadow-lg w-96"
>
<div className="flex flex-col items-center ">
<h1 className="text-4xl text-black font-mono ">{title}</h1>
<div className="flex flex-col items-center pt-8 ">
<CloseButton onClick={props.onDismiss} />
<QRCode className="m-2 mt-4" size={256} value={qrCodeData} />
<div className="h-1 w-full border-t border-gray-800 my-2" />
<h1 className="text-3xl text-gray-800 font-rhr-ns ">{title}</h1>
<PreviewText data={qrCodeData} />
</div>
</div>
Expand Down
39 changes: 20 additions & 19 deletions src/components/inputs/BaseInputProps.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
export default interface BaseInputProps extends InputProps {
section: string
onChange: (value: any) => void
section: string;
onChange: (value: any) => void;
}
export interface Config {
title: string
page_title: string
sections: SectionProps[]
title: string;
page_title: string;
sections: SectionProps[];
}

export interface SectionProps {
name: string
preserveDataOnReset?: boolean
fields: InputProps[]
name: string;
preserveDataOnReset?: boolean;
fields: InputProps[];
}

export interface InputProps {
title: string
type: InputTypes
required: boolean
title: string;
type: InputTypes;
required: boolean;
// A shorthand code for this input
code: string
disabled?: boolean
value?: any
choices?: Record<string, string>
defaultValue?: any
min?: number
max?: number
code: string;
disabled?: boolean;
preserveDataOnReset?: boolean;
value?: any;
choices?: Record<string, string>;
defaultValue?: any;
min?: number;
max?: number;
}

export type InputTypes =
Expand All @@ -35,4 +36,4 @@ export type InputTypes =
| 'range'
| 'select'
| 'counter'
| 'image'
| 'image';
4 changes: 3 additions & 1 deletion src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export function resetSections() {
.map(s => s.fields)
.flat()
.forEach(f => {
f.value = f.defaultValue;
if (!f.preserveDataOnReset) {
f.value = f.defaultValue;
}
}),
),
);
Expand Down

0 comments on commit e335d89

Please sign in to comment.