-
Notifications
You must be signed in to change notification settings - Fork 57
/
MinionEffectsTab.tsx
81 lines (72 loc) · 2.26 KB
/
MinionEffectsTab.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
import * as React from "react";
import { connect } from "react-redux";
import { AI_EFFECT_IDS } from "oni-save-parser";
import { compare } from "@/math";
import { Intent } from "@/style";
import mapStateToProps, { StateProps } from "./derived-state";
import mapDispatchToProps, { DispatchProps } from "./events";
import NonIdealState from "@/components/NonIdealState";
import DataTable, {
DataTableColumn,
DataTableRow
} from "@/components/DataTable";
import NullableInput from "@/components/NullableInput";
import NumericInput from "@/components/NumericInput";
type Props = StateProps & DispatchProps;
class MinionEffectsTab extends React.Component<Props> {
render() {
const { effects, onSetEffectData } = this.props;
if (!effects) {
return (
<NonIdealState intent={Intent.Dangerous} header="No Data">
No effects data could be found on this duplicant.
</NonIdealState>
);
}
const data = AI_EFFECT_IDS.map(effectId => {
const effectIndex = effects.findIndex(x => x.id === effectId);
const effect = effectIndex > -1 ? effects[effectIndex] : null;
return {
effectId,
effectIndex,
timeRemaining: effect ? effect.timeRemaining : null
};
});
const columns: DataTableColumn[] = [
{
Header: "Effect",
sortable: true,
filterable: true,
accessor: "effectId"
},
{
Header: "Time Remaining",
sortable: true,
filterable: false,
id: "level",
accessor: x => x,
Cell: (row: DataTableRow<typeof data[0]>) => (
<NullableInput
value={row.value.timeRemaining}
onCommit={onSetEffectData.bind(
null,
row.value.effectId,
row.value.effectIndex
)}
defaultValue={15000}
renderInput={props => (
<NumericInput precision="single" minValue={0} {...props} />
)}
/>
),
sortMethod: (a: typeof data[0], b: typeof data[0]) =>
compare(a.timeRemaining || 0, b.timeRemaining || 0)
}
];
return <DataTable height="100%" columns={columns} data={data} />;
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(MinionEffectsTab);