Skip to content

Commit

Permalink
Merge pull request #2700 from glific/feature/translation-flag
Browse files Browse the repository at this point in the history
Added flag for auto translation
  • Loading branch information
mdshamoon authored Jan 16, 2024
2 parents bc61350 + 9030e71 commit 2f36c76
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
26 changes: 15 additions & 11 deletions src/components/floweditor/FlowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { DialogBox } from 'components/UI/DialogBox/DialogBox';
import { setNotification } from 'common/notification';
import { PUBLISH_FLOW, RESET_FLOW_COUNT } from 'graphql/mutations/Flow';
import { EXPORT_FLOW, GET_FLOW_DETAILS, GET_FREE_FLOW } from 'graphql/queries/Flow';
import { setAuthHeaders } from 'services/AuthService';
import { getOrganizationServices, setAuthHeaders } from 'services/AuthService';
import { SideDrawerContext } from 'context/session';
import { Loading } from 'components/UI/Layout/Loading/Loading';
import Track from 'services/TrackService';
Expand Down Expand Up @@ -48,6 +48,7 @@ export const FlowEditor = () => {
const [currentEditDialogBox, setCurrentEditDialogBox] = useState(false);
const [dialogMessage, setDialogMessage] = useState('');
const { drawerOpen } = useContext(SideDrawerContext);
const isTranslationEnabled = getOrganizationServices('autoTranslationEnabled');

let modal = null;
let dialog = null;
Expand Down Expand Up @@ -420,16 +421,19 @@ export const FlowEditor = () => {
>
<ResetFlowIcon /> Reset flow counts
</Button>
<Button
className={styles.Button}
variant="outlined"
color="primary"
data-testid="translateFlow"
onClick={() => setShowTranslateFlowModal(true)}
aria-hidden="true"
>
Translation
</Button>

{isTranslationEnabled && (
<Button
className={styles.Button}
variant="outlined"
color="primary"
data-testid="translateFlow"
onClick={() => setShowTranslateFlowModal(true)}
aria-hidden="true"
>
Translation
</Button>
)}
</div>
<div id="flow" />
{loading && <Loading showTip />}
Expand Down
4 changes: 4 additions & 0 deletions src/containers/Flow/FlowTranslation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export const FlowTranslation = ({ flowId, setDialog, loadFlowEditor }: FlowTrans
setNotification(inlineFlowLocalization.errors[0].message, 'warning');
}
},
onError: () => {
setDialog(false);
setNotification(t('An error occured while translating flows.'));
},
});

const [exportFlowTranslations, { loading: exportLoad }] = useLazyQuery(
Expand Down
1 change: 1 addition & 0 deletions src/graphql/queries/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const GET_ORGANIZATION_SERVICES = gql`
query organizationServices {
organizationServices {
dialogflow
autoTranslationEnabled
googleCloudStorage
flowUuidDisplay
rolesAndPermission
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,5 +441,6 @@
"Request JSON": "Request JSON",
"Response JSON": "Response JSON",
"Webhook Logs": "Webhook Logs",
"Translate": "Translate"
"Translate": "Translate",
"An error occured while translating flows.": "An error occured while translating flows."
}
11 changes: 10 additions & 1 deletion src/services/AuthService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ interface RegisterRequest {
token?: string;
}

type ServiceType =
| 'dialogflow'
| 'autoTranslationEnabled'
| 'googleCloudStorage'
| 'flowUuidDisplay'
| 'rolesAndPermission'
| 'contactProfileEnabled'
| 'ticketingEnabled';

// get the current authentication session
export const getAuthSession = (element?: string) => {
const session = localStorage.getItem('glific_session');
Expand Down Expand Up @@ -172,7 +181,7 @@ export const setOrganizationServices = (services: string) => {
localStorage.setItem('organizationServices', services);
};

export const getOrganizationServices = (service: string) => {
export const getOrganizationServices = (service: ServiceType) => {
let services: any = localStorage.getItem('organizationServices');
if (!services) return null;
services = JSON.parse(services);
Expand Down

0 comments on commit 2f36c76

Please sign in to comment.