Skip to content

Commit b1b03a5

Browse files
committed
Tuned 'Connect all' functionality
1 parent 1cd5be4 commit b1b03a5

1 file changed

Lines changed: 43 additions & 23 deletions

File tree

  • src/components/CognateAnalysisModal

src/components/CognateAnalysisModal/index.js

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,10 +2811,10 @@ class CognateAnalysisModal extends React.Component {
28112811

28122812
/* Launches connection of suggestion specified by index. */
28132813

2814-
sg_connect(index, window_log_flag = true) {
2814+
async sg_connect(index, window_log_flag = true, entry_id_str_list_cur = null, sg_state_list_cur = null) {
28152815
const { suggestion_field_id, sg_select_list, sg_state_list, sg_count, sg_entry_map } = this.state;
28162816

2817-
const entry_id_str_list = Object.keys(sg_select_list[index]);
2817+
const entry_id_str_list = entry_id_str_list_cur || Object.keys(sg_select_list[index]);
28182818

28192819
const entry_id_list = entry_id_str_list.map(str2id);
28202820

@@ -2828,7 +2828,7 @@ class CognateAnalysisModal extends React.Component {
28282828
sg_count
28292829
});
28302830

2831-
this.props
2831+
await this.props
28322832
.connectGroup({
28332833
variables: {
28342834
fieldId: suggestion_field_id,
@@ -2848,7 +2848,7 @@ class CognateAnalysisModal extends React.Component {
28482848

28492849
for (const entry_id_str of entry_id_str_list) {
28502850
for (const sg_index of Object.keys(sg_entry_map[entry_id_str])) {
2851-
if (sg_state_list[sg_index] === "left") {
2851+
if ((sg_state_list_cur ? sg_state_list_cur[sg_index] : sg_state_list[sg_index]) === "left") {
28522852

28532853
delete sg_select_list[sg_index][entry_id_str];
28542854
sg_entry_map[entry_id_str][sg_index] = false;
@@ -2894,7 +2894,8 @@ class CognateAnalysisModal extends React.Component {
28942894
sg_state_list,
28952895
sg_count,
28962896
sg_entry_map,
2897-
sg_current_page
2897+
sg_current_page,
2898+
computing
28982899
} = this.state;
28992900

29002901
/* Shows current suggestion state counts. */
@@ -2985,21 +2986,23 @@ class CognateAnalysisModal extends React.Component {
29852986
// Not so good hack in the name of performance,
29862987
// we just give our state to be modified in the child compoment.
29872988

2988-
<SuggestionSelection
2989-
key={`suggestion${start_index + in_page_index}`}
2990-
perspective_index={perspective_index}
2991-
word={word}
2992-
word_entry_id={word_entry_id}
2993-
word_group={word_group}
2994-
single_list={single_list}
2995-
group_list={group_list}
2996-
index={start_index + in_page_index}
2997-
perspective_name_list={perspective_name_list}
2998-
sg_select_list={sg_select_list}
2999-
sg_state_list={sg_state_list}
3000-
sg_entry_map={sg_entry_map}
3001-
sg_connect={this.sg_connect}
3002-
/>
2989+
<div disabled={computing}>
2990+
<SuggestionSelection
2991+
key={`suggestion${start_index + in_page_index}`}
2992+
perspective_index={perspective_index}
2993+
word={word}
2994+
word_entry_id={word_entry_id}
2995+
word_group={word_group}
2996+
single_list={single_list}
2997+
group_list={group_list}
2998+
index={start_index + in_page_index}
2999+
perspective_name_list={perspective_name_list}
3000+
sg_select_list={sg_select_list}
3001+
sg_state_list={sg_state_list}
3002+
sg_entry_map={sg_entry_map}
3003+
sg_connect={this.sg_connect}
3004+
/>
3005+
</div>
30033006
)
30043007
)}
30053008

@@ -3038,14 +3041,24 @@ class CognateAnalysisModal extends React.Component {
30383041

30393042
<div style={{ marginTop: "22px", paddingBottom: "14px" }}>
30403043
<Button
3041-
content={this.context("Connect all selected")}
3044+
content={
3045+
computing ? (
3046+
<span>
3047+
{this.context("Computing")}... <Icon name="spinner" loading />
3048+
</span>
3049+
) : this.context("Connect all selected")
3050+
}
30423051
disabled={sg_count.left <= 0 || sg_count.connecting > 0}
30433052
onClick={() => {
30443053
/* Launching connections of all suggestions with enough selected lexical entries, skipping
30453054
* suggestions which would be invalidated if launched connections are successful. */
30463055

30473056
const invalid_set = {};
30483057
const already_used_set = new Set();
3058+
const sg_state_list_cur = [ ...sg_state_list ];
3059+
const promises = [];
3060+
3061+
this.setState({ computing: true });
30493062

30503063
for (let i = 0; i < suggestion_list.length; i++) {
30513064
if (sg_state_list[i] !== "left" || invalid_set.hasOwnProperty(i)) {
@@ -3059,13 +3072,20 @@ class CognateAnalysisModal extends React.Component {
30593072
continue;
30603073
}
30613074

3075+
// States are changed asynchronously so we have to change and pass
3076+
// entry_id_str_list and sg_state_list_cur as arguments every iteration
3077+
promises.push(this.sg_connect(i, false, entry_id_str_list, sg_state_list_cur));
3078+
3079+
sg_state_list_cur[i] = "processed";
3080+
30623081
for (const entry_id_str of entry_id_str_list) {
30633082
//Object.assign(invalid_set, sg_entry_map[entry_id_str]);
30643083
already_used_set.add(entry_id_str);
30653084
}
3066-
3067-
this.sg_connect(i, false);
30683085
}
3086+
3087+
Promise.all(promises).then(() => this.setState({ computing: false }));
3088+
30693089
}}
30703090
className="lingvo-button-greenest"
30713091
/>

0 commit comments

Comments
 (0)