Skip to content

Commit 80ef8c1

Browse files
authored
feat: Allow editing views (#2889)
1 parent d18cb6a commit 80ef8c1

File tree

4 files changed

+343
-32
lines changed

4 files changed

+343
-32
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import Field from 'components/Field/Field.react';
2+
import Label from 'components/Label/Label.react';
3+
import Modal from 'components/Modal/Modal.react';
4+
import React from 'react';
5+
import TextInput from 'components/TextInput/TextInput.react';
6+
7+
export default class DeleteViewDialog extends React.Component {
8+
constructor() {
9+
super();
10+
this.state = {
11+
confirmation: '',
12+
};
13+
}
14+
15+
valid() {
16+
return this.state.confirmation === this.props.name;
17+
}
18+
19+
render() {
20+
return (
21+
<Modal
22+
type={Modal.Types.DANGER}
23+
icon="warn-outline"
24+
title="Delete view?"
25+
subtitle="This action cannot be undone!"
26+
disabled={!this.valid()}
27+
confirmText="Delete"
28+
cancelText="Cancel"
29+
onCancel={this.props.onCancel}
30+
onConfirm={this.props.onConfirm}
31+
>
32+
<Field
33+
label={<Label text="Confirm this action" description="Enter the view name to continue." />}
34+
input={
35+
<TextInput
36+
placeholder="View name"
37+
value={this.state.confirmation}
38+
onChange={confirmation => this.setState({ confirmation })}
39+
/>
40+
}
41+
/>
42+
</Modal>
43+
);
44+
}
45+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import Dropdown from 'components/Dropdown/Dropdown.react';
2+
import Field from 'components/Field/Field.react';
3+
import Label from 'components/Label/Label.react';
4+
import Modal from 'components/Modal/Modal.react';
5+
import Option from 'components/Dropdown/Option.react';
6+
import React from 'react';
7+
import TextInput from 'components/TextInput/TextInput.react';
8+
import Checkbox from 'components/Checkbox/Checkbox.react';
9+
10+
function isValidJSON(value) {
11+
try {
12+
JSON.parse(value);
13+
return true;
14+
} catch {
15+
return false;
16+
}
17+
}
18+
19+
export default class EditViewDialog extends React.Component {
20+
constructor(props) {
21+
super();
22+
const view = props.view || {};
23+
this.state = {
24+
name: view.name || '',
25+
className: view.className || '',
26+
query: JSON.stringify(view.query || [], null, 2),
27+
showCounter: !!view.showCounter,
28+
};
29+
}
30+
31+
valid() {
32+
return (
33+
this.state.name.length > 0 &&
34+
this.state.className.length > 0 &&
35+
isValidJSON(this.state.query)
36+
);
37+
}
38+
39+
render() {
40+
const { classes, onConfirm, onCancel } = this.props;
41+
return (
42+
<Modal
43+
type={Modal.Types.INFO}
44+
icon="edit-solid"
45+
iconSize={40}
46+
title="Edit view?"
47+
subtitle="Update the custom query."
48+
confirmText="Save"
49+
cancelText="Cancel"
50+
disabled={!this.valid()}
51+
onCancel={onCancel}
52+
onConfirm={() =>
53+
onConfirm({
54+
name: this.state.name,
55+
className: this.state.className,
56+
query: JSON.parse(this.state.query),
57+
showCounter: this.state.showCounter,
58+
})
59+
}
60+
>
61+
<Field
62+
label={<Label text="Name" />}
63+
input={
64+
<TextInput
65+
value={this.state.name}
66+
onChange={name => this.setState({ name })}
67+
/>
68+
}
69+
/>
70+
<Field
71+
label={<Label text="Class" />}
72+
input={
73+
<Dropdown
74+
value={this.state.className}
75+
onChange={className => this.setState({ className })}
76+
>
77+
{classes.map(c => (
78+
<Option key={c} value={c}>
79+
{c}
80+
</Option>
81+
))}
82+
</Dropdown>
83+
}
84+
/>
85+
<Field
86+
label={
87+
<Label
88+
text="Query"
89+
description="An aggregation pipeline that returns an array of items."
90+
/>
91+
}
92+
input={
93+
<TextInput
94+
multiline={true}
95+
value={this.state.query}
96+
onChange={query => this.setState({ query })}
97+
/>
98+
}
99+
/>
100+
<Field
101+
label={<Label text="Show object counter" />}
102+
input={
103+
<Checkbox
104+
checked={this.state.showCounter}
105+
onChange={showCounter => this.setState({ showCounter })}
106+
/>
107+
}
108+
/>
109+
</Modal>
110+
);
111+
}
112+
}

0 commit comments

Comments
 (0)