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
a557b82b
Unverified
Commit
a557b82b
authored
Apr 29, 2019
by
Tamika Tannis
Committed by
GitHub
Apr 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to fully controlled component (#114)
parent
bc94586c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
30 deletions
+12
-30
index.tsx
...plication/static/js/components/AnnouncementPage/index.tsx
+2
-10
index.spec.tsx
...tatic/js/components/AnnouncementPage/tests/index.spec.tsx
+7
-9
index.tsx
...en_application/static/js/components/ProfilePage/index.tsx
+3
-11
No files found.
amundsen_application/static/js/components/AnnouncementPage/index.tsx
View file @
a557b82b
...
@@ -14,10 +14,6 @@ import { AnnouncementsGetRequest } from 'ducks/announcements/types';
...
@@ -14,10 +14,6 @@ import { AnnouncementsGetRequest } from 'ducks/announcements/types';
import
{
announcementsGet
}
from
'ducks/announcements/reducer'
;
import
{
announcementsGet
}
from
'ducks/announcements/reducer'
;
import
{
AnnouncementPost
}
from
'./types'
;
import
{
AnnouncementPost
}
from
'./types'
;
interface
AnnouncementPageState
{
posts
:
AnnouncementPost
[];
}
export
interface
StateFromProps
{
export
interface
StateFromProps
{
posts
:
AnnouncementPost
[];
posts
:
AnnouncementPost
[];
}
}
...
@@ -28,13 +24,9 @@ export interface DispatchFromProps {
...
@@ -28,13 +24,9 @@ export interface DispatchFromProps {
export
type
AnnouncementPageProps
=
StateFromProps
&
DispatchFromProps
;
export
type
AnnouncementPageProps
=
StateFromProps
&
DispatchFromProps
;
export
class
AnnouncementPage
extends
React
.
Component
<
AnnouncementPageProps
,
AnnouncementPageState
>
{
export
class
AnnouncementPage
extends
React
.
Component
<
AnnouncementPageProps
>
{
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
this
.
state
=
{
posts
:
this
.
props
.
posts
,
};
}
}
componentDidMount
()
{
componentDidMount
()
{
...
@@ -56,7 +48,7 @@ export class AnnouncementPage extends React.Component<AnnouncementPageProps, Ann
...
@@ -56,7 +48,7 @@ export class AnnouncementPage extends React.Component<AnnouncementPageProps, Ann
}
}
createPosts
()
{
createPosts
()
{
return
this
.
state
.
posts
.
map
((
post
,
index
)
=>
{
return
this
.
props
.
posts
.
map
((
post
,
index
)
=>
{
return
this
.
createPost
(
post
,
index
)
return
this
.
createPost
(
post
,
index
)
});
});
}
}
...
...
amundsen_application/static/js/components/AnnouncementPage/tests/index.spec.tsx
View file @
a557b82b
...
@@ -37,22 +37,20 @@ describe('AnnouncementPage', () => {
...
@@ -37,22 +37,20 @@ describe('AnnouncementPage', () => {
describe
(
'createPost'
,
()
=>
{
describe
(
'createPost'
,
()
=>
{
let
content
;
let
content
;
let
post
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
post
=
subject
.
state
().
posts
[
0
];
content
=
shallow
(
subject
.
instance
().
createPost
(
props
.
posts
[
0
],
0
));
content
=
shallow
(
subject
.
instance
().
createPost
(
post
,
0
));
});
});
it
(
'renders the post title'
,
()
=>
{
it
(
'renders the post title'
,
()
=>
{
expect
(
content
.
children
().
at
(
0
).
children
().
at
(
0
).
text
()).
toEqual
(
p
ost
.
title
);
expect
(
content
.
children
().
at
(
0
).
children
().
at
(
0
).
text
()).
toEqual
(
p
rops
.
posts
[
0
]
.
title
);
});
});
it
(
'renders the post date'
,
()
=>
{
it
(
'renders the post date'
,
()
=>
{
expect
(
content
.
children
().
at
(
0
).
children
().
at
(
1
).
text
()).
toEqual
(
p
ost
.
date
);
expect
(
content
.
children
().
at
(
0
).
children
().
at
(
1
).
text
()).
toEqual
(
p
rops
.
posts
[
0
]
.
date
);
});
});
it
(
'renders SanitizedHTML with the post content'
,
()
=>
{
it
(
'renders SanitizedHTML with the post content'
,
()
=>
{
expect
(
content
.
find
(
SanitizedHTML
).
props
()).
toMatchObject
({
expect
(
content
.
find
(
SanitizedHTML
).
props
()).
toMatchObject
({
html
:
p
ost
.
html_content
,
html
:
p
rops
.
posts
[
0
]
.
html_content
,
});
});
});
});
});
});
...
@@ -62,12 +60,12 @@ describe('AnnouncementPage', () => {
...
@@ -62,12 +60,12 @@ describe('AnnouncementPage', () => {
subject
.
instance
().
createPost
=
jest
.
fn
();
subject
.
instance
().
createPost
=
jest
.
fn
();
subject
.
instance
().
createPosts
();
subject
.
instance
().
createPosts
();
});
});
it
(
'call createPost() for each
state
.posts[] item'
,
()
=>
{
it
(
'call createPost() for each
props
.posts[] item'
,
()
=>
{
expect
(
subject
.
instance
().
createPost
).
toHaveBeenCalledTimes
(
subject
.
state
()
.
posts
.
length
)
expect
(
subject
.
instance
().
createPost
).
toHaveBeenCalledTimes
(
props
.
posts
.
length
)
});
});
it
(
'passes correct props to createPost()'
,
()
=>
{
it
(
'passes correct props to createPost()'
,
()
=>
{
expect
(
subject
.
instance
().
createPost
).
toHaveBeenCalledWith
(
subject
.
state
()
.
posts
[
0
],
0
);
expect
(
subject
.
instance
().
createPost
).
toHaveBeenCalledWith
(
props
.
posts
[
0
],
0
);
});
});
});
});
...
...
amundsen_application/static/js/components/ProfilePage/index.tsx
View file @
a557b82b
...
@@ -24,11 +24,7 @@ interface DispatchFromProps {
...
@@ -24,11 +24,7 @@ interface DispatchFromProps {
export
type
ProfilePageProps
=
StateFromProps
&
DispatchFromProps
;
export
type
ProfilePageProps
=
StateFromProps
&
DispatchFromProps
;
interface
ProfilePageState
{
export
class
ProfilePage
extends
React
.
Component
<
ProfilePageProps
>
{
user
:
User
;
}
export
class
ProfilePage
extends
React
.
Component
<
ProfilePageProps
,
ProfilePageState
>
{
private
userId
:
string
;
private
userId
:
string
;
constructor
(
props
)
{
constructor
(
props
)
{
...
@@ -37,10 +33,6 @@ export class ProfilePage extends React.Component<ProfilePageProps, ProfilePageSt
...
@@ -37,10 +33,6 @@ export class ProfilePage extends React.Component<ProfilePageProps, ProfilePageSt
const
{
match
}
=
props
;
const
{
match
}
=
props
;
const
params
=
match
.
params
;
const
params
=
match
.
params
;
this
.
userId
=
params
&&
params
.
userId
?
params
.
userId
:
''
;
this
.
userId
=
params
&&
params
.
userId
?
params
.
userId
:
''
;
this
.
state
=
{
user
:
this
.
props
.
user
,
};
}
}
componentDidMount
()
{
componentDidMount
()
{
...
@@ -57,7 +49,7 @@ export class ProfilePage extends React.Component<ProfilePageProps, ProfilePageSt
...
@@ -57,7 +49,7 @@ export class ProfilePage extends React.Component<ProfilePageProps, ProfilePageSt
}
}
generateTabInfo
=
()
=>
{
generateTabInfo
=
()
=>
{
const
user
=
this
.
state
.
user
;
const
user
=
this
.
props
.
user
;
const
tabInfo
=
[];
const
tabInfo
=
[];
// TODO: Populate tabs based on data
// TODO: Populate tabs based on data
...
@@ -84,7 +76,7 @@ export class ProfilePage extends React.Component<ProfilePageProps, ProfilePageSt
...
@@ -84,7 +76,7 @@ export class ProfilePage extends React.Component<ProfilePageProps, ProfilePageSt
/* TODO: Add support to direct to 404 page for edgecase of someone typing in
/* TODO: Add support to direct to 404 page for edgecase of someone typing in
or pasting in a bad url. This would be consistent with TableDetail page behavior */
or pasting in a bad url. This would be consistent with TableDetail page behavior */
render
()
{
render
()
{
const
user
=
this
.
state
.
user
;
const
user
=
this
.
props
.
user
;
return
(
return
(
<
DocumentTitle
title=
{
`${user.display_name} - Amundsen Profile`
}
>
<
DocumentTitle
title=
{
`${user.display_name} - Amundsen Profile`
}
>
<
div
className=
"container profile-page"
>
<
div
className=
"container profile-page"
>
...
...
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