Skip to content

Commit deee9c2

Browse files
committed
Add UI updates to site page
1 parent 5d47701 commit deee9c2

File tree

7 files changed

+117
-21
lines changed

7 files changed

+117
-21
lines changed

src/api.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface GetManifestResponse {
1515

1616
interface ListManifestRequest {
1717
site: string;
18+
manifestType: string;
1819
}
1920

2021
interface ListManifestResponse {
@@ -45,7 +46,10 @@ export class ApiHandler {
4546
expressRequest: express.Request,
4647
request: ListManifestRequest
4748
): Promise<ListManifestResponse> {
48-
const manifests = await server.listManifests(request.site);
49+
const manifests = await server.listManifests(
50+
request.site,
51+
request.manifestType
52+
);
4953
if (!manifests) {
5054
return {
5155
manifests: null,

src/server.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,13 @@ export const lookupManifest = async (options: ManifestLookupOptions[]) => {
7474
return entities.find(Boolean);
7575
};
7676

77-
export const listManifests = async (siteId: string) => {
77+
export const listManifests = async (siteId: string, manifestType?: string) => {
7878
const query = datastore.createQuery('Fileset2Manifest');
7979
query.filter('site', siteId);
80-
query.filter('manifestType', ManifestType.Branch);
80+
query.filter(
81+
'manifestType',
82+
manifestType ? manifestType : ManifestType.Branch
83+
);
8184
const result = await query.run();
8285
if (result) {
8386
return result[0];

src/webui/pages/sitepage.tsx

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,20 @@ export class SitePage extends Page<SitePageProps, SitePageState> {
3535

3636
async componentDidMount() {
3737
document.title = `${this.state.siteId} – Fileset`;
38+
this.updateTable(this.state.tab === undefined ? 'branch' : 'ref');
39+
}
40+
41+
async componentWillReceiveProps(props: SitePageProps) {
42+
this.setState({tab: props.tab});
43+
this.updateTable(props.tab === undefined ? 'branch' : 'ref');
44+
}
45+
46+
async updateTable(manifestType: string) {
3847
try {
3948
this.setState({loading: true});
4049
const resp: any = await rpc('manifest.list', {
4150
site: this.state.siteId,
51+
manifestType: manifestType,
4252
});
4353
this.setState({
4454
loading: false,
@@ -50,10 +60,6 @@ export class SitePage extends Page<SitePageProps, SitePageState> {
5060
}
5161
}
5262

53-
async componentWillReceiveProps(props: SitePageProps) {
54-
this.setState({tab: props.tab});
55-
}
56-
5763
filterManifests(manifests: Array<any>) {
5864
return manifests.sort(
5965
(a, b) => new Date(b.modified).getTime() - new Date(a.modified).getTime()
@@ -92,24 +98,25 @@ export class SitePage extends Page<SitePageProps, SitePageState> {
9298
</Link>
9399
</div>
94100
<div>
95-
{this.state.tab === undefined ? this.renderManifestTable() : ''}
96-
{this.state.tab === 'history' ? this.renderManifestTable() : ''}
101+
{this.state.loading
102+
? this.renderLoading()
103+
: this.renderManifestTable()}
97104
</div>
98105
</div>
99106
);
100107
}
101108

102-
renderManifestTable() {
103-
return this.state.manifests && this.state.manifests.length ? (
109+
renderStagingLinkTable() {
110+
return (
104111
<div class="SitePage__content__table">
105112
<table>
106113
<thead>
107114
<tr>
108115
<th>Branch</th>
109-
<th>Commit</th>
116+
<th data-extra-small>Commit</th>
110117
<th>Modified</th>
111-
<th>Files</th>
112-
<th>Staging link</th>
118+
<th data-extra-small>Files</th>
119+
<th data-extra-small>Staging link</th>
113120
</tr>
114121
</thead>
115122
<tbody>
@@ -148,6 +155,78 @@ export class SitePage extends Page<SitePageProps, SitePageState> {
148155
</tbody>
149156
</table>
150157
</div>
158+
);
159+
}
160+
161+
renderHistoryTable() {
162+
return (
163+
<div class="SitePage__content__table">
164+
<table>
165+
<thead>
166+
<tr>
167+
<th>Description</th>
168+
<th data-extra-small>Commit</th>
169+
<th>Modified</th>
170+
<th data-extra-small>Files</th>
171+
<th data-small>Links</th>
172+
</tr>
173+
</thead>
174+
<tbody>
175+
{this.filterManifests(this.state.manifests).map((manifest, i) => (
176+
<tr>
177+
<td>
178+
{manifest.commit ? (
179+
<div>
180+
{manifest.commit.message}{' '}
181+
<small>{manifest.commit.author.name}</small>
182+
</div>
183+
) : (
184+
<small>(unknown)</small>
185+
)}
186+
</td>
187+
<td>
188+
<code>{manifest.ref.slice(0, 7)}</code>
189+
</td>
190+
<td>{prettyDate(manifest.modified)}</td>
191+
<td>{Object.keys(manifest.paths).length}</td>
192+
<td>
193+
<a
194+
class="button button--tonal button--small"
195+
href={`/fileset/sites/${
196+
this.state.siteId
197+
}/${encodeURIComponent(manifest.ref.slice(0, 7))}/`}
198+
>
199+
<span class="material-icons-outlined">view_list</span>
200+
Details
201+
</a>
202+
<a
203+
class="button button--tonal button--small"
204+
href={createStagingLink(
205+
window.location.href,
206+
manifest.site,
207+
'',
208+
manifest.ref
209+
)}
210+
>
211+
<span class="material-icons-outlined">open_in_new</span>
212+
Staging
213+
</a>
214+
</td>
215+
</tr>
216+
))}
217+
</tbody>
218+
</table>
219+
</div>
220+
);
221+
}
222+
223+
renderManifestTable() {
224+
return this.state.manifests && this.state.manifests.length ? (
225+
this.state.tab === 'history' ? (
226+
this.renderHistoryTable()
227+
) : (
228+
this.renderStagingLinkTable()
229+
)
151230
) : (
152231
<div class="SitePage__content__empty">
153232
<div class="SitePage__content__empty__headline">
@@ -178,9 +257,7 @@ export class SitePage extends Page<SitePageProps, SitePageState> {
178257
{this.state.siteId}
179258
</Link>
180259
</div>
181-
<div class="SitePage__content">
182-
{this.state.loading ? this.renderLoading() : this.renderTabSet()}
183-
</div>
260+
<div class="SitePage__content">{this.renderTabSet()}</div>
184261
</div>
185262
);
186263
}

src/webui/sass/components/_button.sass

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ $button-primary-hover-color: $color-primary-hover
126126

127127
.material-icons-outlined
128128
margin-right: 4px
129-
margin-top: -1px
129+
margin-top: 0

src/webui/sass/pages/_sitepage.sass

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@
2525
text-align: left
2626
top: 0
2727

28+
&[data-extra-small]
29+
width: 100px
30+
31+
&[data-small]
32+
width: 200px
33+
2834
.SitePage__content__table table tr td
2935
padding: 5px 10px
3036

37+
small
38+
font-weight: 700
39+
3140
.SitePage__content__table table tr:hover td
3241
background: #F7F8F8
3342

src/webui/sass/utils/_tabset.sass

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
font-weight: 700
1414

1515
.material-icons-outlined
16-
margin-right: 7px
1716
color: #969DA4
17+
margin-right: 7px
18+
max-height: 17px
19+
max-width: 17px
1820

1921
&--active
2022
border-bottom-color: $color-primary

src/webui/utils/links.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ export function createStagingLink(
1919
});
2020
branch = branch.replace('/', '--');
2121
let prefix;
22-
// Resulting branch isn't URL safe, we need to use the ref.
23-
if (encodeURIComponent(branch) !== branch) {
22+
// Resulting branch is empty (meaning we want the ref link), or isn't URL
23+
// safe, we need to use the ref.
24+
if (!branch || encodeURIComponent(branch) !== branch) {
2425
prefix = ref.slice(0, 7);
2526
} else {
2627
prefix = branch;

0 commit comments

Comments
 (0)