forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuggestedChartRevisionApproverPage.tsx
1645 lines (1571 loc) · 68.1 KB
/
SuggestedChartRevisionApproverPage.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import React from "react"
import { observer } from "mobx-react"
import { observable, computed, action, runInAction } from "mobx"
import { Link } from "react-router-dom"
import { Base64 } from "js-base64"
import Select from "react-select"
import {
Bounds,
getStylesForTargetHeight,
SortOrder,
SuggestedChartRevisionStatus,
Tippy,
uniqBy,
} from "@ourworldindata/utils"
import { Grapher } from "@ourworldindata/grapher"
import {
TextAreaField,
NumberField,
RadioGroup,
Toggle,
Timeago,
} from "./Forms.js"
import { References } from "./ChartEditor.js"
import { AdminLayout } from "./AdminLayout.js"
import { SuggestedChartRevisionStatusIcon } from "./SuggestedChartRevisionList.js"
import { AdminAppContext, AdminAppContextType } from "./AdminAppContext.js"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import {
faMobile,
faDesktop,
faExternalLinkAlt,
faAngleLeft,
faAngleRight,
faAngleDoubleLeft,
faAngleDoubleRight,
faSortAlphaDown,
faSortAlphaUpAlt,
faRandom,
faMagicWandSparkles,
} from "@fortawesome/free-solid-svg-icons"
import {
VisionDeficiency,
VisionDeficiencySvgFilters,
VisionDeficiencyDropdown,
VisionDeficiencyEntity,
} from "./VisionDeficiencies.js"
import { SuggestedChartRevisionSerialized } from "./SuggestedChartRevision.js"
import { match } from "ts-pattern"
import { ReferencesSection } from "./EditorReferencesTab.js"
interface UserSelectOption {
userName: string
userId: number | undefined
}
@observer
export class SuggestedChartRevisionApproverPage extends React.Component<{
suggestedChartRevisionId?: number
}> {
@observable.ref suggestedChartRevisions?: SuggestedChartRevisionSerialized[]
@observable currentlyActiveUserId?: number
@observable.ref originalGrapherElement?: React.ReactElement
@observable.ref suggestedGrapherElement?: React.ReactElement
@observable.ref existingGrapherElement?: React.ReactElement
@observable.ref chartReferences: References | undefined = undefined
// HACK: In order for the <select> dropdown to not drop any existing users after finishing all
// their reviews, we want the list of available users to be append-only, which we achieve by
// introducing this extra state and merging them in the `availableUsers` getter.
_cacheAvailableUsers: UserSelectOption[] = []
@observable rowNum: number = 1
@observable decisionReasonInput?: string = ""
@observable showReadme: boolean = false
@observable showSettings: boolean = false
@observable showPendingOnly: boolean = true
@observable showExistingChart: boolean = false
@observable previewMode: string = "desktop"
@observable desktopPreviewSize: string = "normal"
@observable sortBy: string = "updatedAt"
@observable sortOrder: SortOrder = SortOrder.desc
@observable previewSvgOrJson: string = "svg"
@observable simulateVisionDeficiency?: VisionDeficiency
// GPT
@observable gptNum: number = 0
@observable gptNumDisp: number = 1
@observable usingGPT: boolean = false
ALL_TABS = {
approval: "Chart Approval Tool",
readme: "Instructions",
settings: "Settings",
} as const
@observable activeTab: keyof typeof this.ALL_TABS = "approval"
@observable private _isGraphersSet = false
static contextType = AdminAppContext
context!: AdminAppContextType
@computed get admin() {
return this.context.admin
}
@computed get offset() {
return this.rowNumValid - 1
}
@computed get prevBtnIsDisabled() {
return !this._isGraphersSet || this.rowNumValid <= 1
}
@computed get nextBtnIsDisabled() {
return (
!this._isGraphersSet ||
this.rowNumValid >= this.numAvailableRowsForSelectedUser
)
}
@computed get randomBtnIsDisabled() {
return !this._isGraphersSet || this.numAvailableRowsForSelectedUser <= 1
}
@computed get grapherBounds() {
let bounds
if (this.previewMode === "mobile") {
bounds = new Bounds(0, 0, 360, 500)
} else {
if (this.desktopPreviewSize === "small") {
bounds = new Bounds(0, 0, 600, 450)
} else if (this.desktopPreviewSize === "normal") {
bounds = new Bounds(0, 0, 800, 600)
} else {
bounds = new Bounds(0, 0, 1200, 900)
}
}
return bounds
}
@computed get rowNumValid() {
return Math.max(
Math.min(this.rowNum, this.numAvailableRowsForSelectedUser),
1
)
}
@computed get updateButtonsIsDisabled() {
return !this._isGraphersSet
}
@computed get approveButtonIsDisabled() {
return (
this.updateButtonsIsDisabled ||
(this.currentSuggestedChartRevision &&
!this.currentSuggestedChartRevision.canApprove)
)
}
@computed get rejectButtonIsDisabled() {
return (
this.updateButtonsIsDisabled ||
(this.currentSuggestedChartRevision &&
!this.currentSuggestedChartRevision.canReject)
)
}
@computed get flagButtonIsDisabled() {
return (
this.updateButtonsIsDisabled ||
(this.currentSuggestedChartRevision &&
!this.currentSuggestedChartRevision.canFlag)
)
}
@computed get listMode() {
const { suggestedChartRevisionId } = this.props
return !suggestedChartRevisionId
}
@action.bound async refresh() {
console.log("refresh")
this.clearDecisionReasonInput()
await this.fetchGraphers()
await this.fetchRefs()
}
@computed get currentSuggestedChartRevision() {
return this.availableRevisionsForCurrentUser?.[this.offset]
}
@action.bound async fetchGraphers() {
console.log("fetchGraphers 1")
const { admin } = this.context
const json = await admin.getJSON("/api/suggested-chart-revisions", {
status:
this.listMode && this.showPendingOnly
? SuggestedChartRevisionStatus.pending
: null,
sortBy: this.sortBy,
sortOrder: this.sortOrder,
})
console.log("fetchGraphers 2")
runInAction(() => {
this.suggestedChartRevisions =
json.suggestedChartRevisions as SuggestedChartRevisionSerialized[]
})
console.log("fetchGraphers 3")
this.decisionReasonInput = this.currentSuggestedChartRevision
? this.currentSuggestedChartRevision.decisionReason ?? ""
: ""
void this.rerenderGraphers()
console.log("fetchGraphers 4")
}
@action.bound async rerenderGraphers() {
console.log("rerenderGraphers 1")
this._isGraphersSet = false
setTimeout(() => {
if (this.currentSuggestedChartRevision) {
this._isGraphersSet = true
}
}, 0)
}
@action.bound async fetchRefs() {
console.log("fetchRefs 1")
const chartId = this.currentSuggestedChartRevision?.chartId
const { admin } = this.context
const json =
chartId === undefined
? {}
: await admin.getJSON(`/api/charts/${chartId}.references.json`)
this.chartReferences = json.references
console.log("fetchRefs 2")
}
@action.bound onApproveSuggestedChartRevision() {
console.log("WE GETTING CLOSER 0A")
void this.updateSuggestedChartRevision(
SuggestedChartRevisionStatus.approved,
this.decisionReasonInput
)
}
@action.bound onRejectSuggestedChartRevision() {
console.log("WE GETTING CLOSER 0R")
void this.updateSuggestedChartRevision(
SuggestedChartRevisionStatus.rejected,
this.decisionReasonInput
)
}
@action.bound onFlagSuggestedChartRevision() {
console.log("WE GETTING CLOSER 0F")
void this.updateSuggestedChartRevision(
SuggestedChartRevisionStatus.flagged,
this.decisionReasonInput
)
}
@action.bound async updateSuggestedChartRevision(
status: SuggestedChartRevisionStatus,
decisionReason: string | undefined
) {
this._isGraphersSet = false
if (!this.currentSuggestedChartRevision) return
const { admin } = this.context
const suggestedConfig: object =
this.currentSuggestedChartRevision?.suggestedConfig
const data = { suggestedConfig, status, decisionReason }
await admin.requestJSON(
`/api/suggested-chart-revisions/${this.currentSuggestedChartRevision.id}/update`,
data,
"POST"
)
// KLUDGE to prevent error that otherwise occurs when this.refresh() is
// called when the user is viewing the very last suggested revision.
// if (status !== SuggestedChartRevisionStatus.pending) {
// this.numTotalRows -= 1
// }
this.disableChatGPT()
void this.refresh()
}
@action.bound updateChartConfigWithGPT() {
if (this.currentSuggestedChartRevision) {
// Get suggestions
const suggestions =
this.currentSuggestedChartRevision?.experimental?.["gpt"]?.[
"suggestions"
]
if (suggestions !== undefined) {
// Set title
const title = suggestions?.[this.gptNum]?.["title"]
this.currentSuggestedChartRevision.suggestedConfig.title = title
// Set subtitle
const subtitle = suggestions?.[this.gptNum]?.["subtitle"]
this.currentSuggestedChartRevision.suggestedConfig.subtitle =
subtitle
this.gptNumDisp = this.gptNum + 1
this.gptNum = this.gptNumDisp % suggestions?.length || 1
this.usingGPT = true
}
}
void this.rerenderGraphers()
}
@action.bound getGPTModelNameUsed(): string | undefined {
const experimental = this.currentSuggestedChartRevision?.experimental
const suggestions = experimental?.gpt?.suggestions
if (
suggestions?.every(
(suggestion) =>
suggestion.title !== undefined &&
suggestion.subtitle !== undefined
) &&
experimental?.gpt?.model
) {
console.log("GPT suggestions are available!")
return experimental.gpt.model
}
console.log("NO GPT FIELD")
return undefined
}
@action.bound resetChartConfigWithGPT() {
this.disableChatGPT()
void this.refresh()
}
@action.bound disableChatGPT() {
this.gptNum = 0
this.gptNumDisp = 1
this.usingGPT = false
}
@action.bound onFirst() {
if (!this.prevBtnIsDisabled) {
this.disableChatGPT()
this.rowNum = 1
void this.refresh()
}
}
@action.bound onPrev() {
if (!this.prevBtnIsDisabled) {
this.disableChatGPT()
this.rowNum = this.rowNumValid - 1
void this.refresh()
}
}
@action.bound onNext() {
if (!this.nextBtnIsDisabled) {
this.disableChatGPT()
this.rowNum = this.rowNumValid + 1
void this.refresh()
}
}
@action.bound onLast() {
if (!this.nextBtnIsDisabled) {
this.disableChatGPT()
this.rowNum = this.numAvailableRowsForSelectedUser
void this.refresh()
}
}
@action.bound onRandom() {
if (!this.randomBtnIsDisabled) {
this.disableChatGPT()
this.rowNum = Math.floor(
Math.random() * this.numAvailableRowsForSelectedUser + 1
)
void this.refresh()
}
}
@action.bound onDecisionReasonInput(input: string) {
this.decisionReasonInput = input
}
@action.bound clearDecisionReasonInput() {
this.decisionReasonInput = ""
}
@action.bound onRowNumInput(input: number | undefined) {
if (input === undefined || input === null) {
return
}
this.rowNum = input
setTimeout(() => {
void this.refresh()
}, 100)
}
@action.bound onChangeDesktopPreviewSize(value: string) {
console.log("onChangeDesktopPreviewSize")
this.desktopPreviewSize = value
void this.rerenderGraphers()
}
@action.bound onChangePreviewSvgOrJson(value: string) {
console.log("onChangePreviewSvgOrJson")
this.previewSvgOrJson = value
void this.rerenderGraphers()
}
@action.bound onSortByChange(selected: any) {
this.sortBy = selected.value
void this.refresh()
}
@action.bound onSortOrderChange(value: SortOrder) {
this.sortOrder = value
void this.refresh()
}
@action.bound onToggleShowPendingOnly(value: boolean) {
this.showPendingOnly = value
void this.refresh()
}
@action.bound onToggleShowExistingChart(value: boolean) {
this.showExistingChart = value
// this.refresh()
}
@action.bound onToggleShowReadme() {
this.showReadme = !this.showReadme
}
@action.bound onToggleShowSettings() {
this.showSettings = !this.showSettings
}
componentDidMount() {
void this.refresh().then(() => {
this.admin.loadingIndicatorSetting = "off"
})
}
render() {
return (
<AdminLayout
title="Approval tool for suggested chart revisions"
noSidebar
>
<main className="SuggestedChartRevisionApproverPage">
{/* Render tabs with content */}
{this.renderContent()}
</main>
</AdminLayout>
)
}
renderContent() {
// Render all tabs and their content
const { ALL_TABS, activeTab } = this
return (
<div>
<div>
<ul className="nav nav-tabs">
{Object.entries(ALL_TABS).map(([tab, displayName]) => (
<li key={tab} className="nav-item">
<a
className={
"nav-link" +
(tab === activeTab ? " active" : "")
}
onClick={action(
() =>
(this.activeTab =
tab as keyof typeof ALL_TABS)
)}
>
{displayName}
</a>
</li>
))}
</ul>
</div>
<div className="sidebar-content">
{match(activeTab)
.with("approval", () => this.renderApprovalTool())
.with("readme", () => this.renderReadme())
.with("settings", () => this.renderSettings())
.otherwise(() => null)}
</div>
</div>
)
}
@computed get availableUsers(): UserSelectOption[] {
const availableUserAccordingToRevisions =
this.suggestedChartRevisions?.map((revision) => ({
userId: revision.createdById,
userName: revision.createdByFullName,
})) ?? []
const merged = uniqBy(
[
...this._cacheAvailableUsers,
...availableUserAccordingToRevisions,
],
(user) => user.userId
)
this._cacheAvailableUsers = merged
return merged
}
@computed get availableRevisionsForCurrentUser() {
console.log(this.currentlyActiveUserId)
if (this.currentlyActiveUserId === undefined)
return this.suggestedChartRevisions
return this.suggestedChartRevisions?.filter(
(revision) => revision.createdById === this.currentlyActiveUserId
)
}
@computed get numAvailableRowsForSelectedUser() {
return this.availableRevisionsForCurrentUser?.length ?? 0
}
renderApprovalTool() {
// Render the approval tool
return (
<div>
{this.renderUserMenu()}
{this.numAvailableRowsForSelectedUser > 0 || !this.listMode ? (
<React.Fragment>
{this.renderGraphers()}
{this.renderControls()}
{this.renderMeta()}
</React.Fragment>
) : (
<div
style={{
marginTop: "2rem",
padding: "1rem",
width: "50%",
border: "1px solid #ccc",
backgroundColor: "#FFF5D4",
boxShadow: "0 0 1px rgba(0,0,0,0.2)",
}}
>
<p>
⚠️ <b>0 pending chart revisions found.</b> All
suggested chart revisions have already been
approved, flagged, or rejected.
</p>
<p>
If you wish to see all suggested chart revisions,
either uncheck the{" "}
<i>Show "pending" revisions only</i> box in the
Settings tab or{" "}
<Link to="/suggested-chart-revisions">
click here
</Link>{" "}
to view a complete list of suggested chart
revisions.
</p>
</div>
)}
</div>
)
}
@action.bound onCurrentlyActiveUserChange(
event: React.ChangeEvent<HTMLSelectElement>
) {
runInAction(() => {
this.currentlyActiveUserId =
event.currentTarget.value === "-1"
? undefined
: parseInt(event.currentTarget.value)
this.rowNum = 1
})
void this.refresh()
}
renderUserMenu() {
const userOptions = [
{ userName: "All users", userId: -1 },
...this.availableUsers,
]
return (
<React.Fragment>
<label htmlFor="size">Show revisions from user:</label>
<select
onChange={this.onCurrentlyActiveUserChange}
value={this.currentlyActiveUserId ?? -1}
style={{
// marginTop: "0.5rem",
// marginBottom: "0.5rem",
margin: "1rem 0 0 1rem",
padding: "0.5rem",
border: "1px solid #ccc",
borderRadius: "4px",
fontSize: "1rem",
// backgroundColor: "white",
color: "#555",
}}
>
{userOptions.map((user) => (
<option key={user.userId} value={user.userId}>
{user.userName}
</option>
))}
</select>
</React.Fragment>
)
}
renderGraphers() {
// Render both charts next to each other
console.log("renderGraphers")
const gpt_model_name = this.getGPTModelNameUsed()
return (
<React.Fragment>
<div className="charts-view">
{/* Original chart */}
<div
className="chart-view"
style={{
height: this.grapherBounds.height + 10,
width: this.grapherBounds.width,
}}
>
{this.currentSuggestedChartRevision && (
<React.Fragment>
<div
className="header"
style={{
paddingBottom: "1rem",
display: "flex",
justifyContent: "flex-start",
}}
>
<Tippy content="This is what the chart looked like when the suggested revision was created.">
<h3 className="grapherChart">
Original
</h3>
</Tippy>
<span
className="text-muted"
style={{ padding: "0.25rem" }}
>
{`(#${this.currentSuggestedChartRevision.chartId}, v${this.currentSuggestedChartRevision.originalConfig.version})`}
</span>
<Link
className="btn btn-outline-secondary"
to={`/charts/${this.currentSuggestedChartRevision.chartId}/edit`}
target="_blank"
rel="noreferrer"
title="Edit original chart in a new tab"
>
Edit{" "}
<FontAwesomeIcon
icon={faExternalLinkAlt}
/>
</Link>
</div>
</React.Fragment>
)}
{this._isGraphersSet &&
this.currentSuggestedChartRevision &&
this.renderGrapher(
this.currentSuggestedChartRevision
.originalConfig
)}
</div>
{this.showExistingChart && (
<div
className="chart-view"
style={{
height: this.grapherBounds.height + 10,
width: this.grapherBounds.width,
}}
>
{this.currentSuggestedChartRevision && (
<React.Fragment>
<div
className="header"
style={{
paddingBottom: "1rem",
display: "flex",
justifyContent: "flex-start",
}}
>
<Tippy content="This is what the chart looks like right now on the OWID website.">
<h3 className="grapherChart">
Existing
</h3>
</Tippy>
<span className="text-muted">
{`(#${this.currentSuggestedChartRevision.chartId}, V${this.currentSuggestedChartRevision.existingConfig.version})`}
</span>
<Link
className="btn btn-outline-secondary"
to={`/charts/${this.currentSuggestedChartRevision.chartId}/edit`}
target="_blank"
rel="noreferrer"
title="Edit existing chart in a new tab"
>
Edit{" "}
<FontAwesomeIcon
icon={faExternalLinkAlt}
/>
</Link>
</div>
{/* <p
className="text-muted"
style={{ fontWeight: 300 }}
>
This is what the chart looks like right now on the OWID website.
</p> */}
</React.Fragment>
)}
{this._isGraphersSet &&
this.currentSuggestedChartRevision &&
this.renderGrapher(
this.currentSuggestedChartRevision
.existingConfig
)}
</div>
)}
{/* Suggested chart */}
<div
className="chart-view"
style={{
height: this.grapherBounds.height + 10,
width: this.grapherBounds.width,
}}
>
{this.currentSuggestedChartRevision && (
<React.Fragment>
<div
className="header"
style={{
paddingBottom: "1rem",
display: "flex",
justifyContent: "space-between",
}}
>
{/* Title and link to edit */}
<div
style={{
display: "flex",
justifyContent: "flex-start",
}}
>
<Tippy content="This is what the chart will look like if the suggested revision is approved.">
<h3 className="grapherChart">
Suggested
</h3>
</Tippy>
<span className="text-muted">
{/* {`(#${this.currentSuggestedChartRevision.chartId}, V${this.currentSuggestedChartRevision.suggestedConfig.version})`} */}
</span>
<Link
className="btn btn-outline-secondary"
to={`/charts/${
this
.currentSuggestedChartRevision
.chartId
}/edit/${Base64.encode(
JSON.stringify(
this
.currentSuggestedChartRevision
.suggestedConfig
)
)}`}
target="_blank"
rel="noreferrer"
title="Edit chart in a new tab"
>
Edit as chart{" "}
{
this
.currentSuggestedChartRevision
.chartId
}{" "}
<FontAwesomeIcon
icon={faExternalLinkAlt}
/>
</Link>
</div>
{/* GPT section */}
<div
style={{
paddingRight: "1rem",
display: "flex",
justifyContent: "flex-start",
}}
>
{/* <Tippy content="This is what the chart looked like when the suggested revision was created."> */}
<button
className="btn btn-info"
onClick={
this.updateChartConfigWithGPT
}
title="This is an experimental feature! It will replace the title and subtitle of the suggested chart with a new suggestion. You can go back to the original settings clicking on 'Reset'."
disabled={
gpt_model_name === undefined
}
>
<FontAwesomeIcon
icon={faMagicWandSparkles}
/>{" "}
{
gpt_model_name === undefined
? "chatGPT unavailable"
: gpt_model_name //{this.usingGPT? ` #${this.gptNumDisp}` : ""}
}
{this.usingGPT
? ` #${this.gptNumDisp}`
: ""}
</button>
{/* </Tippy> */}
<button
className="btn btn-link btn-sm"
onClick={
this.resetChartConfigWithGPT
}
title="Reset to original suggested configuration"
>
Reset
</button>
</div>
</div>
</React.Fragment>
)}
{this._isGraphersSet &&
this.currentSuggestedChartRevision &&
this.renderGrapher(
this.currentSuggestedChartRevision
.suggestedConfig
)}
</div>
</div>
</React.Fragment>
)
}
renderGrapher(grapherConfig: any) {
console.log("renderGrapher")
return (
<div>
{this.previewSvgOrJson === "json" ? (
<div
className="json-view"
style={{
height: this.grapherBounds.height * 0.9,
maxWidth: this.grapherBounds.width,
}}
>
<pre>
<code>
{JSON.stringify(grapherConfig, null, 2)}
</code>
</pre>
</div>
) : (
<figure
data-grapher-src
style={{
filter:
this.simulateVisionDeficiency &&
`url(#${this.simulateVisionDeficiency.id})`,
}}
>
<Grapher
{...{
...grapherConfig,
bounds: this.grapherBounds,
dataApiUrlForAdmin:
this.context.admin.settings
.DATA_API_FOR_ADMIN_UI, // passed this way because clientSettings are baked and need a recompile to be updated
}}
/>
</figure>
)}
</div>
)
}
renderControls() {
// Render controls on how to navigate the approval
return (
<div className="controls">
{this.renderControlsNotes()}
{this.renderControlsButtons()}
{this.renderControlsNumberOfRevisions()}
</div>
)
}
renderControlsNotes() {
// Render textarea in the controls block
return (
<TextAreaField
label="Notes"
placeholder="e.g. why are you rejecting this suggested revision?"
value={this.decisionReasonInput}
onValue={this.onDecisionReasonInput}
disabled={!this._isGraphersSet}
rows={1}
/>
)
}
renderControlsButtons() {
// Render buttons in controls section
return (
<div className="buttons">
{this.listMode && (
<React.Fragment>
<button
className="btn btn-secondary"
onClick={this.onFirst}
title="Go to first suggestion"
disabled={this.prevBtnIsDisabled}
aria-disabled={this.prevBtnIsDisabled}
style={{
pointerEvents: this.prevBtnIsDisabled
? "none"
: undefined,
}}
>
<FontAwesomeIcon icon={faAngleDoubleLeft} />
</button>
<button
className="btn btn-secondary"
onClick={this.onPrev}
title="Go to previous suggestion"
disabled={this.prevBtnIsDisabled}
aria-disabled={this.prevBtnIsDisabled}
style={{
pointerEvents: this.prevBtnIsDisabled
? "none"
: undefined,
}}
>
<FontAwesomeIcon icon={faAngleLeft} />
</button>
</React.Fragment>
)}
<button
className="btn btn-danger btn-lg"
onClick={this.onRejectSuggestedChartRevision}
title="Reject the suggestion, keeping the original chart as it is"
disabled={this.rejectButtonIsDisabled}
aria-disabled={this.rejectButtonIsDisabled}
style={{
pointerEvents: this.rejectButtonIsDisabled
? "none"
: undefined,
}}
>
{/* <SuggestedChartRevisionStatusIcon
status={SuggestedChartRevisionStatus.rejected}
setColor={false}
/>{" "} */}
Reject
</button>
<button
className="btn btn-light btn-lg"
onClick={this.onFlagSuggestedChartRevision}
title="Flag the suggestion for further inspection, keeping the original chart as it is"
disabled={this.flagButtonIsDisabled}
aria-disabled={this.flagButtonIsDisabled}
style={{
pointerEvents: this.flagButtonIsDisabled
? "none"
: undefined,
}}
>
{/* <SuggestedChartRevisionStatusIcon
status={SuggestedChartRevisionStatus.flagged}
setColor={false}
/>{" "} */}
Flag
</button>
<button
className="btn btn-success btn-lg"
onClick={this.onApproveSuggestedChartRevision}
title="Approve the suggestion, replacing the original chart with the suggested chart (also republishes the chart)"
disabled={this.approveButtonIsDisabled}
aria-disabled={this.approveButtonIsDisabled}
style={{
pointerEvents: this.approveButtonIsDisabled
? "none"
: undefined,