Skip to content

Commit 38ebdfc

Browse files
Merge branch 'xal_proxy' into staging
2 parents eefd61a + 9cc216d commit 38ebdfc

2 files changed

Lines changed: 115 additions & 2 deletions

File tree

src/components/BanModal/index.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export const queryUsers = gql`
2020
intl_name
2121
email
2222
is_active
23+
additional_metadata {
24+
allowed_sync
25+
}
2326
}
2427
}
2528
`;
@@ -32,11 +35,20 @@ const activateDeactivateUserMutation = gql`
3235
}
3336
`;
3437

38+
const allowSyncDictsMutation = gql`
39+
mutation allowSyncDicts($userId: Int!, $allowedSync: Boolean!) {
40+
allow_sync_dicts(user_id: $userId, allowed_sync: $allowedSync) {
41+
triumph
42+
}
43+
}
44+
`;
45+
3546
class BanModal extends React.Component {
3647
constructor(props) {
3748
super(props);
3849
this.state = { selected_user: null };
3950
this.handleActivateDeactivate = this.handleActivateDeactivate.bind(this);
51+
this.handleAllowSync = this.handleAllowSync.bind(this);
4052
}
4153

4254
handleActivateDeactivate() {
@@ -71,6 +83,39 @@ class BanModal extends React.Component {
7183
);
7284
}
7385

86+
handleAllowSync() {
87+
const user = this.state.selected_user;
88+
if (user === null) {
89+
return;
90+
}
91+
92+
const allowed_sync = user.additional_metadata.allowed_sync;
93+
const success_str = allowed_sync ? "Successfully denied synchronization" : "Successfully allowed synchronization";
94+
const error_str = allowed_sync ? "Failed to deny synchronization" : "Failed to allow synchronization";
95+
96+
const user_str = `'${user.login}' (${user.name}${user.intl_name !== user.login ? `, ${user.intl_name}` : ""})`;
97+
98+
const { refetch } = this.props.data;
99+
100+
this.props
101+
.allowSyncDicts({
102+
variables: {
103+
userId: user.id,
104+
allowedSync: !allowed_sync
105+
}
106+
})
107+
.then(
108+
() => {
109+
window.logger.suc(`${this.context(success_str)} ${user_str}.`);
110+
this.props.closeModal();
111+
refetch();
112+
},
113+
() => {
114+
window.logger.err(`${this.context(error_str)} ${user_str}!`);
115+
}
116+
);
117+
}
118+
74119
render() {
75120
const { visible, data } = this.props;
76121
if (!visible || data.loading || data.error) {
@@ -110,6 +155,18 @@ class BanModal extends React.Component {
110155
</div>
111156
</Modal.Content>
112157
<Modal.Actions>
158+
<Button
159+
disabled={this.state.selected_user === null}
160+
content={
161+
this.state.selected_user === null
162+
? this.context("Allow sync / Deny sync")
163+
: this.state.selected_user.additional_metadata.allowed_sync
164+
? this.context("Deny sync")
165+
: this.context("Allow sync")
166+
}
167+
onClick={this.handleAllowSync}
168+
className="lingvo-button-violet"
169+
/>
113170
<Button
114171
disabled={this.state.selected_user === null}
115172
content={
@@ -151,5 +208,6 @@ export default compose(
151208
dispatch => bindActionCreators({ closeModal }, dispatch)
152209
),
153210
graphql(queryUsers, { skip: props => !props.visible }),
154-
graphql(activateDeactivateUserMutation, { name: "activateDeactivateUser" })
211+
graphql(activateDeactivateUserMutation, { name: "activateDeactivateUser" }),
212+
graphql(allowSyncDictsMutation, { name: "allowSyncDicts" })
155213
)(BanModal);

src/components/PerspectiveView/index.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ const ModalContentWrapper = styled("div")`
3535
min-height: 15vh;
3636
`;
3737

38+
export const queryListChanges = gql `
39+
query listChanges(
40+
$proxy: String,
41+
$stamps: ObjectVal!
42+
) {
43+
list_changes(
44+
proxy: $proxy,
45+
stamps: $stamps
46+
) {
47+
language
48+
dictionary
49+
perspective {
50+
lexical_entries {
51+
entities
52+
}
53+
}
54+
}
55+
56+
}
57+
`;
58+
3859
export const queryPerspective = gql`
3960
query queryPerspective1($id: LingvodocID!) {
4061
perspective(id: $id) {
@@ -558,6 +579,30 @@ class P extends React.Component {
558579
});
559580
};
560581

582+
const doSync = () => {
583+
// 1. Get changes from Core,
584+
// 2. Get changes from Satellite,
585+
// 3. Display changes,
586+
// 4. Apply/Deny changes
587+
588+
const groupList = [selectedEntries];
589+
590+
mergeLexicalEntries({
591+
variables: { groupList },
592+
593+
refetchQueries: [
594+
{
595+
query: queryLexicalEntries,
596+
variables: query_args
597+
}
598+
]
599+
600+
}).then(() => {
601+
resetSelection();
602+
this.setState({ entriesTotal: entriesTotal - selectedEntries.length + 1 });
603+
});
604+
};
605+
561606
const mergeEntries = () => {
562607
const groupList = [selectedEntries];
563608

@@ -607,7 +652,8 @@ class P extends React.Component {
607652
);
608653
}
609654
/* eslint-enable no-shadow */
610-
const isAuthenticated = user && user.user.id;
655+
const isAuthenticated = user?.user?.id;
656+
const allowedSync = user?.user?.allowed_sync;
611657

612658
const isTableLanguages = JSON.stringify(id) === JSON.stringify([4839, 2]);
613659

@@ -713,6 +759,14 @@ class P extends React.Component {
713759
(mode === "publish" && isAuthenticated) ||
714760
(mode === "contributions" && isAuthenticated)) && (
715761
<div className="lingvo-perspective-buttons">
762+
{mode === "edit" && allowedSync && (
763+
<Button
764+
icon={<i className="lingvo-icon lingvo-icon_refresh" />}
765+
content={this.context("Synchronize")}
766+
onClick={doSync}
767+
className="lingvo-button-green lingvo-perspective-button"
768+
/>
769+
)}
716770
{mode === "edit" && (
717771
<Button
718772
icon={<i className="lingvo-icon lingvo-icon_add" />}
@@ -1219,5 +1273,6 @@ export default compose(
12191273
graphql(queryPerspective, {
12201274
options: { notifyOnNetworkStatusChange: true }
12211275
}),
1276+
graphql(queryListChanges, { name: "listChanges" }),
12221277
branch(({ data: { loading } }) => loading, renderComponent(Placeholder))
12231278
)(PerspectiveViewWrapper);

0 commit comments

Comments
 (0)