Skip to content

Commit 42ef644

Browse files
authored
Added attributes to settings (growthbook#243)
1 parent 11ef84c commit 42ef644

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

packages/front-end/components/Layout/Layout.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ const navlinks: SidebarLinkProps[] = [
9898
href: "/settings/projects",
9999
path: /^settings\/projects/,
100100
},
101+
{
102+
name: "Attributes",
103+
href: "/settings/attributes",
104+
path: /^settings\/attributes/,
105+
},
101106
{
102107
name: "Billing",
103108
href: "/settings/billing",
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import React, { useState } from "react";
2+
import useUser from "../../hooks/useUser";
3+
import Tooltip from "../../components/Tooltip";
4+
import { FaQuestionCircle } from "react-icons/fa";
5+
import { GBEdit } from "../../components/Icons";
6+
import EditAttributesModal from "../../components/Features/EditAttributesModal";
7+
8+
const FeatureAttributesPage = (): React.ReactElement => {
9+
const [editOpen, setEditOpen] = useState(false);
10+
const { settings, permissions } = useUser();
11+
const attributeSchema = settings?.attributeSchema || [];
12+
13+
return (
14+
<>
15+
<div className="contents container-fluid pagecontents">
16+
<div className="mb-5">
17+
<div className="row mb-3 align-items-center">
18+
<div className="col-auto">
19+
<h3>Targeting Attributes</h3>
20+
<p className="text-gray">
21+
These attributes can be used when targeting feature flags.
22+
Attributes set here must also be passed in through the SDK.
23+
</p>
24+
</div>
25+
<div style={{ flex: 1 }} />
26+
{permissions.organizationSettings && (
27+
<div className="col-auto">
28+
<button
29+
className="btn btn-primary float-right"
30+
onClick={() => {
31+
setEditOpen(true);
32+
}}
33+
>
34+
<span className="h4 pr-2 m-0 d-inline-block align-top">
35+
<GBEdit />
36+
</span>
37+
Edit Attributes
38+
</button>
39+
</div>
40+
)}
41+
</div>
42+
<table className="table gbtable">
43+
<thead>
44+
<tr>
45+
<th>Attribute</th>
46+
<th>Data Type</th>
47+
<th>
48+
Identifier{" "}
49+
<Tooltip text="Any attribute that uniquely identifies a user, account, device, or similar.">
50+
<FaQuestionCircle
51+
style={{ position: "relative", top: "-1px" }}
52+
/>
53+
</Tooltip>
54+
</th>
55+
</tr>
56+
</thead>
57+
<tbody>
58+
{attributeSchema && attributeSchema.length > 0 ? (
59+
<>
60+
{attributeSchema.map((v, i) => (
61+
<tr key={i}>
62+
<td className="text-gray font-weight-bold">
63+
{v.property}
64+
</td>
65+
<td className="text-gray">
66+
{v.datatype}
67+
{v.datatype === "enum" && <>: ({v.enum})</>}
68+
</td>
69+
<td className="text-gray">
70+
{v.hashAttribute && <>yes</>}
71+
</td>
72+
</tr>
73+
))}
74+
</>
75+
) : (
76+
<>
77+
<tr>
78+
<td colSpan={3} className="text-center text-gray">
79+
<em>
80+
No attributes defined{" "}
81+
<a
82+
href="#"
83+
onClick={(e) => {
84+
e.preventDefault();
85+
setEditOpen(true);
86+
}}
87+
>
88+
Add attributes now
89+
</a>
90+
</em>
91+
</td>
92+
</tr>
93+
</>
94+
)}
95+
</tbody>
96+
</table>
97+
</div>
98+
</div>
99+
{editOpen && <EditAttributesModal close={() => setEditOpen(false)} />}
100+
</>
101+
);
102+
};
103+
104+
export default FeatureAttributesPage;

0 commit comments

Comments
 (0)