IO-134 Document Upload sizing limits
This commit is contained in:
2
App.js
2
App.js
@@ -6,7 +6,7 @@ import { PersistGate } from "redux-persist/integration/react";
|
|||||||
import * as Sentry from "sentry-expo";
|
import * as Sentry from "sentry-expo";
|
||||||
import ScreenMainComponent from "./components/screen-main/screen-main.component";
|
import ScreenMainComponent from "./components/screen-main/screen-main.component";
|
||||||
import env from "./env";
|
import env from "./env";
|
||||||
import { logImEXEvent } from "./firebase/firebase.utils";
|
import { logImEXEvent } from "./firebase/firebase.analytics";
|
||||||
import { client } from "./graphql/client";
|
import { client } from "./graphql/client";
|
||||||
import { persistor, store } from "./redux/store";
|
import { persistor, store } from "./redux/store";
|
||||||
import "./translations/i18n";
|
import "./translations/i18n";
|
||||||
|
|||||||
@@ -1320,6 +1320,48 @@
|
|||||||
</translation>
|
</translation>
|
||||||
</translations>
|
</translations>
|
||||||
</concept_node>
|
</concept_node>
|
||||||
|
<concept_node>
|
||||||
|
<name>storageexceeded</name>
|
||||||
|
<definition_loaded>false</definition_loaded>
|
||||||
|
<description></description>
|
||||||
|
<comment></comment>
|
||||||
|
<default_text></default_text>
|
||||||
|
<translations>
|
||||||
|
<translation>
|
||||||
|
<language>en-US</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>es-MX</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>fr-CA</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
</translations>
|
||||||
|
</concept_node>
|
||||||
|
<concept_node>
|
||||||
|
<name>storageexceeded_title</name>
|
||||||
|
<definition_loaded>false</definition_loaded>
|
||||||
|
<description></description>
|
||||||
|
<comment></comment>
|
||||||
|
<default_text></default_text>
|
||||||
|
<translations>
|
||||||
|
<translation>
|
||||||
|
<language>en-US</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>es-MX</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>fr-CA</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
</translations>
|
||||||
|
</concept_node>
|
||||||
<concept_node>
|
<concept_node>
|
||||||
<name>temporarystorage</name>
|
<name>temporarystorage</name>
|
||||||
<definition_loaded>false</definition_loaded>
|
<definition_loaded>false</definition_loaded>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { Button, List, Title } from "react-native-paper";
|
import { Button, List, Title } from "react-native-paper";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
import { setCameraJob, setCameraJobId } from "../../redux/app/app.actions";
|
import { setCameraJob, setCameraJobId } from "../../redux/app/app.actions";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({});
|
const mapStateToProps = createStructuredSelector({});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Button } from "react-native-paper";
|
|||||||
import { SafeAreaView } from "react-native-safe-area-context";
|
import { SafeAreaView } from "react-native-safe-area-context";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
import { setCameraJob, setCameraJobId } from "../../redux/app/app.actions";
|
import { setCameraJob, setCameraJobId } from "../../redux/app/app.actions";
|
||||||
import {
|
import {
|
||||||
checkUserSession,
|
checkUserSession,
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
|
import { useApolloClient } from "@apollo/client";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
import { AssetsSelector } from "expo-images-picker";
|
import { AssetsSelector } from "expo-images-picker";
|
||||||
import * as MediaLibrary from "expo-media-library";
|
import * as MediaLibrary from "expo-media-library";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import React, { useCallback, useState } from "react";
|
import React, { useCallback, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { StyleSheet, Text, View } from "react-native";
|
import { StyleSheet, Text, View, Alert } from "react-native";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
import {
|
import {
|
||||||
selectCurrentCameraJobId,
|
selectCurrentCameraJobId,
|
||||||
selectDeleteAfterUpload,
|
selectDeleteAfterUpload,
|
||||||
@@ -20,8 +21,9 @@ import { handleUpload } from "../../util/document-upload.utility";
|
|||||||
import CameraSelectJob from "../camera-select-job/camera-select-job.component";
|
import CameraSelectJob from "../camera-select-job/camera-select-job.component";
|
||||||
import UploadDeleteSwitch from "../upload-delete-switch/upload-delete-switch.component";
|
import UploadDeleteSwitch from "../upload-delete-switch/upload-delete-switch.component";
|
||||||
import UploadProgress from "../upload-progress/upload-progress.component";
|
import UploadProgress from "../upload-progress/upload-progress.component";
|
||||||
|
import { GET_DOC_SIZE_TOTALS } from "../../graphql/documents.queries";
|
||||||
//const limit = plimit(2);
|
//const limit = plimit(2);
|
||||||
|
import * as FileSystem from "expo-file-system";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentUser: selectCurrentUser,
|
currentUser: selectCurrentUser,
|
||||||
@@ -47,7 +49,7 @@ export function ImageBrowserScreen({
|
|||||||
const forceRerender = useCallback(() => {
|
const forceRerender = useCallback(() => {
|
||||||
setTick((tick) => tick + 1);
|
setTick((tick) => tick + 1);
|
||||||
}, []);
|
}, []);
|
||||||
|
const client = useApolloClient();
|
||||||
async function handleOnSuccess(uri, id) {
|
async function handleOnSuccess(uri, id) {
|
||||||
console.log("Succesful upload!", uri);
|
console.log("Succesful upload!", uri);
|
||||||
logImEXEvent("imexmobile_successful_upload");
|
logImEXEvent("imexmobile_successful_upload");
|
||||||
@@ -56,6 +58,49 @@ export function ImageBrowserScreen({
|
|||||||
|
|
||||||
const onDone = async (data) => {
|
const onDone = async (data) => {
|
||||||
logImEXEvent("imexmobile_upload_documents", { count: data.length });
|
logImEXEvent("imexmobile_upload_documents", { count: data.length });
|
||||||
|
|
||||||
|
//Validate to make sure the totals for the file sizes do not exceed the total on the job.
|
||||||
|
|
||||||
|
const queryData = await client.query({
|
||||||
|
query: GET_DOC_SIZE_TOTALS,
|
||||||
|
|
||||||
|
fetchPolicy: "network-only",
|
||||||
|
variables: {
|
||||||
|
jobId: selectedCameraJobId !== "temp" ? selectedCameraJobId : null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const totalOfUploads = await data.reduce(async (acc, val) => {
|
||||||
|
//Get the size of the file based on URI.
|
||||||
|
const info = await FileSystem.getInfoAsync(val.uri, { size: true });
|
||||||
|
return (await acc) + info.size;
|
||||||
|
}, 0);
|
||||||
|
console.log("data :>> ", data);
|
||||||
|
console.log(
|
||||||
|
"Size of uploaded documents.",
|
||||||
|
queryData.data.documents_aggregate.aggregate.sum.size,
|
||||||
|
"Shop Limit",
|
||||||
|
bodyshop.jobsizelimit,
|
||||||
|
"Space remaining",
|
||||||
|
bodyshop.jobsizelimit -
|
||||||
|
queryData.data.documents_aggregate.aggregate.sum.size,
|
||||||
|
"Total of uploaded files",
|
||||||
|
totalOfUploads
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
bodyshop.jobsizelimit -
|
||||||
|
queryData.data.documents_aggregate.aggregate.sum.size <=
|
||||||
|
totalOfUploads
|
||||||
|
) {
|
||||||
|
//No more room... abandon ship.
|
||||||
|
Alert.alert(
|
||||||
|
t("mediabrowser.labels.storageexceeded_title"),
|
||||||
|
t("mediabrowser.labels.storageexceeded")
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const ret = await Promise.all(
|
const ret = await Promise.all(
|
||||||
data.map(async (p) => {
|
data.map(async (p) => {
|
||||||
let filename;
|
let filename;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { StyleSheet, Switch, Text, View } from "react-native";
|
import { StyleSheet, Switch, Text, View } from "react-native";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
import { toggleDeleteAfterUpload } from "../../redux/app/app.actions";
|
import { toggleDeleteAfterUpload } from "../../redux/app/app.actions";
|
||||||
import { selectDeleteAfterUpload } from "../../redux/app/app.selectors";
|
import { selectDeleteAfterUpload } from "../../redux/app/app.selectors";
|
||||||
|
|
||||||
|
|||||||
24
firebase/firebase.analytics.js
Normal file
24
firebase/firebase.analytics.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import * as Analytics from "expo-firebase-analytics";
|
||||||
|
import { store } from "../redux/store";
|
||||||
|
|
||||||
|
export const logImEXEvent = (eventName, additionalParams, stateProp = null) => {
|
||||||
|
const state = stateProp || store.getState();
|
||||||
|
const eventParams = {
|
||||||
|
shop:
|
||||||
|
(state.user && state.user.bodyshop && state.user.bodyshop.shopname) ||
|
||||||
|
null,
|
||||||
|
user:
|
||||||
|
(state.user && state.user.currentUser && state.user.currentUser.email) ||
|
||||||
|
null,
|
||||||
|
...additionalParams,
|
||||||
|
};
|
||||||
|
console.log(
|
||||||
|
"%c[Analytics]",
|
||||||
|
"background-color: green ;font-weight:bold;",
|
||||||
|
eventName,
|
||||||
|
eventParams
|
||||||
|
);
|
||||||
|
Analytics.logEvent(eventName, eventParams);
|
||||||
|
};
|
||||||
|
|
||||||
|
//export const ExpoAnalytics = Analytics;
|
||||||
@@ -55,24 +55,24 @@ export const updateCurrentUser = (userDetails) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const logImEXEvent = (eventName, additionalParams, stateProp = null) => {
|
// export const logImEXEvent = (eventName, additionalParams, stateProp = null) => {
|
||||||
const state = stateProp || store.getState();
|
// const state = stateProp || store.getState();
|
||||||
const eventParams = {
|
// const eventParams = {
|
||||||
shop:
|
// shop:
|
||||||
(state.user && state.user.bodyshop && state.user.bodyshop.shopname) ||
|
// (state.user && state.user.bodyshop && state.user.bodyshop.shopname) ||
|
||||||
null,
|
// null,
|
||||||
user:
|
// user:
|
||||||
(state.user && state.user.currentUser && state.user.currentUser.email) ||
|
// (state.user && state.user.currentUser && state.user.currentUser.email) ||
|
||||||
null,
|
// null,
|
||||||
...additionalParams,
|
// ...additionalParams,
|
||||||
};
|
// };
|
||||||
console.log(
|
// console.log(
|
||||||
"%c[Analytics]",
|
// "%c[Analytics]",
|
||||||
"background-color: green ;font-weight:bold;",
|
// "background-color: green ;font-weight:bold;",
|
||||||
eventName,
|
// eventName,
|
||||||
eventParams
|
// eventParams
|
||||||
);
|
// );
|
||||||
Analytics.logEvent(eventName, eventParams);
|
// Analytics.logEvent(eventName, eventParams);
|
||||||
};
|
// };
|
||||||
|
|
||||||
//export const ExpoAnalytics = Analytics;
|
//export const ExpoAnalytics = Analytics;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export const QUERY_BODYSHOP = gql`
|
|||||||
query QUERY_BODYSHOP {
|
query QUERY_BODYSHOP {
|
||||||
bodyshops(where: { associations: { active: { _eq: true } } }) {
|
bodyshops(where: { associations: { active: { _eq: true } } }) {
|
||||||
id
|
id
|
||||||
|
jobsizelimit
|
||||||
md_ro_statuses
|
md_ro_statuses
|
||||||
md_order_statuses
|
md_order_statuses
|
||||||
shopname
|
shopname
|
||||||
|
|||||||
@@ -1,11 +1,27 @@
|
|||||||
import gql from "graphql-tag";
|
import gql from "graphql-tag";
|
||||||
|
|
||||||
|
export const GET_DOC_SIZE_TOTALS = gql`
|
||||||
|
query GET_DOC_SIZE_TOTALS($jobId: uuid!) {
|
||||||
|
documents_aggregate(where: { jobid: { _eq: $jobId } }) {
|
||||||
|
aggregate {
|
||||||
|
sum {
|
||||||
|
size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
export const GET_DOCUMENTS_BY_JOB = gql`
|
export const GET_DOCUMENTS_BY_JOB = gql`
|
||||||
query GET_DOCUMENTS_BY_JOB($jobId: uuid!) {
|
query GET_DOCUMENTS_BY_JOB($jobId: uuid!) {
|
||||||
documents(
|
documents_aggregate(where: { jobid: { _eq: $jobId } }) {
|
||||||
where: { jobid: { _eq: $jobId } }
|
aggregate {
|
||||||
order_by: { updated_at: desc }
|
sum {
|
||||||
) {
|
size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
documents(order_by: { updated_at: desc }) {
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
key
|
key
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import { all, call, put, takeLatest } from "redux-saga/effects";
|
|||||||
import {
|
import {
|
||||||
auth,
|
auth,
|
||||||
getCurrentUser,
|
getCurrentUser,
|
||||||
logImEXEvent,
|
|
||||||
updateCurrentUser,
|
updateCurrentUser,
|
||||||
} from "../../firebase/firebase.utils";
|
} from "../../firebase/firebase.utils";
|
||||||
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
import { QUERY_BODYSHOP } from "../../graphql/bodyshop.queries";
|
import { QUERY_BODYSHOP } from "../../graphql/bodyshop.queries";
|
||||||
import { client } from "../../graphql/client";
|
import { client } from "../../graphql/client";
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -90,6 +90,8 @@
|
|||||||
"nomedia": "Look's like there's no media on your device. Take some photos or videos and they will appear here.",
|
"nomedia": "Look's like there's no media on your device. Take some photos or videos and they will appear here.",
|
||||||
"selectjob": "--- Select a job ---",
|
"selectjob": "--- Select a job ---",
|
||||||
"selectjobassetselector": "Please select a job to upload media. ",
|
"selectjobassetselector": "Please select a job to upload media. ",
|
||||||
|
"storageexceeded": "Unable to uploaded selected files because there is not sufficient space available on this job.",
|
||||||
|
"storageexceeded_title": "Unable to upload file(s)",
|
||||||
"temporarystorage": "* Temporary Storage *"
|
"temporarystorage": "* Temporary Storage *"
|
||||||
},
|
},
|
||||||
"titles": {
|
"titles": {
|
||||||
|
|||||||
@@ -90,6 +90,8 @@
|
|||||||
"nomedia": "",
|
"nomedia": "",
|
||||||
"selectjob": "",
|
"selectjob": "",
|
||||||
"selectjobassetselector": "",
|
"selectjobassetselector": "",
|
||||||
|
"storageexceeded": "",
|
||||||
|
"storageexceeded_title": "",
|
||||||
"temporarystorage": ""
|
"temporarystorage": ""
|
||||||
},
|
},
|
||||||
"titles": {
|
"titles": {
|
||||||
|
|||||||
@@ -90,6 +90,8 @@
|
|||||||
"nomedia": "",
|
"nomedia": "",
|
||||||
"selectjob": "",
|
"selectjob": "",
|
||||||
"selectjobassetselector": "",
|
"selectjobassetselector": "",
|
||||||
|
"storageexceeded": "",
|
||||||
|
"storageexceeded_title": "",
|
||||||
"temporarystorage": ""
|
"temporarystorage": ""
|
||||||
},
|
},
|
||||||
"titles": {
|
"titles": {
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ export const uploadToCloudinary = async (
|
|||||||
type: fileType,
|
type: fileType,
|
||||||
extension: extension,
|
extension: extension,
|
||||||
bodyshopid: bodyshop.id,
|
bodyshopid: bodyshop.id,
|
||||||
|
size: file.size,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user