Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
37e51197
Unverified
Commit
37e51197
authored
6 years ago
by
Kyle Doherty
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
show correct items based on admin status + tests (#8071)
parent
bf9f1023
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/nav/components/ProfileLink.jsx
+46
-60
46 additions, 60 deletions
frontend/src/metabase/nav/components/ProfileLink.jsx
frontend/test/nav/ProfileLink.unit.spec.js
+31
-0
31 additions, 0 deletions
frontend/test/nav/ProfileLink.unit.spec.js
with
77 additions
and
60 deletions
frontend/src/metabase/nav/components/ProfileLink.jsx
+
46
−
60
View file @
37e51197
...
...
@@ -14,82 +14,68 @@ import Logs from "metabase/components/Logs";
import
LogoIcon
from
"
metabase/components/LogoIcon
"
;
import
EntityMenu
from
"
metabase/components/EntityMenu
"
;
// generate the proper set of list items for the current user
// based on whether they're an admin or not
export
default
class
ProfileLink
extends
Component
{
constructor
(
props
,
context
)
{
super
(
props
,
context
);
this
.
state
=
{
dropdownOpen
:
false
,
modalOpen
:
null
,
};
_
.
bindAll
(
this
,
"
toggleDropdown
"
,
"
closeDropdown
"
,
"
openModal
"
,
"
closeModal
"
,
);
}
state
=
{
dropdownOpen
:
false
,
};
static
propTypes
=
{
user
:
PropTypes
.
object
.
isRequired
,
context
:
PropTypes
.
string
.
isRequired
,
};
toggleDropdown
()
{
this
.
setState
({
dropdownOpen
:
!
this
.
state
.
dropdownOpen
});
}
closeDropdown
()
{
this
.
setState
({
dropdownOpen
:
false
});
}
openModal
(
modalName
)
{
openModal
=
modalName
=>
{
this
.
setState
({
dropdownOpen
:
false
,
modalOpen
:
modalName
});
}
}
;
closeModal
()
{
closeModal
=
()
=>
{
this
.
setState
({
modalOpen
:
null
});
}
};
generateOptionsForUser
=
()
=>
{
const
admin
=
this
.
props
.
user
.
is_superuser
;
const
adminContext
=
this
.
props
.
context
===
"
admin
"
;
return
[
{
title
:
t
`Account settings`
,
icon
:
null
,
link
:
Urls
.
accountSettings
(),
},
...(
admin
&&
[
{
title
:
adminContext
?
t
`Exit admin`
:
t
`Admin`
,
icon
:
null
,
link
:
adminContext
?
"
/
"
:
"
/admin
"
,
},
]),
...(
admin
&&
[
{
title
:
t
`Logs`
,
icon
:
null
,
action
:
()
=>
this
.
openModal
(
"
logs
"
),
},
]),
{
title
:
t
`About Metabase`
,
icon
:
null
,
action
:
()
=>
this
.
openModal
(
"
about
"
),
},
{
title
:
t
`Sign out`
,
icon
:
null
,
link
:
"
auth/logout
"
,
},
];
};
render
()
{
const
{
context
}
=
this
.
props
;
const
{
modalOpen
}
=
this
.
state
;
const
{
tag
,
date
,
...
versionExtra
}
=
MetabaseSettings
.
get
(
"
version
"
);
const
admin
=
context
===
"
admin
"
;
return
(
<
Box
>
<
EntityMenu
items
=
{
[
{
title
:
t
`Account settings`
,
icon
:
null
,
link
:
Urls
.
accountSettings
(),
},
{
title
:
admin
?
t
`Exit admin`
:
t
`Admin`
,
icon
:
null
,
link
:
admin
?
"
/
"
:
"
/admin
"
,
},
{
title
:
t
`Logs`
,
icon
:
null
,
action
:
()
=>
this
.
openModal
(
"
logs
"
),
},
{
title
:
t
`About Metabase`
,
icon
:
null
,
action
:
()
=>
this
.
openModal
(
"
about
"
),
},
{
title
:
t
`Sign out`
,
icon
:
null
,
link
:
"
auth/logout
"
,
},
]
}
triggerIcon
=
"gear"
/>
<
EntityMenu
items
=
{
this
.
generateOptionsForUser
()
}
triggerIcon
=
"gear"
/>
{
modalOpen
===
"
about
"
?
(
<
Modal
small
onClose
=
{
this
.
closeModal
}
>
<
div
className
=
"px4 pt4 pb2 text-centered relative"
>
...
...
This diff is collapsed.
Click to expand it.
frontend/test/nav/ProfileLink.unit.spec.js
0 → 100644
+
31
−
0
View file @
37e51197
import
React
from
"
react
"
;
import
{
shallow
}
from
"
enzyme
"
;
import
ProfileLink
from
"
metabase/nav/components/ProfileLink
"
;
jest
.
mock
(
"
metabase/lib/settings
"
,
()
=>
({
get
:
()
=>
({
tag
:
1
,
version
:
1
,
}),
}));
describe
(
"
ProfileLink
"
,
()
=>
{
describe
(
"
options
"
,
()
=>
{
describe
(
"
normal user
"
,
()
=>
{
it
(
"
should show the proper set of items
"
,
()
=>
{
const
normalUser
=
{
is_superuser
:
false
};
const
wrapper
=
shallow
(
<
ProfileLink
user
=
{
normalUser
}
context
=
{
""
}
/>
)
;
expect
(
wrapper
.
instance
().
generateOptionsForUser
().
length
).
toBe
(
3
);
});
});
describe
(
"
admin
"
,
()
=>
{
it
(
"
should show the proper set of items
"
,
()
=>
{
const
admin
=
{
is_superuser
:
true
};
const
wrapper
=
shallow
(
<
ProfileLink
user
=
{
admin
}
context
=
{
""
}
/>
)
;
expect
(
wrapper
.
instance
().
generateOptionsForUser
().
length
).
toBe
(
5
);
});
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment