Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit fa4687f

Browse files
feat(gui): show default value from code and documentation in selection view (#947)
* The default value of the code and the default value of the documentation will be showed, now. * style: apply automatic fixes of linters * Missing values are replaced by their corresponding messages. * style: apply automatic fixes of linters * fix(gui): clone method of parameter * fix(gui): merge two paragraphs Co-authored-by: Lars Reimann <[email protected]> Co-authored-by: lars-reimann <[email protected]> Co-authored-by: nvollroth <[email protected]>
1 parent faa656f commit fa4687f

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

api-editor/gui/src/features/packageData/model/APIJsonData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface PythonParameterJson {
6868
docstring: {
6969
type: Optional<string>;
7070
description: Optional<string>;
71+
default_value: Optional<string>;
7172
};
7273
type: object; // TODO parse type
7374
}

api-editor/gui/src/features/packageData/model/PythonPackageBuilder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const parsePythonParameterJson = function (
159159
parameterJson.docstring.type ?? '',
160160
parameterJson.docstring.description ?? '',
161161
parameterJson.type,
162+
parameterJson.docstring.default_value ?? '',
162163
);
163164
idToDeclaration.set(parameterJson.id, result);
164165
return result;

api-editor/gui/src/features/packageData/model/PythonParameter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class PythonParameter extends PythonDeclaration {
2929
readonly typeInDocs: string = '',
3030
readonly description: string = '',
3131
readonly type: object = {},
32+
readonly defaultValueInDocs: Optional<string> = null,
3233
) {
3334
super();
3435

@@ -85,6 +86,7 @@ export class PythonParameter extends PythonDeclaration {
8586
docstring: {
8687
type: this.typeInDocs,
8788
description: this.description,
89+
default_value: this.defaultValueInDocs,
8890
},
8991
type: this.type,
9092
};
@@ -100,6 +102,8 @@ export class PythonParameter extends PythonDeclaration {
100102
this.isPublic,
101103
this.typeInDocs,
102104
this.description,
105+
this.type,
106+
this.defaultValueInDocs,
103107
);
104108
result.containingFunction = this.containingFunction;
105109
return result;

api-editor/gui/src/features/packageData/selectionView/ParameterView.tsx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, Heading, Stack, Text as ChakraText, useColorModeValue } from '@chakra-ui/react';
1+
import { Box, Heading, HStack, Stack, Text as ChakraText, useColorModeValue } from '@chakra-ui/react';
22
import React from 'react';
33
import { PythonParameter } from '../model/PythonParameter';
44
import { ParameterNode } from './ParameterNode';
@@ -39,12 +39,36 @@ export const ParameterView: React.FC<ParameterViewProps> = function ({ pythonPar
3939
</Stack>
4040
)}
4141

42-
{pythonParameter.defaultValue && (
42+
{pythonParameter && (
4343
<Stack spacing={4}>
4444
<Heading as="h4" size="md">
4545
Default Value
4646
</Heading>
47-
<ChakraText paddingLeft={4}>{pythonParameter.defaultValue}</ChakraText>
47+
48+
{pythonParameter.defaultValue ? (
49+
<Stack>
50+
<ChakraText paddingLeft={4}>Code: {pythonParameter.defaultValue}</ChakraText>
51+
52+
{pythonParameter.defaultValueInDocs ? (
53+
<ChakraText paddingLeft={4}>
54+
Documentation: {pythonParameter.defaultValueInDocs}
55+
</ChakraText>
56+
) : (
57+
<HStack>
58+
<ChakraText paddingLeft={4}>
59+
Documentation:{' '}
60+
<Box as="span" color="gray.500">
61+
The documentation does not specify a default value.
62+
</Box>
63+
</ChakraText>
64+
</HStack>
65+
)}
66+
</Stack>
67+
) : (
68+
<ChakraText paddingLeft={4} color="gray.500">
69+
The parameter is required.
70+
</ChakraText>
71+
)}
4872
</Stack>
4973
)}
5074

@@ -126,12 +150,8 @@ const CustomBarChart: React.FC<CustomBarChartProps> = function ({ parameterUsage
126150
datasets: [
127151
{
128152
data: labels.map((key) => sortedParameterUsages.get(key)),
129-
borderColor: labels.map((key) =>
130-
isStringifiedLiteral(key) ? 'rgba(137, 87, 229, 1)' : 'rgba(136, 136, 136, 1)',
131-
),
132-
backgroundColor: labels.map((key) =>
133-
isStringifiedLiteral(key) ? 'rgba(137, 87, 229, 0.2)' : 'rgba(136, 136, 136, 0.2)',
134-
),
153+
borderColor: labels.map((key) => (isStringifiedLiteral(key) ? '#871F78' : '#888888')),
154+
backgroundColor: labels.map((key) => (isStringifiedLiteral(key) ? '#871F78' : '#888888')),
135155
},
136156
],
137157
};

0 commit comments

Comments
 (0)