-
Notifications
You must be signed in to change notification settings - Fork 108
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
Update metadata #3361
Update metadata #3361
Changes from all commits
45f443e
eb17937
0efec32
82fa71d
c4e0a68
30cd88e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import * as CONSTANTS from "assets/constants/overviewConstants"; | ||
import * as TYPES from "./types"; | ||
|
||
import { DANGER, ERROR_MSG } from "assets/constants/toastConstants"; | ||
|
||
import API from "../utils/axiosInstance"; | ||
import { DANGER } from "assets/constants/toastConstants"; | ||
import { expandUriTemplate } from "../utils/helper"; | ||
import { findNoOfDays } from "utils/dateFunctions"; | ||
import { showToast } from "./toastActions"; | ||
import { expandUriTemplate } from "../utils/helper"; | ||
|
||
export const getDatasets = () => async (dispatch, getState) => { | ||
const alreadyRendered = getState().overview.loadingDone; | ||
|
@@ -41,7 +42,7 @@ export const getDatasets = () => async (dispatch, getState) => { | |
} | ||
} | ||
} catch (error) { | ||
dispatch(showToast(DANGER, error?.response?.data?.message)); | ||
dispatch(showToast(DANGER, error?.response?.data?.message ?? ERROR_MSG)); | ||
dispatch({ type: TYPES.NETWORK_ERROR }); | ||
} | ||
if (alreadyRendered) { | ||
|
@@ -129,14 +130,26 @@ export const updateDataset = | |
(item) => item.resource_id === dataset.resource_id | ||
); | ||
runs[dataIndex].metadata[metaDataActions[actionType]] = | ||
response.data[metaDataActions[actionType]]; | ||
response.data.metadata[metaDataActions[actionType]]; | ||
dispatch({ | ||
type: TYPES.USER_RUNS, | ||
payload: runs, | ||
}); | ||
dispatch(initializeRuns()); | ||
|
||
const errors = response.data?.errors; | ||
if (errors && Object.keys(errors).length > 0) { | ||
let errorText = ""; | ||
|
||
for (const [key, value] of Object.entries(errors)) { | ||
errorText += `${key} : ${value} \n`; | ||
} | ||
dispatch( | ||
showToast("warning", "Problem updating metadata", errorText) | ||
); | ||
} | ||
} else { | ||
dispatch(showToast(DANGER, response?.data?.message)); | ||
dispatch(showToast(DANGER, response?.data?.message ?? ERROR_MSG)); | ||
} | ||
} catch (error) { | ||
dispatch(showToast(DANGER, error?.response?.data?.message)); | ||
|
@@ -173,7 +186,7 @@ export const deleteDataset = (dataset) => async (dispatch, getState) => { | |
dispatch(showToast(CONSTANTS.SUCCESS, "Deleted!")); | ||
} | ||
} catch (error) { | ||
dispatch(showToast(DANGER, error?.response?.data?.message)); | ||
dispatch(showToast(DANGER, error?.response?.data?.message ?? ERROR_MSG)); | ||
dispatch({ type: TYPES.NETWORK_ERROR }); | ||
} | ||
dispatch({ type: TYPES.COMPLETED }); | ||
|
@@ -193,6 +206,12 @@ export const setSelectedRuns = (rows) => { | |
}; | ||
}; | ||
|
||
export const setSelectedSavedRuns = (rows) => { | ||
return { | ||
type: TYPES.SELECTED_SAVED_RUNS, | ||
payload: rows, | ||
}; | ||
}; | ||
Comment on lines
+209
to
+214
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternately, export const setSelectedSavedRuns = (rows) => (
{
type: TYPES.SELECTED_SAVED_RUNS,
payload: rows,
}
); That is, we only need to return a value which is an object -- we don't need any actual code (like a |
||
export const updateMultipleDataset = | ||
(method, value) => (dispatch, getState) => { | ||
const selectedRuns = getState().overview.selectedRuns; | ||
|
@@ -245,7 +264,7 @@ export const publishDataset = | |
dispatch(showToast(CONSTANTS.SUCCESS, "Updated!")); | ||
} | ||
} catch (error) { | ||
dispatch(showToast(DANGER, error?.response?.data?.message)); | ||
dispatch(showToast(DANGER, error?.response?.data?.message ?? ERROR_MSG)); | ||
dispatch({ type: TYPES.NETWORK_ERROR }); | ||
} | ||
dispatch({ type: TYPES.COMPLETED }); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const DANGER = "danger"; | ||
export const ERROR_MSG = "Something went wrong!"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is expedient, but it would be really handy if we could come up with something less generic. Any context would potentially be helpful. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ import { | |
editMetadata, | ||
publishDataset, | ||
setRowtoEdit, | ||
setSelectedRuns, | ||
setSelectedSavedRuns, | ||
updateDataset, | ||
} from "actions/overviewActions"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
|
@@ -29,23 +29,25 @@ import { SavedRunsRow } from "./common-component"; | |
|
||
const SavedRunsComponent = () => { | ||
const dispatch = useDispatch(); | ||
const { savedRuns, selectedRuns } = useSelector((state) => state.overview); | ||
const { savedRuns, selectedSavedRuns } = useSelector( | ||
(state) => state.overview | ||
); | ||
|
||
/* Selecting */ | ||
const areAllRunsSelected = | ||
savedRuns?.length > 0 && savedRuns?.length === selectedRuns?.length; | ||
savedRuns?.length > 0 && savedRuns?.length === selectedSavedRuns?.length; | ||
Comment on lines
37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The For instance, while Also, we can (and should) use So, this code should do an explicit test for the presence of the field, and then test it's value: savedRuns?.length && savedRuns.length > 0 && savedRuns.length === selectedSavedRuns?.length; However, if |
||
const selectAllRuns = (isSelecting) => { | ||
dispatch(setSelectedRuns(isSelecting ? [...savedRuns] : [])); | ||
dispatch(setSelectedSavedRuns(isSelecting ? [...savedRuns] : [])); | ||
}; | ||
const onSelectRuns = (run, _rowIndex, isSelecting) => { | ||
const otherSelectedRuns = selectedRuns.filter( | ||
const otherSelectedRuns = selectedSavedRuns.filter( | ||
(r) => r.resource_id !== run.resource_id | ||
); | ||
const c = isSelecting ? [...otherSelectedRuns, run] : otherSelectedRuns; | ||
dispatch(setSelectedRuns(c)); | ||
dispatch(setSelectedSavedRuns(c)); | ||
}; | ||
const isRowSelected = (run) => | ||
selectedRuns.filter((item) => item.name === run.name).length > 0; | ||
selectedSavedRuns.filter((item) => item.name === run.name).length > 0; | ||
/* Selecting */ | ||
|
||
/* Actions Row */ | ||
|
@@ -107,6 +109,7 @@ const SavedRunsComponent = () => { | |
selectAllRuns(isSelecting), | ||
isSelected: areAllRunsSelected, | ||
}} | ||
style={{ borderTop: "1px solid #d2d2d2" }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity, why are we specifying the |
||
></Th> | ||
<Th>{columnNames.result}</Th> | ||
<Th>{columnNames.uploadedtime}</Th> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,10 @@ const ToastComponent = () => { | |
/> | ||
} | ||
> | ||
{item?.message && <p>{item?.message}</p>} | ||
{item?.message && | ||
item?.message.split("\n").map((i, key) => { | ||
Comment on lines
+36
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need (and therefore shouldn't use) the |
||
return <p key={i}>{i}</p>; | ||
})} | ||
</Alert> | ||
))} | ||
</AlertGroup> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternately,