Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup and version update #1420

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "glific-frontend",
"version": "1.5.1",
"version": "1.6.0",
"private": true,
"dependencies": {
"@absinthe/socket": "^0.2.1",
Expand Down
49 changes: 26 additions & 23 deletions src/components/floweditor/FlowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import { PUBLISH_FLOW } from '../../graphql/mutations/Flow';
import { GET_FLOW_DETAILS } from '../../graphql/queries/Flow';
import { setAuthHeaders } from '../../services/AuthService';
import { GET_ORGANIZATION_SERVICES } from '../../graphql/queries/Organization';
import { Loading } from '../UI/Layout/Loading/Loading';

declare function showFlowEditor(node: any, config: any): void;

const loadfiles = () => {
const loadfiles = (startFlowEditor: any) => {
const files: Array<HTMLScriptElement | HTMLLinkElement> = [];
const filesToLoad: any = Manifest.files;
let index = 0;
Expand All @@ -30,6 +31,11 @@ const loadfiles = () => {
if (filesToLoad[fileName].endsWith('.js')) {
index += 1;
const script = document.createElement('script');
if (index === 2) {
script.onload = () => {
startFlowEditor();
};
}
script.src = filesToLoad[fileName];
script.id = `flowEditorScript${index}`;
script.async = false;
Expand Down Expand Up @@ -150,6 +156,7 @@ export const FlowEditor = (props: FlowEditorProps) => {
const { uuid } = match.params;
const [publishDialog, setPublishDialog] = useState(false);
const [simulatorId, setSimulatorId] = useState(0);
const [loading, setLoading] = useState(true);

const config = setConfig(uuid);
const [published, setPublished] = useState(false);
Expand All @@ -163,7 +170,20 @@ export const FlowEditor = (props: FlowEditorProps) => {
let modal = null;
let dialog = null;

const [getOrganizationServices, { data: services }] = useLazyQuery(GET_ORGANIZATION_SERVICES);
const [getOrganizationServices] = useLazyQuery(GET_ORGANIZATION_SERVICES, {
onCompleted: (services) => {
const { dialogflow, googleCloudStorage } = services.organizationServices;

if (googleCloudStorage) {
config.attachmentsEnabled = true;
}
if (!dialogflow) {
config.excludeTypes.push('split_by_intent');
}
showFlowEditor(document.getElementById('flow'), config);
setLoading(false);
},
});

const [publishFlow] = useMutation(PUBLISH_FLOW, {
onCompleted: (data) => {
Expand Down Expand Up @@ -236,8 +256,9 @@ export const FlowEditor = (props: FlowEditorProps) => {

useEffect(() => {
const { fetch, xmlSend } = setAuthHeaders();
const files = loadfiles();
getOrganizationServices();
const files = loadfiles(() => {
getOrganizationServices();
});

return () => {
Object.keys(files).forEach((node: any) => {
Expand All @@ -255,25 +276,6 @@ export const FlowEditor = (props: FlowEditorProps) => {
};
}, []);

useEffect(() => {
if (services) {
// check if runtime main file is present and then load
const lastFile: HTMLScriptElement | null = document.body.querySelector('#flowEditorScript2');
if (lastFile) {
const { dialogflow, googleCloudStorage } = services.organizationServices;

if (googleCloudStorage) {
config.attachmentsEnabled = true;
}
if (!dialogflow) {
config.excludeTypes.push('split_by_intent');
}

showFlowEditor(document.getElementById('flow'), config);
}
}
}, [config, services]);

const handlePublishFlow = () => {
publishFlow({ variables: { uuid: props.match.params.uuid } });
};
Expand Down Expand Up @@ -429,6 +431,7 @@ export const FlowEditor = (props: FlowEditorProps) => {
) : null}
</div>
<div id="flow" />
{loading && <Loading />}
</div>
</>
);
Expand Down
6 changes: 4 additions & 2 deletions src/containers/Consulting/ConsultingList/ConsultingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
GET_CONSULTING_HOURS,
GET_CONSULTING_HOURS_COUNT,
} from '../../../graphql/queries/Consulting';
import { DELETE_CONSULTING_HOURS } from '../../../graphql/mutations/Consulting';
import { ReactComponent as ConsultingIcon } from '../../../assets/images/icons/icon-consulting.svg';

interface ConsultingListProps {
Expand All @@ -25,7 +24,7 @@ const ConsultingList: React.SFC<ConsultingListProps> = ({ match, openDialog }: a
const queries = {
countQuery: GET_CONSULTING_HOURS_COUNT,
filterItemsQuery: GET_CONSULTING_HOURS,
deleteItemQuery: DELETE_CONSULTING_HOURS,
deleteItemQuery: null,
};

const columnNames = ['NAME', 'DATE', 'MINUTES', 'TYPE', 'ACTIONS'];
Expand Down Expand Up @@ -71,6 +70,8 @@ const ConsultingList: React.SFC<ConsultingListProps> = ({ match, openDialog }: a
const dialogMessage = 'This action cannot be undone.';
const dialogTitle = 'Are you sure you want to delete this consulting record?';

const restrictedAction = () => ({ delete: false, edit: true });

return (
<>
<List
Expand All @@ -83,6 +84,7 @@ const ConsultingList: React.SFC<ConsultingListProps> = ({ match, openDialog }: a
query: GET_CONSULTING_HOURS,
variables: setVariables(),
}}
restrictedAction={restrictedAction}
searchParameter="organizationName"
dialogMessage={dialogMessage}
dialogTitle={dialogTitle}
Expand Down