Skip to content

Commit

Permalink
#1213 | Changes to support new location upload file format
Browse files Browse the repository at this point in the history
  • Loading branch information
1t5j0y committed Jun 18, 2024
1 parent c9290c2 commit 7547738
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/upload/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Dashboard = ({ getStatuses, getUploadTypes, uploadTypes = new UploadTypes(
const [entityForDownload, setEntityForDownload] = React.useState("");
const [file, setFile] = React.useState();
const [autoApprove, setAutoApprove] = React.useState(false);
const [mode, setMode] = React.useState("relaxed");
const [mode, setMode] = React.useState("CREATE");
const [hierarchy, setHierarchy] = React.useState();
const [configuredHierarchies, setConfiguredHierarchies] = React.useState([]);

Expand All @@ -49,7 +49,7 @@ const Dashboard = ({ getStatuses, getUploadTypes, uploadTypes = new UploadTypes(
staticTypesWithStaticDownload.getCode(name) || staticTypesWithDynamicDownload.getCode(name) || uploadTypes.getCode(name);

const uploadFile = async () => {
const [ok, error] = await api.bulkUpload(getUploadTypeCode(uploadType), file, autoApprove, mode);
const [ok, error] = await api.bulkUpload(getUploadTypeCode(uploadType), file, autoApprove, mode, hierarchy);
if (!ok && error) {
alert(error);
}
Expand Down Expand Up @@ -89,15 +89,15 @@ const Dashboard = ({ getStatuses, getUploadTypes, uploadTypes = new UploadTypes(

const dropdownHandler = option => {
setAutoApprove(false);
setMode("relaxed");
setMode("CREATE");
setUploadType(option);
option !== staticTypesWithStaticDownload.getName("metadataZip") && setEntityForDownload(option);
};

const isSampleDownloadDisallowed =
isEmpty(entityForDownload) ||
(uploadType === "Locations" && isEmpty(mode)) ||
(uploadType === "Locations" && mode === "relaxed" && isEmpty(hierarchy));
(uploadType === "Locations" && mode === "CREATE" && isEmpty(hierarchy));

return (
<Grid container spacing={2} className={classes.root}>
Expand Down Expand Up @@ -150,7 +150,7 @@ const Dashboard = ({ getStatuses, getUploadTypes, uploadTypes = new UploadTypes(
</Grid>
<Grid container item>
{uploadType === "Locations" &&
mode === "relaxed" &&
mode === "CREATE" &&
(configuredHierarchies && configuredHierarchies.length > 0 ? (
<LocationHierarchy hierarchy={hierarchy} setHierarchy={setHierarchy} configuredHierarchies={configuredHierarchies} />
) : (
Expand Down
6 changes: 3 additions & 3 deletions src/upload/LocationModes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export const LocationModes = ({ mode, setMode }) => {
return (
<FormControl component="fieldset" style={{ marginTop: "20px" }}>
<FormLabel component="legend">Select Mode</FormLabel>
<RadioGroup row aria-label="mode" name="mode1" value={mode || "relaxed"} onChange={handleChange}>
<RadioGroup row aria-label="mode" name="mode1" value={mode || "CREATE"} onChange={handleChange}>
<Tooltip title="Create new locations" placement="bottom-start" arrow>
<div>
<FormControlLabel value="relaxed" control={<Radio color="primary" />} label="Create" />
<FormControlLabel value="CREATE" control={<Radio color="primary" />} label="Create" />
</div>
</Tooltip>
<Tooltip title="Edit locations' name, parent, GPS coordinates or properties" placement="bottom-start" arrow>
<div>
<FormControlLabel value="strict" control={<Radio color="primary" />} label="Edit" />
<FormControlLabel value="EDIT" control={<Radio color="primary" />} label="Edit" />
</div>
</Tooltip>
</RadioGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/upload/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export default {
fetchUploadJobStatuses: (params = {}) => {
return http.fetchJson(http.withParams("/import/status", { size: 5, ...params })).then(r => r.json);
},
bulkUpload: (type, file, autoApprove, locationUploadMode) =>
bulkUpload: (type, file, autoApprove, locationUploadMode, locationHierarchy) =>
http
.uploadFile(http.withParams("/import/new", { type, autoApprove, locationUploadMode }), file)
.uploadFile(http.withParams("/import/new", { type, autoApprove, locationUploadMode, locationHierarchy }), file)
//returns [response, error]
.then(r => [r.text, null])
.catch(r => [null, `${get(r, "response.data") || get(r, "message") || "unknown error"}`]),
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16944,6 +16944,19 @@ rsvp@^4.8.4:
"rules-config@github:avniproject/rules-config#fe552da405368bfd138e2f38e605c1d307e3ebe4":
version "0.0.1"
resolved "https://codeload.github.com/avniproject/rules-config/tar.gz/fe552da405368bfd138e2f38e605c1d307e3ebe4"
dependencies:
"@quasar/babel-preset-app" "^2.0.1"
babel-preset-env "^1.7.0"
babel-register "^6.26.0"
chai "^4.1.2"
lodash "^4.17.11"
moment "^2.29.4"
superagent "^3.8.3"
test "^0.6.0"
uglifyjs-webpack-plugin "^1.2.5"
webpack "^3.12.0"
webpack-cli "^3.0.3"
webpack-node-externals "1.6.0"

run-async@^2.2.0, run-async@^2.4.0:
version "2.4.1"
Expand Down

0 comments on commit 7547738

Please sign in to comment.