Skip to content

Commit

Permalink
Rename website column. Table component.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Aug 7, 2020
1 parent a09867f commit 000f84d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 9 deletions.
1 change: 1 addition & 0 deletions assets/pen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion components/Settings.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import Page from './Page';
import Table from './Table';
import { get } from 'lib/web';

const columns = [
{ key: 'name', label: 'Name' },
{ key: 'domain', label: 'Domain' },
];

export default function Settings() {
const [data, setData] = useState();

async function loadData() {
setData(await get(`/api/website`));
}

useEffect(() => {
loadData();
}, []);

if (!data) {
return null;
}

return (
<Page>
<h2>Settings</h2>
<Table columns={columns} rows={data.websites} />
</Page>
);
}
25 changes: 25 additions & 0 deletions components/Table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import styles from './Table.module.css';

export default function Table({ columns, rows }) {
return (
<table className={styles.table}>
<thead>
<tr>
{columns.map(({ key, label }) => (
<th key={key}>{label}</th>
))}
</tr>
</thead>
<tbody>
{rows.map((row, rowIndex) => (
<tr key={rowIndex}>
{columns.map(({ key }) => (
<td key={`${rowIndex}${key}`}>{row[key]}</td>
))}
</tr>
))}
</tbody>
</table>
);
}
7 changes: 7 additions & 0 deletions components/Table.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.table {
width: 100%;
}

.table th {
text-align: left;
}
2 changes: 1 addition & 1 deletion components/WebsiteDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' })
<Page>
<div className="row">
<div className={classNames(styles.chart, 'col')}>
<h2>{data.label}</h2>
<h2>{data.name}</h2>
<WebsiteChart
websiteId={websiteId}
onDataLoad={handleDataLoad}
Expand Down
10 changes: 5 additions & 5 deletions components/WebsiteList.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ export default function WebsiteList() {
return (
<Page>
{data &&
data.websites.map(({ website_id, label }) => (
data.websites.map(({ website_id, name }) => (
<div key={website_id} className={styles.website}>
<div className={styles.header}>
<h2>
<Link
href="/website/[...id]"
as={`/website/${website_id}/${label}`}
as={`/website/${website_id}/${name}`}
className={styles.title}
>
{label}
{name}
</Link>
</h2>
<Link
href="/website/[...id]"
as={`/website/${website_id}/${label}`}
as={`/website/${website_id}/${name}`}
className={styles.details}
>
<Icon icon={<Arrow />} /> View details
</Link>
</div>
<WebsiteChart key={website_id} title={label} websiteId={website_id} />
<WebsiteChart key={website_id} title={name} websiteId={website_id} />
</div>
))}
</Page>
Expand Down
3 changes: 2 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ model session {
model website {
website_id Int @default(autoincrement()) @id
website_uuid String @unique
label String
name String
created_at DateTime? @default(now())
user_id Int
domain String?
account account @relation(fields: [user_id], references: [user_id])
event event[]
pageview pageview[]
Expand Down
3 changes: 2 additions & 1 deletion sql/schema.postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ create table website (
website_id serial primary key,
website_uuid uuid unique not null,
user_id int not null references account(user_id) on delete cascade,
label varchar(100) not null,
name varchar(100) not null,
domain varchar(500),
created_at timestamp with time zone default current_timestamp
);

Expand Down

0 comments on commit 000f84d

Please sign in to comment.