Skip to content

Commit

Permalink
Suggestions state
Browse files Browse the repository at this point in the history
  • Loading branch information
vmonakhov committed Feb 20, 2025
1 parent 1fe16fc commit dd568e5
Showing 1 changed file with 51 additions and 23 deletions.
74 changes: 51 additions & 23 deletions src/components/CognateAnalysisModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const languageQuery = gql`
}
`;

/*
const wordsQuery = gql`
query words(
$perspectiveId: LingvodocID!
Expand All @@ -156,6 +157,7 @@ const wordsQuery = gql`
)
}
`;
*/

const resultSuggestionsQuery = gql`
query resultSuggestions(
Expand All @@ -167,6 +169,22 @@ const resultSuggestionsQuery = gql`
}
`;

const saveSuggestionsStateMutation = gql`
mutation saveSuggestionsState(
$resultFile: String!
$suggestionsState: ObjectVal
$debugFlag: Boolean
) {
save_suggestions_state(
result_file: $resultFile
suggestions_state: $suggestionsState
debug_flag: $debugFlag
) {
triumph
}
}
`;

const computeCognateAnalysisMutation = gql`
mutation computeCognateAnalysis(
$sourcePerspectiveId: LingvodocID!
Expand Down Expand Up @@ -3107,40 +3125,29 @@ class CognateAnalysisModal extends React.Component {

const { client, resultFile } = this.props;

const {
data: {
result_suggestions: {
suggestion_list,
perspective_name_list,
transcription_count,
group_count,
source_perspective_id
}
}
} = await client.query({
const { data: { result_suggestions }} = await client.query({
query: resultSuggestionsQuery,
variables: { resultFile: resultFile }
variables: { resultFile }
});

const { source_perspective_id: perspectiveId, perspective_name_list } = result_suggestions;

const {
data: {
all_fields: allFields,
all_fields,
perspective: { columns, tree, english_status }
}
} = await client.query({
query: cognateAnalysisDataQuery,
variables: { perspectiveId: source_perspective_id }
variables: { perspectiveId }
});

this.initialize_common(allFields, columns, tree, english_status);
this.initialize_common(all_fields, columns, tree, english_status);

this.setState({
suggestion_list,
perspective_name_list,
transcription_count,
group_count,
...result_suggestions,
dictionary_count: perspective_name_list.length,
...this.handleSuggestionResult({ suggestion_list }),
...this.handleSuggestionResult({ ...result_suggestions }), // override sg_<states>
result: "",
initialized: true
});
Expand All @@ -3155,7 +3162,7 @@ class CognateAnalysisModal extends React.Component {
);
}

const { mode } = this.props;
const { mode, resultFile, saveSuggestionsState } = this.props;
const viewMode = (mode === "view_suggestions");

const {
Expand All @@ -3167,7 +3174,12 @@ class CognateAnalysisModal extends React.Component {
fileSuite,
done,
total,
estimate
estimate,
sg_select_list,
sg_state_list,
sg_count,
sg_entry_map,
debugFlag
} = this.state;

const disabledCompute = (
Expand Down Expand Up @@ -3199,6 +3211,20 @@ class CognateAnalysisModal extends React.Component {
tabIndex = "0"
closeIcon
onClose={ () => {
if (viewMode) {
saveSuggestionsState({
variables: {
resultFile,
suggestionsState: {
sg_select_list,
sg_state_list,
sg_count,
sg_entry_map
},
debugFlag
}
});
}
this.setState({ computing: false }, this.props.closeModal);
}}
dimmer open
Expand Down Expand Up @@ -3577,7 +3603,8 @@ CognateAnalysisModal.propTypes = {
computeSwadeshAnalysis: PropTypes.func.isRequired,
computeMorphCognateAnalysis: PropTypes.func.isRequired,
computeNeuroCognateAnalysis: PropTypes.func.isRequired,
computeComplexDistance: PropTypes.func.isRequired
computeComplexDistance: PropTypes.func.isRequired,
saveSuggestionsState: PropTypes.func.isRequired
};

export default compose(
Expand All @@ -3593,5 +3620,6 @@ export default compose(
graphql(computeComplexDistanceMutation, { name: "computeComplexDistance" }),
graphql(computeNeuroCognateAnalysisMutation, { name: "computeNeuroCognateAnalysis" }),
graphql(connectMutation, { name: "connectGroup" }),
graphql(saveSuggestionsStateMutation, {name: "saveSuggestionsState"}),
withApollo
)(CognateAnalysisModal);

0 comments on commit dd568e5

Please sign in to comment.