Skip to content

Commit

Permalink
Merge pull request #779 from remap-keys/fix-778
Browse files Browse the repository at this point in the history
Add a new property `comment` to describe each parameter.
  • Loading branch information
yoichiro authored Nov 24, 2023
2 parents cdd3339 + 58fb21e commit 7a58348
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 19 deletions.
48 changes: 30 additions & 18 deletions src/components/catalog/keyboard/build/BuildParametersDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,26 +330,37 @@ function ParameterEditors(props: ParameterEditorProps) {
event.target.value
);
}}
helperText={parameter.definition.comment}
/>
) : parameter.definition.type === 'select' ? (
<Select
fullWidth
size="small"
value={parameter.value}
onChange={(event) => {
props.onChangeParameterValue(
props.selectedFirmwareFile,
parameter.definition,
event.target.value
);
}}
>
{parameter.definition.options.map((option) => (
<MenuItem value={option} key={`parameter-option-${option}`}>
{option}
</MenuItem>
))}
</Select>
<div>
<Select
fullWidth
size="small"
value={parameter.value}
onChange={(event) => {
props.onChangeParameterValue(
props.selectedFirmwareFile,
parameter.definition,
event.target.value
);
}}
>
{parameter.definition.options.map((option) => (
<MenuItem
value={option}
key={`parameter-option-${option}`}
>
{option}
</MenuItem>
))}
</Select>
{parameter.definition.comment && (
<Typography variant="caption">
{parameter.definition.comment}
</Typography>
)}
</div>
) : parameter.definition.type === 'number' ? (
<TextField
fullWidth
Expand All @@ -364,6 +375,7 @@ function ParameterEditors(props: ParameterEditorProps) {
event.target.value
);
}}
helperText={parameter.definition.comment}
/>
) : null}
</Grid>
Expand Down
7 changes: 6 additions & 1 deletion src/components/documents/build/Build.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export default function Build() {
sx={{ mt: 2, ml: 2, fontFamily: 'monospace' }}
>
&lt;remap name=&quot;NAME&quot; type=&quot;TYPE&quot;
default=&quot;DEFAULT&quot; options=&quot;OPTIONS&quot; /&gt;
default=&quot;DEFAULT&quot; options=&quot;OPTIONS&quot;
comment=&quot;COMMENT&quot; /&gt;
</Typography>
</Paper>
<Typography variant="body1" gutterBottom={true}>
Expand All @@ -121,6 +122,10 @@ export default function Build() {
is &quot;select&quot;. The options are written with the
&apos;,&apos; character as a delimiter.
</li>
<li>
comment - The comment of the parameter. This is displayed under
each UI to describe the parameter. It is optional.
</li>
</ul>
</Typography>
<Typography variant="body1" gutterBottom={true}>
Expand Down
40 changes: 40 additions & 0 deletions src/services/build/FirmwareCodeParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,45 @@ describe('FirmwareCodeParser', () => {
},
]);
});

test('should extract parameters from source with comment', () => {
const source = `
<remap name="foo" type="select" default="baz" options="bar,baz" comment="comment1" />
<remap name="bar" type="text" default="john" comment="comment2" />
<remap name="baz" type="number" default="20" comment="comment3 foobar" />
`;

const parameters = extractBuildableFirmwareCodeParameters(source);

expect(parameters).toEqual([
{
name: 'foo',
type: 'select',
options: ['bar', 'baz'],
default: 'baz',
comment: 'comment1',
startPosition: 9,
endPosition: 94,
},
{
name: 'bar',
type: 'text',
options: [],
default: 'john',
comment: 'comment2',
startPosition: 103,
endPosition: 169,
},
{
name: 'baz',
type: 'number',
options: [],
default: '20',
comment: 'comment3 foobar',
startPosition: 178,
endPosition: 251,
},
]);
});
});
});
2 changes: 2 additions & 0 deletions src/services/build/FirmwareCodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const extractBuildableFirmwareCodeParameters = (
const type = extractAttribute(tagContent, 'type');
const options = extractAttribute(tagContent, 'options');
const defaultValue = extractAttribute(tagContent, 'default');
const comment = extractAttribute(tagContent, 'comment');

if (
!name ||
Expand All @@ -49,6 +50,7 @@ export const extractBuildableFirmwareCodeParameters = (
name,
type: type as 'select' | 'text' | 'number',
default: defaultValue,
comment,
options: [],
startPosition,
endPosition,
Expand Down
1 change: 1 addition & 0 deletions src/store/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export type IBuildableFirmwareCodeParameter = {
type: IBuildableFirmwareCodeParameterType;
options: string[];
default: string;
comment: string | undefined;
startPosition: number;
endPosition: number;
};
Expand Down

0 comments on commit 7a58348

Please sign in to comment.