Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AmendsenProject
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shaik Janipasha
AmendsenProject
Commits
e31e280e
Unverified
Commit
e31e280e
authored
Sep 10, 2019
by
Daniel
Committed by
GitHub
Sep 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added auto-select resource after searching (#292)
parent
0e262bb2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
9 deletions
+77
-9
reducer.ts
amundsen_application/static/js/ducks/search/reducer.ts
+1
-1
sagas.ts
amundsen_application/static/js/ducks/search/sagas.ts
+11
-5
index.spec.ts
...en_application/static/js/ducks/search/tests/index.spec.ts
+48
-2
utils.ts
amundsen_application/static/js/ducks/search/utils.ts
+15
-1
Resources.ts
amundsen_application/static/js/interfaces/Resources.ts
+2
-0
No files found.
amundsen_application/static/js/ducks/search/reducer.ts
View file @
e31e280e
...
@@ -32,7 +32,7 @@ export interface SearchReducerState {
...
@@ -32,7 +32,7 @@ export interface SearchReducerState {
};
};
/* ACTIONS */
/* ACTIONS */
export
function
searchAll
(
term
:
string
,
resource
:
ResourceType
,
pageIndex
:
number
):
SearchAllRequest
{
export
function
searchAll
(
term
:
string
,
resource
?:
ResourceType
,
pageIndex
?
:
number
):
SearchAllRequest
{
return
{
return
{
payload
:
{
payload
:
{
resource
,
resource
,
...
...
amundsen_application/static/js/ducks/search/sagas.ts
View file @
e31e280e
...
@@ -30,11 +30,12 @@ import {
...
@@ -30,11 +30,12 @@ import {
searchResourceFailure
,
searchResourceFailure
,
searchResourceSuccess
,
setPageIndex
,
setResource
,
searchResourceSuccess
,
setPageIndex
,
setResource
,
}
from
'./reducer'
;
}
from
'./reducer'
;
import
{
getPageIndex
,
getSearchState
}
from
'./utils'
;
import
{
autoSelectResource
,
getPageIndex
,
getSearchState
}
from
'./utils'
;
import
{
updateSearchUrl
}
from
'utils/navigation-utils'
;
import
{
updateSearchUrl
}
from
'utils/navigation-utils'
;
export
function
*
searchAllWorker
(
action
:
SearchAllRequest
):
SagaIterator
{
export
function
*
searchAllWorker
(
action
:
SearchAllRequest
):
SagaIterator
{
const
{
resource
,
pageIndex
,
term
}
=
action
.
payload
;
let
{
resource
}
=
action
.
payload
;
const
{
pageIndex
,
term
}
=
action
.
payload
;
const
tableIndex
=
resource
===
ResourceType
.
table
?
pageIndex
:
0
;
const
tableIndex
=
resource
===
ResourceType
.
table
?
pageIndex
:
0
;
const
userIndex
=
resource
===
ResourceType
.
user
?
pageIndex
:
0
;
const
userIndex
=
resource
===
ResourceType
.
user
?
pageIndex
:
0
;
const
dashboardIndex
=
resource
===
ResourceType
.
dashboard
?
pageIndex
:
0
;
const
dashboardIndex
=
resource
===
ResourceType
.
dashboard
?
pageIndex
:
0
;
...
@@ -53,7 +54,12 @@ export function* searchAllWorker(action: SearchAllRequest): SagaIterator {
...
@@ -53,7 +54,12 @@ export function* searchAllWorker(action: SearchAllRequest): SagaIterator {
dashboards
:
dashboardResponse
.
dashboards
||
initialState
.
dashboards
,
dashboards
:
dashboardResponse
.
dashboards
||
initialState
.
dashboards
,
isLoading
:
false
,
isLoading
:
false
,
};
};
const
index
=
getPageIndex
(
searchAllResponse
,
resource
);
if
(
resource
===
undefined
)
{
resource
=
autoSelectResource
(
searchAllResponse
);
searchAllResponse
.
selectedTab
=
resource
;
}
const
index
=
getPageIndex
(
searchAllResponse
);
yield
put
(
searchAllSuccess
(
searchAllResponse
));
yield
put
(
searchAllSuccess
(
searchAllResponse
));
updateSearchUrl
({
term
,
resource
,
index
,
},
true
);
updateSearchUrl
({
term
,
resource
,
index
,
},
true
);
...
@@ -80,7 +86,7 @@ export function* searchResourceWatcher(): SagaIterator {
...
@@ -80,7 +86,7 @@ export function* searchResourceWatcher(): SagaIterator {
export
function
*
submitSearchWorker
(
action
:
SubmitSearchRequest
):
SagaIterator
{
export
function
*
submitSearchWorker
(
action
:
SubmitSearchRequest
):
SagaIterator
{
const
{
searchTerm
}
=
action
.
payload
;
const
{
searchTerm
}
=
action
.
payload
;
yield
put
(
searchAll
(
searchTerm
,
ResourceType
.
table
,
0
));
yield
put
(
searchAll
(
searchTerm
));
updateSearchUrl
({
term
:
searchTerm
});
updateSearchUrl
({
term
:
searchTerm
});
};
};
export
function
*
submitSearchWatcher
():
SagaIterator
{
export
function
*
submitSearchWatcher
():
SagaIterator
{
...
@@ -142,7 +148,7 @@ export function* loadPreviousSearchWorker(action: LoadPreviousSearchRequest): Sa
...
@@ -142,7 +148,7 @@ export function* loadPreviousSearchWorker(action: LoadPreviousSearchRequest): Sa
updateSearchUrl
({
updateSearchUrl
({
term
:
state
.
search_term
,
term
:
state
.
search_term
,
resource
:
state
.
selectedTab
,
resource
:
state
.
selectedTab
,
index
:
getPageIndex
(
state
,
state
.
selectedTab
),
index
:
getPageIndex
(
state
),
});
});
};
};
export
function
*
loadPreviousSearchWatcher
():
SagaIterator
{
export
function
*
loadPreviousSearchWatcher
():
SagaIterator
{
...
...
amundsen_application/static/js/ducks/search/tests/index.spec.ts
View file @
e31e280e
import
{
testSaga
}
from
'redux-saga-test-plan'
;
import
{
testSaga
}
from
'redux-saga-test-plan'
;
import
{
ResourceType
}
from
'interfaces'
;
import
{
DEFAULT_RESOURCE_TYPE
,
ResourceType
}
from
'interfaces'
;
import
*
as
API
from
'../api/v0'
;
import
*
as
API
from
'../api/v0'
;
...
@@ -331,7 +331,7 @@ describe('search ducks', () => {
...
@@ -331,7 +331,7 @@ describe('search ducks', () => {
const
term
=
'test'
;
const
term
=
'test'
;
updateSearchUrlSpy
.
mockClear
();
updateSearchUrlSpy
.
mockClear
();
testSaga
(
submitSearchWorker
,
submitSearch
(
term
))
testSaga
(
submitSearchWorker
,
submitSearch
(
term
))
.
next
().
put
(
searchAll
(
term
,
ResourceType
.
table
,
0
))
.
next
().
put
(
searchAll
(
term
))
.
next
().
isDone
();
.
next
().
isDone
();
expect
(
updateSearchUrlSpy
).
toHaveBeenCalledWith
({
term
});
expect
(
updateSearchUrlSpy
).
toHaveBeenCalledWith
({
term
});
...
@@ -536,5 +536,51 @@ describe('search ducks', () => {
...
@@ -536,5 +536,51 @@ describe('search ducks', () => {
expect
(
SearchUtils
.
getPageIndex
(
mockState
,
'not valid input'
)).
toEqual
(
0
);
expect
(
SearchUtils
.
getPageIndex
(
mockState
,
'not valid input'
)).
toEqual
(
0
);
});
});
});
});
describe
(
'autoSelectResource'
,
()
=>
{
const
emptyMockState
=
{
...
searchState
,
dashboards
:
{
...
searchState
.
dashboards
,
total_results
:
0
,
},
tables
:
{
...
searchState
.
tables
,
total_results
:
0
,
},
users
:
{
...
searchState
.
users
,
total_results
:
0
,
}
};
it
(
'returns the DEFAULT_RESOURCE_TYPE when search results are empty'
,
()
=>
{
expect
(
SearchUtils
.
autoSelectResource
(
emptyMockState
)).
toEqual
(
DEFAULT_RESOURCE_TYPE
);
});
it
(
'prefers `table` over `user` and `dashboard`'
,
()
=>
{
const
mockState
=
{
...
emptyMockState
};
mockState
.
tables
.
total_results
=
10
;
mockState
.
users
.
total_results
=
10
;
mockState
.
dashboards
.
total_results
=
10
;
expect
(
SearchUtils
.
autoSelectResource
(
mockState
)).
toEqual
(
ResourceType
.
table
);
});
it
(
'prefers `user` over `dashboard`'
,
()
=>
{
const
mockState
=
{
...
emptyMockState
};
mockState
.
tables
.
total_results
=
0
;
mockState
.
users
.
total_results
=
10
;
mockState
.
dashboards
.
total_results
=
10
;
expect
(
SearchUtils
.
autoSelectResource
(
mockState
)).
toEqual
(
ResourceType
.
user
);
});
it
(
'returns `dashboard` if there are dashboards but no other results'
,
()
=>
{
const
mockState
=
{
...
emptyMockState
};
mockState
.
tables
.
total_results
=
0
;
mockState
.
users
.
total_results
=
0
;
mockState
.
dashboards
.
total_results
=
10
;
expect
(
SearchUtils
.
autoSelectResource
(
mockState
)).
toEqual
(
ResourceType
.
dashboard
);
});
});
});
});
});
});
amundsen_application/static/js/ducks/search/utils.ts
View file @
e31e280e
import
{
GlobalState
}
from
'ducks/rootReducer'
;
import
{
GlobalState
}
from
'ducks/rootReducer'
;
import
{
SearchReducerState
}
from
'ducks/search/reducer'
;
import
{
SearchReducerState
}
from
'ducks/search/reducer'
;
import
{
ResourceType
}
from
'interfaces/Resources'
;
import
{
DEFAULT_RESOURCE_TYPE
,
ResourceType
}
from
'interfaces/Resources'
;
export
const
getSearchState
=
(
state
:
GlobalState
):
SearchReducerState
=>
state
.
search
;
export
const
getSearchState
=
(
state
:
GlobalState
):
SearchReducerState
=>
state
.
search
;
...
@@ -16,3 +16,17 @@ export const getPageIndex = (state: SearchReducerState, resource?: ResourceType)
...
@@ -16,3 +16,17 @@ export const getPageIndex = (state: SearchReducerState, resource?: ResourceType)
};
};
return
0
;
return
0
;
};
};
export
const
autoSelectResource
=
(
state
:
SearchReducerState
)
=>
{
if
(
state
.
tables
&&
state
.
tables
.
total_results
>
0
)
{
return
ResourceType
.
table
;
}
if
(
state
.
users
&&
state
.
users
.
total_results
>
0
)
{
return
ResourceType
.
user
}
if
(
state
.
dashboards
&&
state
.
dashboards
.
total_results
>
0
)
{
return
ResourceType
.
dashboard
}
return
DEFAULT_RESOURCE_TYPE
;
};
amundsen_application/static/js/interfaces/Resources.ts
View file @
e31e280e
...
@@ -6,6 +6,8 @@ export enum ResourceType {
...
@@ -6,6 +6,8 @@ export enum ResourceType {
dashboard
=
"dashboard"
,
dashboard
=
"dashboard"
,
};
};
export
const
DEFAULT_RESOURCE_TYPE
=
ResourceType
.
table
;
export
interface
Resource
{
export
interface
Resource
{
type
:
ResourceType
;
type
:
ResourceType
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment