Skip to content

Commit b5a5f80

Browse files
committed
refactor modified indication
1 parent 13c2a4b commit b5a5f80

File tree

11 files changed

+96
-114
lines changed

11 files changed

+96
-114
lines changed

packages/selenium-ide/src/neo/components/Suite/index.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ class Suite extends React.Component {
124124
onClick={this.handleClick}
125125
>
126126
<span className="si-caret" />
127-
<span className="title">{this.props.suite.name}</span>
127+
<span
128+
className={classNames('title', {
129+
changed: this.props.suite.modified,
130+
})}
131+
>
132+
{this.props.suite.name}
133+
</span>
128134
</a>
129135
)}
130136
{listMenu}

packages/selenium-ide/src/neo/components/Suite/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
overflow: hidden;
2222
}
2323

24+
.project > a .title.changed::after {
25+
content: '*';
26+
}
27+
2428
.project > a .si-caret {
2529
font-size: 10px;
2630
color: #505050;

packages/selenium-ide/src/neo/components/TestList/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default class TestList extends Component {
7373
PlaybackState.stackCaller.id === test.id &&
7474
PlaybackState.paused
7575
}
76-
changed={UiState.getTestState(test).modified}
76+
changed={test.modified}
7777
selectTest={UiState.selectTest}
7878
moveSelectionUp={() => {
7979
UiState.selectTestByIndex(index - 1)
@@ -107,7 +107,7 @@ export default class TestList extends Component {
107107
PlaybackState.stackCaller.id === test.id &&
108108
PlaybackState.paused
109109
}
110-
changed={UiState.getTestState(test).modified}
110+
changed={test.modified}
111111
selectTest={UiState.selectTest}
112112
removeTest={
113113
this.props.removeTest
@@ -145,7 +145,7 @@ export default class TestList extends Component {
145145
PlaybackState.stackCaller.id === test.id &&
146146
PlaybackState.paused
147147
}
148-
changed={UiState.getTestState(test).modified}
148+
changed={test.modified}
149149
selectTest={UiState.selectTest}
150150
renameTest={this.props.renameTest}
151151
duplicateTest={() => {

packages/selenium-ide/src/neo/components/TestTable/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export default class TestTable extends React.Component {
6060
this.newCommand = undefined
6161
}
6262
scrollToLastPos() {
63-
if (UiState.selectedTest.state.scrollY) {
64-
this.node.scrollTop = UiState.selectedTest.state.scrollY
63+
if (UiState.selectedTest.test.scrollY) {
64+
this.node.scrollTop = UiState.selectedTest.test.scrollY
6565
} else {
6666
this.node.scrollTop = 0
6767
}
@@ -78,7 +78,7 @@ export default class TestTable extends React.Component {
7878
}
7979
}
8080
handleScroll() {
81-
UiState.selectedTest.state.scrollY = this.node.scrollTop
81+
UiState.selectedTest.test.scrollY = this.node.scrollTop
8282
}
8383
render() {
8484
if (this.props.commands)

packages/selenium-ide/src/neo/models/Suite.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
import { action, observable, computed } from 'mobx'
18+
import { action, observable, computed, reaction } from 'mobx'
1919
import uuidv4 from 'uuid/v4'
2020
import naturalCompare from 'string-natural-compare'
2121
import TestCase from './TestCase'
@@ -34,10 +34,18 @@ export default class Suite {
3434
persistSession = false
3535
@observable
3636
_tests = []
37+
@observable
38+
modified = false
3739

3840
constructor(id = uuidv4(), name = 'Untitled Suite') {
3941
this.id = id
4042
this.name = name
43+
this.changeTestsDisposer = reaction(
44+
() => this._tests.length,
45+
() => {
46+
this.modified = true
47+
}
48+
)
4149
this.containsTest = this.containsTest.bind(this)
4250
this.export = this.export.bind(this)
4351
}
@@ -56,6 +64,7 @@ export default class Suite {
5664
@action.bound
5765
setName(name) {
5866
this.name = name
67+
this.modified = true
5968
}
6069

6170
@action.bound

packages/selenium-ide/src/neo/models/TestCase.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
import { action, observable } from 'mobx'
18+
import { action, observable, reaction } from 'mobx'
1919
import uuidv4 from 'uuid/v4'
2020
import Command from './Command'
2121

@@ -26,11 +26,30 @@ export default class TestCase {
2626
@observable
2727
commands = []
2828
nameDialogShown = false
29+
@observable
30+
modified = false
31+
@observable
32+
selectedCommand = null
33+
@observable
34+
scrollY = null
2935

3036
constructor(id = uuidv4(), name = 'Untitled Test') {
3137
this.id = id
3238
this.name = name
39+
this.changeDisposer = reaction(
40+
() =>
41+
this.commands.map(({ command, target, targets, value }) => ({
42+
command,
43+
target,
44+
targets,
45+
value,
46+
})),
47+
() => {
48+
this.modified = true
49+
}
50+
)
3351
this.export = this.export.bind(this)
52+
this.dispose = this.dispose.bind(this)
3453
}
3554

3655
@action.bound
@@ -50,6 +69,7 @@ export default class TestCase {
5069
@action.bound
5170
setName(name) {
5271
this.name = name
72+
this.modified = true
5373
}
5474

5575
@action.bound
@@ -138,6 +158,10 @@ export default class TestCase {
138158
}
139159
}
140160

161+
dispose() {
162+
this.changeDisposer()
163+
}
164+
141165
@action
142166
static fromJS = function(jsRep) {
143167
const test = new TestCase(jsRep.id)

packages/selenium-ide/src/neo/side-effects/modify.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

packages/selenium-ide/src/neo/stores/domain/ProjectStore.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
import { action, observable, computed, toJS } from 'mobx'
18+
import { action, observable, computed, reaction, toJS } from 'mobx'
1919
import uuidv4 from 'uuid/v4'
2020
import naturalCompare from 'string-natural-compare'
2121
import TestCase from '../../models/TestCase'
2222
import Suite from '../../models/Suite'
23-
import modify from '../../side-effects/modify'
2423
import { VERSIONS } from '../../IO/migrate'
2524

2625
export default class ProjectStore {
@@ -45,8 +44,28 @@ export default class ProjectStore {
4544

4645
constructor(name = 'Untitled Project') {
4746
this.name = name
48-
modify(this)
47+
this.changedTestDisposer = reaction(
48+
() => this._tests.find(({ modified }) => modified),
49+
modified => {
50+
if (modified) this.setModified(true)
51+
}
52+
)
53+
this.changeTestsDisposer = reaction(
54+
() => this._tests.length,
55+
() => this.setModified(true)
56+
)
57+
this.changedSuiteDisposer = reaction(
58+
() => this._suites.find(({ modified }) => modified),
59+
modified => {
60+
if (modified) this.setModified(true)
61+
}
62+
)
63+
this.changeSuitesDisposer = reaction(
64+
() => this._suites.length,
65+
() => this.setModified(true)
66+
)
4967
this.toJS = this.toJS.bind(this)
68+
this.dispose = this.dispose.bind(this)
5069
}
5170

5271
@computed
@@ -67,13 +86,17 @@ export default class ProjectStore {
6786
@action.bound
6887
setUrl(url) {
6988
this.url = url
89+
this.setModified(true)
7090
}
7191

7292
@action.bound
7393
addUrl(urlToAdd) {
7494
if (urlToAdd) {
7595
const url = new URL(urlToAdd).href
76-
if (!this._urls.find(u => u === url)) this._urls.push(url)
96+
if (!this._urls.find(u => u === url)) {
97+
this._urls.push(url)
98+
this.setModified(true)
99+
}
77100
}
78101
}
79102

@@ -85,14 +108,12 @@ export default class ProjectStore {
85108
@action.bound
86109
changeName(name) {
87110
this.name = name.replace(/<[^>]*>/g, '') // firefox adds unencoded html elements to the string, strip them
111+
this.setModified(true)
88112
}
89113

90114
@action.bound
91115
setModified(modified = true) {
92116
this.modified = modified
93-
if (!modified) {
94-
modify(this)
95-
}
96117
}
97118

98119
@action.bound
@@ -197,6 +218,13 @@ export default class ProjectStore {
197218
this.setModified(false)
198219
}
199220

221+
dispose() {
222+
this.changeTestsDisposer()
223+
this.changedTestDisposer()
224+
this.changeSuitesDisposer()
225+
this.changedSuiteDisposer()
226+
}
227+
200228
toJS() {
201229
return toJS({
202230
id: this.id,

packages/selenium-ide/src/neo/stores/seed.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,5 +605,7 @@ export default function seed(store, numberOfSuites = 0) {
605605

606606
store.changeName('seed project')
607607

608+
UiState.saved()
609+
608610
return store
609611
}

packages/selenium-ide/src/neo/stores/view/TestState.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)