Skip to content

Commit

Permalink
New Settings > Capabilities page (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed May 6, 2021
1 parent df15e16 commit ec39e52
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 10 deletions.
5 changes: 5 additions & 0 deletions mwdb/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mwdb/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.0-14",
"@fortawesome/free-solid-svg-icons": "^5.1.0-11",
"@fortawesome/free-regular-svg-icons": "^5.1.0-11",
"@fortawesome/free-solid-svg-icons": "^5.1.0-11",
"@fortawesome/react-fontawesome": "0.1.0-11",
"@mwdb-web/commons": "file:src/commons",
"axios": "^0.21.1",
"bootstrap": "4.3.1",
"bootstrap-select": "^1.13.18",
"brace": "^0.11.1",
"d3": "^5.10.0",
"dagre-d3": "^0.6.3",
Expand Down
1 change: 1 addition & 0 deletions mwdb/web/src/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"version": "2.3.0",
"peerDependencies": {
"@fortawesome/react-fontawesome": "*",
"bootstrap-select": "*",
"lodash": "*",
"react": "*",
"react-ace": "*",
Expand Down
45 changes: 45 additions & 0 deletions mwdb/web/src/commons/ui/BootstrapSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { useCallback, useLayoutEffect, useRef } from "react";

import "bootstrap-select";
import "bootstrap-select/dist/css/bootstrap-select.css";
import $ from "jquery";

export default function BootstrapSelect({
children,
onChange,
noneSelectedText,
...props
}) {
const ref = useRef(null);
const setRef = useCallback((node) => {
// Initialize the select element when mounted
if (node) {
const selectElement = $(node);
selectElement.selectpicker();
}
// Save a reference to the node
ref.current = node;
}, []);

useLayoutEffect(() => {
// Bind onChange event handler and unbind the old/unmounted one
const selectElement = $(ref.current);
selectElement.on("changed.bs.select", onChange);
return () => {
selectElement.off("changed.bs.select", onChange);
};
}, [onChange]);

useLayoutEffect(() => {
// Re-render selectpicker when props are changed
// FIX: noneSelectedText doesn't update on refresh itself
$(ref.current).selectpicker({ noneSelectedText });
$(ref.current).selectpicker("refresh");
}, [props, noneSelectedText]);

return (
<select ref={setRef} {...props}>
{children}
</select>
);
}
20 changes: 12 additions & 8 deletions mwdb/web/src/commons/ui/GroupBadge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import React from "react";
import { Link } from "react-router-dom";

export default function GroupBadge({ group }) {
export default function GroupBadge({ group, clickable }) {
const badge = (
<span
className={`badge badge-${group.private ? "primary" : "secondary"}`}
>
{group.name}
</span>
);

if (!clickable) return badge;

return (
<Link
to={
Expand All @@ -10,13 +20,7 @@ export default function GroupBadge({ group }) {
: `/profile/group/${group.name}`
}
>
<span
className={`badge badge-${
group.private ? "primary" : "secondary"
}`}
>
{group.name}
</span>
{badge}
</Link>
);
}
1 change: 1 addition & 0 deletions mwdb/web/src/commons/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";

export { default as APIKeyList } from "./APIKeyList";
export { default as Autocomplete } from "./Autocomplete";
export { default as BootstrapSelect } from "./BootstrapSelect";
export { default as ConfirmationModal } from "./ConfirmationModal";
export { default as DataTable } from "./DataTable";
export { default as DateString } from "./DateString";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function CapabilitiesTable({ profile }) {
group.capabilities.includes(cap)
)
.map((group) => (
<GroupBadge group={group} />
<GroupBadge group={group} clickable />
))}
</div>
</td>
Expand Down
2 changes: 2 additions & 0 deletions mwdb/web/src/components/Profile/Views/ProfileGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default function ProfileGroup({ profile }) {
name: login,
private: true,
}}
clickable
/>
))}
</ProfileItem>
Expand All @@ -98,6 +99,7 @@ export default function ProfileGroup({ profile }) {
name: login,
private: true,
}}
clickable
/>
))}
</ProfileItem>
Expand Down
8 changes: 8 additions & 0 deletions mwdb/web/src/components/Settings/SettingsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import UserCreate from "./Views/UserCreate";
import GroupRegister from "./Views/GroupRegister";
import AttributeDefine from "./Views/AttributeDefine";
import UserView from "./Views/UserView";
import AccessControl from "./Views/AccessControl";

function SettingsNav() {
const auth = useContext(AuthContext);
Expand Down Expand Up @@ -162,6 +163,13 @@ export default function SettingsView(props) {
<GroupUpdate />
</AdministrativeRoute>

<AdministrativeRoute
exact
path="/admin/capabilities"
>
<AccessControl />
</AdministrativeRoute>

<AttributeRoute exact path="/admin/attributes">
<ManageAttributes />
</AttributeRoute>
Expand Down

0 comments on commit ec39e52

Please sign in to comment.