Skip to content

Commit

Permalink
Add default unit to duration search query params (#244)
Browse files Browse the repository at this point in the history
Signed-off-by: Everett Ross <reverett@uber.com>
  • Loading branch information
everett980 committed Dec 12, 2018
1 parent ae37289 commit a57d15d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
19 changes: 15 additions & 4 deletions packages/jaeger-ui/src/components/SearchTracePage/SearchForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import './SearchForm.css';
const FormItem = Form.Item;
const Option = Select.Option;

const durationPlaceholderText = 'e.g. 1.2s, 100ms, 500us; defaults unit to ms';
const AdaptedInput = reduxFormFieldAdapter(Input);
const AdaptedSelect = reduxFormFieldAdapter(Select);
const AdaptedVirtualSelect = reduxFormFieldAdapter(VirtSelect, option => (option ? option.value : null));
Expand Down Expand Up @@ -98,6 +99,11 @@ export function convertQueryParamsToFormDates({ start, end }) {
};
}

function addDefaultUnitToDuration(duration) {
if (!duration) return null;
return /[0-9]$/.test(duration) ? `${duration}ms` : duration;
}

export function submitForm(fields, searchTraces) {
const {
resultsLimit,
Expand Down Expand Up @@ -146,8 +152,8 @@ export function submitForm(fields, searchTraces) {
start,
end,
tags: convTagsLogfmt(tags) || undefined,
minDuration: minDuration || null,
maxDuration: maxDuration || null,
minDuration: addDefaultUnitToDuration(minDuration),
maxDuration: addDefaultUnitToDuration(maxDuration),
});
}

Expand Down Expand Up @@ -323,13 +329,18 @@ export class SearchFormImpl extends React.PureComponent {
<Field
name="minDuration"
component={AdaptedInput}
placeholder="e.g. 1.2s, 100ms, 500us"
placeholder={durationPlaceholderText}
props={{ disabled }}
/>
</FormItem>

<FormItem label="Max Duration">
<Field name="maxDuration" component={AdaptedInput} placeholder="e.g. 1.1s" props={{ disabled }} />
<Field
name="maxDuration"
component={AdaptedInput}
placeholder={durationPlaceholderText}
props={{ disabled }}
/>
</FormItem>

<FormItem label="Limit Results">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('submitForm()', () => {
});

describe('`fields.{minDuration,maxDuration}', () => {
it('retains values as-is when they are truthy', () => {
it('retains values as-is when they are truthy and do not terminate in a number', () => {
fields.minDuration = 'some-min';
fields.maxDuration = 'some-max';
submitForm(fields, searchTraces);
Expand All @@ -229,6 +229,17 @@ describe('submitForm()', () => {
expect(maxDuration).toBe(fields.maxDuration);
});

it("appends 'ms' when they are truthy and terminate in a number", () => {
fields.minDuration = '100';
fields.maxDuration = '200';
submitForm(fields, searchTraces);
const { calls } = searchTraces.mock;
expect(calls.length).toBe(1);
const { minDuration, maxDuration } = calls[0][0];
expect(minDuration).toBe(`${fields.minDuration}ms`);
expect(maxDuration).toBe(`${fields.maxDuration}ms`);
});

it('omits values when they are falsy', () => {
fields.minDuation = undefined;
fields.maxDuation = undefined;
Expand Down

0 comments on commit a57d15d

Please sign in to comment.