Skip to content

Commit

Permalink
Refactor to avoid warning and a bit of clean-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-limyr committed Jan 22, 2025
1 parent 4dc1a14 commit bc9edc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
16 changes: 2 additions & 14 deletions client/src/components/SearchInput/TripQueryArguments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,13 @@ import ArgumentTooltip from './ArgumentTooltip.tsx';
import { excludedArguments } from './excluded-arguments.ts';
import { ResolvedType } from './useTripArgs.ts';
import ResetButton from './ResetButton.tsx';
import { DefaultValue, extractAllArgs, ProcessedArgument } from './extractArgs.ts';
import { DefaultValue, extractAllArgs, formatArgumentName, ProcessedArgument } from './extractArgs.ts';

interface TripQueryArgumentsProps {
tripQueryVariables: TripQueryVariables;
setTripQueryVariables: (tripQueryVariables: TripQueryVariables) => void;
}

/**
* Returns a human-readable name from a path like "someNestedArg.subArg".
*/
function formatArgumentName(input: string): string {
if (!input) {
return ' ';
}
const parts = input.split('.');
const formatted = parts[parts.length - 1].replace(/([A-Z])/g, ' $1').trim();
return formatted.replace(/\b\w/g, (char) => char.toUpperCase()) + ' ';
}

const TripQueryArguments: React.FC<TripQueryArgumentsProps> = ({ tripQueryVariables, setTripQueryVariables }) => {
const [argumentsList, setArgumentsList] = useState<ProcessedArgument[]>([]);
const [expandedArguments, setExpandedArguments] = useState<Record<string, boolean>>({});
Expand All @@ -38,7 +26,7 @@ const TripQueryArguments: React.FC<TripQueryArgumentsProps> = ({ tripQueryVariab

const extractedArgs = extractAllArgs(tripArgs.trip.arguments);
setArgumentsList(extractedArgs);
}, [tripArgs, loading, error, extractAllArgs]);
}, [tripArgs, loading, error]);

function normalizePathForList(path: string): string {
// Replace numeric segments with `*`
Expand Down
12 changes: 11 additions & 1 deletion client/src/components/SearchInput/extractArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ export interface ProcessedArgument {
isComplex?: boolean;
isList?: boolean;
}

/**
* Returns a human-readable name from a path like "someNestedArg.subArg".
*/
export function formatArgumentName(input: string): string {
if (!input) {
return ' ';
}
const parts = input.split('.');
const formatted = parts[parts.length - 1].replace(/([A-Z])/g, ' $1').trim();
return formatted.replace(/\b\w/g, (char) => char.toUpperCase()) + ' ';
}
/**
* Recursively extracts a flat list of arguments (ProcessedArgument[]).
*/
Expand Down

0 comments on commit bc9edc2

Please sign in to comment.