Skip to content

Commit d37d70d

Browse files
authored
Fix/workflow advanced query (#259)
* fix bug where query string is not being cleared properly when switching from advanced to basic * when refreshing the page it should retain the state of basic or advanced query. * removing unused variable. only use queryString for advanced API. clear state toggling between. fixed trim input issue. * ensure advance query uses list API * fix lint * updating integration test with testcase for advanced screen * fixing lint * added filter mode query param to keep track of screen when refreshing. No longer clearing queryString. * fixing lint * fixing integration test * fixing lint
1 parent 95e894d commit d37d70d

File tree

4 files changed

+95
-33
lines changed

4 files changed

+95
-33
lines changed

client/routes/domain/workflow-list.vue

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export default {
3636
loading: false,
3737
results: [],
3838
error: undefined,
39-
nextPageToken: undefined,
4039
npt: undefined,
4140
nptAlt: undefined,
4241
statuses: [
@@ -51,7 +50,6 @@ export default {
5150
{ value: 'TIMED_OUT', label: 'Timed Out' },
5251
],
5352
maxRetentionDays: undefined,
54-
filterMode: 'basic',
5553
};
5654
},
5755
async created() {
@@ -72,9 +70,9 @@ export default {
7270
},
7371
computed: {
7472
fetchUrl() {
75-
const { domain, queryString, state } = this;
73+
const { domain, filterMode, state } = this;
7674
77-
if (queryString) {
75+
if (filterMode === 'advanced') {
7876
return `/api/domains/${domain}/workflows/list`;
7977
}
8078
@@ -90,6 +88,9 @@ export default {
9088
? 'StartTime'
9189
: 'CloseTime';
9290
},
91+
filterMode() {
92+
return this.$route.query.filterMode || 'basic';
93+
},
9394
formattedResults() {
9495
const { dateFormat, results, timeFormat, timezone } = this;
9596
@@ -174,6 +175,7 @@ export default {
174175
criteria() {
175176
const {
176177
endTime,
178+
filterMode,
177179
queryString,
178180
startTime,
179181
statusName: status,
@@ -185,19 +187,24 @@ export default {
185187
return null;
186188
}
187189
190+
if (filterMode === 'advanced') {
191+
return {
192+
queryString: queryString.trim(),
193+
};
194+
}
195+
188196
const criteria = {
189197
startTime,
190198
endTime,
191199
status,
192-
...(queryString && { queryString }),
193-
...(workflowId && { workflowId }),
194-
...(workflowName && { workflowName }),
200+
...(workflowId && { workflowId: workflowId.trim() }),
201+
...(workflowName && { workflowName: workflowName.trim() }),
195202
};
196203
197204
return criteria;
198205
},
199206
queryString() {
200-
return this.$route.query.queryString;
207+
return this.$route.query.queryString || '';
201208
},
202209
minStartDate() {
203210
return this.getMinStartDate();
@@ -210,6 +217,13 @@ export default {
210217
},
211218
},
212219
methods: {
220+
clearState() {
221+
this.error = undefined;
222+
this.loading = false;
223+
this.npt = undefined;
224+
this.nptAlt = undefined;
225+
this.results = [];
226+
},
213227
async fetch(url, queryWithStatus) {
214228
let workflows = [];
215229
let nextPageToken = '';
@@ -271,9 +285,15 @@ export default {
271285
return;
272286
}
273287
288+
if (this.filterMode === 'advanced' && !this.criteria.queryString) {
289+
this.clearState();
290+
291+
return;
292+
}
293+
274294
let workflows = [];
275295
276-
if (this.state !== 'all') {
296+
if (this.state !== 'all' || this.filterMode === 'advanced') {
277297
const query = { ...this.criteria, nextPageToken: this.npt };
278298
279299
if (query.queryString) {
@@ -330,9 +350,7 @@ export default {
330350
},
331351
refreshWorkflows: debounce(
332352
function refreshWorkflows() {
333-
this.results = [];
334-
this.npt = undefined;
335-
this.nptAlt = undefined;
353+
this.clearState();
336354
this.fetchWorkflows();
337355
},
338356
typeof Mocha === 'undefined' ? 200 : 60,
@@ -341,10 +359,7 @@ export default {
341359
setWorkflowFilter(e) {
342360
const target = e.target || e.testTarget; // test hook since Event.target is readOnly and unsettable
343361
344-
this.$router.replaceQueryParam(
345-
target.getAttribute('name'),
346-
target.value.trim()
347-
);
362+
this.$router.replaceQueryParam(target.getAttribute('name'), target.value);
348363
},
349364
setStatus(status) {
350365
if (status) {
@@ -428,12 +443,12 @@ export default {
428443
return query;
429444
},
430445
toggleFilter() {
431-
if (this.filterMode === 'advanced') {
432-
this.filterMode = 'basic';
433-
this.$route.query.queryString = '';
434-
} else {
435-
this.filterMode = 'advanced';
436-
}
446+
const { query } = this.$route;
447+
448+
this.clearState();
449+
const filterMode = this.filterMode === 'advanced' ? 'basic' : 'advanced';
450+
451+
this.$router.replace({ query: { ...query, filterMode } });
437452
},
438453
onWorkflowGridScroll(startIndex, endIndex) {
439454
if (!this.npt && !this.nptAlt) {

client/test/fixtures.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ export default {
7676
.toISOString(),
7777
},
7878
],
79+
list: [
80+
{
81+
execution: {
82+
workflowId: 'email-daily-summaries',
83+
runId: '51ccc0d1-6ffe-4a7a-a89f-6b5154df86f7',
84+
},
85+
type: {
86+
name: 'github.com/uber/cadence-web/email-daily-summaries-1',
87+
},
88+
closeStatus: 'COMPLETED',
89+
startTime: emailRun1Start.toISOString(),
90+
closeTime: moment(timeBasis)
91+
.subtract(2, 'minutes')
92+
.subtract(1, 'day')
93+
.toISOString(),
94+
},
95+
],
7996
},
8097
history: {
8198
emailRun1: [

client/test/scenario.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,22 @@ Scenario.prototype.withWorkflows = function withWorkflows({
250250
}
251251

252252
const startTimeDays = startTimeOffset || status === 'open' ? 30 : 21;
253-
const url = `/api/domains/${this.domain}/workflows/${status}?${qs.stringify({
254-
startTime: moment()
255-
.subtract(startTimeDays, 'day')
256-
.startOf('day')
257-
.toISOString(),
258-
endTime: moment()
259-
.endOf('day')
260-
.toISOString(),
261-
...query,
262-
})}`;
263-
253+
const baseUrl = `/api/domains/${this.domain}/workflows/${status}`;
254+
const queryString = qs.stringify(
255+
status === 'list'
256+
? query
257+
: {
258+
startTime: moment()
259+
.subtract(startTimeDays, 'day')
260+
.startOf('day')
261+
.toISOString(),
262+
endTime: moment()
263+
.endOf('day')
264+
.toISOString(),
265+
...query,
266+
}
267+
);
268+
const url = `${baseUrl}?${queryString}`;
264269
const response = Array.isArray(workflows)
265270
? { executions: workflows, nextPageToken: '' }
266271
: workflows;

client/test/workflow-list.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,29 @@ describe('Workflow list', () => {
357357
.querySelector('header.filters .status .selected-tag')
358358
.should.have.trimmed.text('Failed');
359359
});
360+
361+
it('should call list API when filterMode = advanced and queryString query params are set', async function test() {
362+
const [testEl] = new Scenario(this.test)
363+
.withDomain('ci-test')
364+
.startingAt(
365+
'/domains/ci-test/workflows?status=FAILED&queryString=demo&filterMode=advanced'
366+
)
367+
.withNewsFeed()
368+
.withWorkflows({
369+
status: 'list',
370+
query: {
371+
queryString: 'demo',
372+
},
373+
})
374+
.withDomainDescription('ci-test')
375+
.go();
376+
377+
const workflowsEl = await testEl.waitUntilExists(
378+
'section.workflow-list.ready'
379+
);
380+
381+
workflowsEl
382+
.querySelector('header.filters input[name="queryString"]')
383+
.value.should.equal('demo');
384+
});
360385
});

0 commit comments

Comments
 (0)