-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRevisionHistoryPage.tsx
133 lines (124 loc) · 4.66 KB
/
RevisionHistoryPage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import React, {useState} from "react";
import {Breadcrumb, Table, Button, Dropdown, Label, Select} from 'flowbite-react';
import {Revision, RevisionHistory} from "./revisionHistory.ts";
import {HiChevronDown, HiChevronLeft, HiChevronRight} from 'react-icons/hi';
export const RevisionHistoryPage: () => React.ReactElement = () => {
return (
<div className={"container mx-auto"}>
<header className={"mb-8"}>
<Breadcrumb className={"my-8"}>
<Breadcrumb.Item href={"https://www.yext.com/s/3744518/search2/experiences"}>
Search
</Breadcrumb.Item>
<Breadcrumb.Item
href={"https://www.yext.com/s/3744518/search2/experiences/default/verticals"}>
Default Experience
</Breadcrumb.Item>
<Breadcrumb.Item>
Revision History
</Breadcrumb.Item>
</Breadcrumb>
<h1
className={"mb-4 text-3xl font-extrabold leading-none tracking-tight text-gray-900 md:text-4xl dark:text-white"}>Revision
History</h1>
<p>Use this page to see all revisions of your search configuration and assign your latest and production
labels to a specific revision.</p>
</header>
<RevisionHistoryTable/>
</div>
);
}
export const RevisionHistoryTable = () => {
const [offset, setOffset] = useState(0);
const [limit, setLimit] = useState(5);
return (
<div className={"overflow-x-auto"}>
<div className={"flex flex-row justify-end mb-2 content-baseline"}>
<div className={"flex flex-row mx-2 items-baseline"}>
<Label htmlFor={"changeLimit"} className={"me-2"}>Show</Label>
<Select id={"changeLimit"} value={limit} onChange={(e) => setLimit(parseInt(e.target.value))}>
<option value="5">5</option>
<option value="10">10</option>
</Select>
</div>
<Button.Group>
<Button color={"light"} disabled={offset === 0} aria-label={"previous"} onClick={() => {
setOffset(Math.max(offset - limit, 0))
}}><HiChevronLeft/></Button>
<Button color={"light"} disabled={offset + limit >= RevisionHistory.length} aria-label={"next"}
onClick={() => {
setOffset(offset + limit)
}}><HiChevronRight/></Button>
</Button.Group>
</div>
<Table>
<Table.Head>
<Table.HeadCell>Version Number</Table.HeadCell>
<Table.HeadCell>Timestamp</Table.HeadCell>
<Table.HeadCell>Updated By</Table.HeadCell>
<Table.HeadCell>Actions</Table.HeadCell>
</Table.Head>
<Table.Body>
<RevisionHistoryRows offset={offset} limit={limit}/>
</Table.Body>
</Table>
</div>
)
}
export const RevisionHistoryRows: React.FC<{
offset: number,
limit: number,
}> = ({offset, limit}) => {
const revisions = RevisionHistory.slice(offset, offset + limit);
return (
<>
{revisions.map(revision => <RevisionHistoryTableRow key={revision.id} revision={revision}/>)}
</>
)
}
export const RevisionHistoryTableRow: React.FC<{ revision: Revision }> = ({revision}) => {
return (
<Table.Row>
<Table.Cell><RevisionLabel revision={revision}/></Table.Cell>
<Table.Cell>{revision.timestamp}</Table.Cell>
<Table.Cell>{revision.updatedBy}</Table.Cell>
<Table.Cell><ActionMenu revision={revision}/></Table.Cell>
</Table.Row>
)
}
export const RevisionLabel: React.FC<{ revision: Revision }> = ({revision}) => {
if (revision.label) {
const colorScheme = revision.label.toLowerCase() === "production" ? "green" : "red";
return (
<div className={"flex flex-row items-baseline"}>
<span className={"me-2"}>{revision.id}</span>
<span
className={`bg-${colorScheme}-100 text-${colorScheme}-800 text-sm font-medium me-2 px-2.5 py-0.5 rounded dark:bg-${colorScheme}-900 dark:text-${colorScheme}-300`}>
{revision.label}
</span>
</div>
)
}
return (
<>{revision.id}</>
);
}
export const ActionMenu: React.FC<{ revision: Revision }> = ({revision}) => {
return (
<Button.Group>
<Button as={"a"} color={"dark"}
href={`https://www.yext.com/s/3744518/search2/experiences/default/revisionHistory/${revision.id}`}
target={"_blank"}>View JSON</Button>
<Dropdown
color={"dark"}
label={""}
aria-label={"More Options"}
renderTrigger={
() => <Button color={"dark"} className={"rounded-l-none"}><HiChevronDown/></Button>
}>
<Dropdown.Item>Publish to Production</Dropdown.Item>
<Dropdown.Item>Restore to Latest</Dropdown.Item>
</Dropdown>
</Button.Group>
)
}