Skip to content

Commit

Permalink
Merge pull request #40 from FRC2713/inlineEdit
Browse files Browse the repository at this point in the history
Multi Select and Auto Increment
  • Loading branch information
tytremblay authored Apr 2, 2024
2 parents 703fc62 + 47c0ef6 commit df5731c
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 33 deletions.
47 changes: 17 additions & 30 deletions config/2024/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"title": "Match Number",
"type": "number",
"required": true,
"code": "matchNumber"
"code": "matchNumber",
"preserveDataOnReset": true,
"autoIncrementOnReset": true
},
{
"title": "Robot",
Expand Down Expand Up @@ -59,29 +61,6 @@
{
"name": "Autonomous",
"fields": [
{
"title": "Mobility?",
"type": "boolean",
"defaultValue": false,
"required": false,
"code": "Mved"
},
{
"code": "auamp",
"title": "Amp Scored",
"type": "counter",
"defaultValue": 0,
"min": 0,
"required": false
},
{
"code": "auampm",
"title": "Amp Missed",
"type": "counter",
"defaultValue": 0,
"min": 0,
"required": false
},
{
"code": "ausc",
"title": "Speaker Scored",
Expand All @@ -99,12 +78,20 @@
"required": false
},
{
"code": "auf",
"title": "Auto Foul",
"type": "counter",
"defaultValue": 0,
"min": 0,
"required": false
"code": "a_gp_collect",
"title": "Game Pieces Collected",
"type": "select",
"multiSelect": true,
"choices": {
"1": "Preload",
"2": "Floor 1",
"3": "Floor 2",
"4": "Floor 3",
"5": "Floor 4",
"6": "Floor 5",
"7": "Floor 6",
"8": "Floor 7"
}
}
]
},
Expand Down
6 changes: 6 additions & 0 deletions config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
},
"max": {
"type": "number"
},
"multiSelect": {
"type": "boolean"
},
"autoIncrementOnReset": {
"type": "boolean"
}
},
"required": ["title", "type", "required", "code"],
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@headlessui/react": "^1.7.18",
"@heroicons/react": "^2.1.1",
"@monaco-editor/react": "^4.6.0",
"clsx": "^2.1.0",
"immer": "^10.0.3",
"lodash": "^4.17.21",
"next-themes": "^0.2.1",
Expand Down
1 change: 1 addition & 0 deletions src/components/inputs/BaseInputProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface InputProps {
defaultValue?: any;
min?: number;
max?: number;
autoIncrementOnReset?: boolean;
}

export type InputTypes =
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface NumberInputProps extends BaseInputProps {
export default function NumberInput(data: NumberInputProps) {
function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
e.preventDefault();
data.onChange(e.currentTarget.value);
data.onChange(Number(e.currentTarget.value));
}

return (
Expand Down
18 changes: 16 additions & 2 deletions src/components/inputs/SelectInput.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
import clsx from 'clsx';
import React from 'react';
import BaseInputProps from './BaseInputProps';

export interface SelectInputProps extends BaseInputProps {
options: Record<string, string>;
multiSelect?: boolean;
defaultValue: string;
}

export default function SelectInput(data: SelectInputProps) {
function handleSelect(evt: React.ChangeEvent<HTMLSelectElement>) {
data.onChange(evt.currentTarget.value);
evt.preventDefault();
if (!data.multiSelect) {
data.onChange(evt.currentTarget.value);
} else {
const selectedOptions = Array.from(evt.currentTarget.selectedOptions).map(
o => o.value,
);
data.onChange(selectedOptions);
}
}
return (
<select
className="w-full rounded bg-white px-4 py-2 dark:bg-gray-700 dark:text-white"
className={clsx(
'w-full rounded bg-white px-4 py-2 dark:bg-gray-700 dark:text-white ',
data.multiSelect && 'overflow-hidden',
)}
size={data.multiSelect ? Object.keys(data.options).length : 1}
name={data.title}
id={data.title}
onChange={handleSelect}
value={data.value}
multiple={data.multiSelect}
>
{Object.keys(data.options).map(o => {
return (
Expand Down
5 changes: 5 additions & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export function resetSections() {
.forEach(f => {
if (!f.preserveDataOnReset) {
f.value = f.defaultValue;
} else if (
(f.type === 'number' || f.type === 'counter') &&
f.autoIncrementOnReset
) {
f.value = f.value + 1;
}
}),
),
Expand Down

0 comments on commit df5731c

Please sign in to comment.