Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
amundsen_dev
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
Surendar Reddy Mangannagari
amundsen_dev
Commits
ce5096dd
Unverified
Commit
ce5096dd
authored
May 29, 2019
by
Ryan Lieu
Committed by
GitHub
May 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
url to state fixes (#171)
parent
523e0e71
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
239 additions
and
57 deletions
+239
-57
index.tsx
...sen_application/static/js/components/SearchPage/index.tsx
+28
-13
index.spec.tsx
...tion/static/js/components/SearchPage/tests/index.spec.tsx
+201
-41
reducer.ts
amundsen_application/static/js/ducks/search/reducer.ts
+10
-3
No files found.
amundsen_application/static/js/components/SearchPage/index.tsx
View file @
ce5096dd
...
...
@@ -4,6 +4,7 @@ import { bindActionCreators } from 'redux';
import
*
as
DocumentTitle
from
'react-document-title'
;
import
*
as
qs
from
'simple-query-string'
;
import
Pagination
from
'react-js-pagination'
;
import
{
RouteComponentProps
}
from
'react-router'
;
import
SearchBar
from
'./SearchBar'
;
import
SearchList
from
'./SearchList'
;
...
...
@@ -48,7 +49,7 @@ export interface StateFromProps {
searchTerm
:
string
;
popularTables
:
TableResource
[];
tables
:
TableSearchResults
;
dashboards
:
DashboardSearchResults
dashboards
:
DashboardSearchResults
;
users
:
UserSearchResults
;
}
...
...
@@ -58,7 +59,7 @@ export interface DispatchFromProps {
getPopularTables
:
()
=>
GetPopularTablesRequest
;
}
export
type
SearchPageProps
=
StateFromProps
&
DispatchFromProps
;
export
type
SearchPageProps
=
StateFromProps
&
DispatchFromProps
&
RouteComponentProps
<
any
>
;
interface
SearchPageState
{
selectedTab
:
ResourceType
;
...
...
@@ -77,17 +78,25 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
componentDidMount
()
{
this
.
props
.
getPopularTables
();
const
params
=
qs
.
parse
(
window
.
location
.
search
);
const
params
=
qs
.
parse
(
this
.
props
.
location
.
search
);
const
{
searchTerm
,
pageIndex
,
selectedTab
}
=
params
;
const
currentTab
=
this
.
getSelectedTabByResourceType
(
selectedTab
);
const
{
term
,
index
,
currentTab
}
=
this
.
getSanitizedUrlParams
(
searchTerm
,
pageIndex
,
selectedTab
);
this
.
setState
({
selectedTab
:
currentTab
});
if
(
searchTerm
&&
searchTerm
.
length
>
0
)
{
const
index
=
pageIndex
||
0
;
this
.
props
.
searchAll
(
searchTerm
,
this
.
createSearchOptions
(
index
,
currentTab
));
// Update the page URL with validated parameters.
this
.
updatePageUrl
(
searchTerm
,
currentTab
,
index
);
if
(
term
!==
""
)
{
this
.
props
.
searchAll
(
term
,
this
.
createSearchOptions
(
index
,
currentTab
));
if
(
currentTab
!==
selectedTab
||
pageIndex
!==
index
)
{
this
.
updatePageUrl
(
term
,
currentTab
,
index
);
}
}
}
componentDidUpdate
(
prevProps
)
{
if
(
this
.
props
.
location
.
search
!==
prevProps
.
location
.
search
)
{
const
params
=
qs
.
parse
(
this
.
props
.
location
.
search
);
const
{
searchTerm
,
pageIndex
,
selectedTab
}
=
params
;
const
{
term
,
index
,
currentTab
}
=
this
.
getSanitizedUrlParams
(
searchTerm
,
pageIndex
,
selectedTab
);
this
.
setState
({
selectedTab
:
currentTab
});
this
.
props
.
searchAll
(
term
,
this
.
createSearchOptions
(
index
,
currentTab
));
}
}
...
...
@@ -110,6 +119,13 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
};
};
getSanitizedUrlParams
=
(
searchTerm
:
string
,
pageIndex
:
number
,
selectedTab
:
ResourceType
)
=>
{
const
currentTab
=
this
.
getSelectedTabByResourceType
(
selectedTab
);
const
index
=
pageIndex
||
0
;
const
term
=
searchTerm
?
searchTerm
:
""
;
return
{
term
,
index
,
currentTab
};
};
getPageIndexByResourceType
=
(
tab
:
ResourceType
):
number
=>
{
switch
(
tab
)
{
case
ResourceType
.
table
:
...
...
@@ -123,7 +139,6 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
};
onSearchBarSubmit
=
(
searchTerm
:
string
):
void
=>
{
this
.
props
.
searchAll
(
searchTerm
);
this
.
updatePageUrl
(
searchTerm
,
this
.
state
.
selectedTab
,
0
);
};
...
...
@@ -141,7 +156,7 @@ export class SearchPage extends React.Component<SearchPageProps, SearchPageState
updatePageUrl
=
(
searchTerm
:
string
,
tab
:
ResourceType
,
pageIndex
:
number
):
void
=>
{
const
pathName
=
`/search?searchTerm=
${
searchTerm
}
&selectedTab=
${
tab
}
&pageIndex=
${
pageIndex
}
`
;
window
.
history
.
pushState
({},
''
,
`
${
window
.
location
.
origin
}${
pathName
}
`
);
this
.
props
.
history
.
push
(
pathName
);
};
renderPopularTables
=
()
=>
{
...
...
amundsen_application/static/js/components/SearchPage/tests/index.spec.tsx
View file @
ce5096dd
This diff is collapsed.
Click to expand it.
amundsen_application/static/js/ducks/search/reducer.ts
View file @
ce5096dd
...
...
@@ -12,7 +12,7 @@ import {
}
from
'./types'
;
import
{
ResourceType
}
from
'components/common/ResourceListItem/types'
;
export
type
SearchReducerAction
=
SearchAllResponse
|
SearchResourceResponse
;
export
type
SearchReducerAction
=
SearchAllResponse
|
SearchResourceResponse
|
SearchAllRequest
;
export
interface
SearchReducerState
{
search_term
:
string
;
...
...
@@ -58,19 +58,26 @@ const initialState: SearchReducerState = {
};
export
default
function
reducer
(
state
:
SearchReducerState
=
initialState
,
action
:
SearchReducerAction
):
SearchReducerState
{
const
newState
=
action
.
payload
;
switch
(
action
.
type
)
{
// Updates search term to reflect action
case
SearchAll
.
ACTION
:
return
{
...
state
,
search_term
:
action
.
term
,
};
// SearchAll will reset all resources with search results or the initial state
case
SearchAll
.
SUCCESS
:
const
newState
=
action
.
payload
;
return
{
...
initialState
,
...
newState
,
};
// SearchResource will set only a single resource and preserves search state for other resources
case
SearchResource
.
SUCCESS
:
const
resourceNewState
=
action
.
payload
;
return
{
...
state
,
...
n
ewState
,
...
resourceN
ewState
,
};
case
SearchAll
.
FAILURE
:
case
SearchResource
.
FAILURE
:
...
...
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