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

DT-969: Show server errors when creating a draft DAR #2714

Merged
merged 4 commits into from
Nov 6, 2024
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
26 changes: 18 additions & 8 deletions src/components/data_search/DatasetSearchTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,18 @@ export const DatasetSearchTable = (props) => {
doSearch();
};
const applyForAccess = async () => {
const darDraft = await DAR.postDarDraft({ datasetId: selected });
history.push(`/dar_application/${darDraft.referenceId}`);
try {
const draftResponse = await DAR.postDarDraft({ datasetId: selected });
if (draftResponse.referenceId) {
history.push(`/dar_application/${draftResponse.referenceId}`);
} else if (draftResponse.message) {
Notifications.showError({ text: draftResponse.message + ' Please contact customer support for help.' });
} else {
Notifications.showError({ text: 'Error: Unable to create a Draft Data Access Request' });
fboulnois marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (error) {
Notifications.showError({ text: 'Error: Unable to create a Draft Data Access Request' });
}
};

useEffect(() => {
Expand All @@ -207,11 +217,11 @@ export const DatasetSearchTable = (props) => {
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
<TableHeaderSection icon={icon} title={title} description="Search, filter, and select datasets, then click 'Apply for Access' to request access" />
<Box sx={{paddingTop: '2em', paddingLeft: '2em'}}>
<div className="right-header-section" style={Styles.RIGHT_HEADER_SECTION}>
<div className='right-header-section' style={Styles.RIGHT_HEADER_SECTION}>
<input
data-cy="search-bar"
type="text"
placeholder="Enter search terms"
data-cy='search-bar'
type='text'
placeholder='Enter search terms'
style={{
width: '100%',
border: '1px solid #cecece',
Expand All @@ -227,7 +237,7 @@ export const DatasetSearchTable = (props) => {
/>
<div/>
<Box sx={{ display: 'flex', flexDirection: 'row', justifyContent: 'flex-end', paddingLeft: '1em', height: '4rem' }}>
<Button variant="contained" onClick={() => {filterHandler(null, datasets, 'search', '')}} sx={{ width: '100px' }}>
<Button variant='contained' onClick={() => {filterHandler(null, datasets, 'search', '');}} sx={{ width: '100px' }}>
Clear Search
</Button>
</Box>
Expand Down Expand Up @@ -274,7 +284,7 @@ export const DatasetSearchTable = (props) => {
<Box sx={{ display: 'flex', flexDirection: 'row', justifyContent: 'flex-end', padding: '2em 4em' }}>
{
!isEmpty(datasets) &&
<Button variant="contained" onClick={applyForAccess} sx={{ transform: 'scale(1.5)' }} >
<Button variant='contained' onClick={applyForAccess} sx={{ transform: 'scale(1.5)' }} >
Apply for Access
</Button>
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ajax/DAR.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const DAR = {
const url = DAAUtils.isEnabled() ?
`${await getApiUrl()}/api/dar/v3/draft` :
`${await getApiUrl()}/api/dar/v2/draft`;
const res = await axios.post(url, dar, Config.authOpts());
const res = await axios.post(url, dar, Object.assign({}, Config.authOpts(), {validateStatus: () => true}));
return res.data;
},

Expand Down
20 changes: 15 additions & 5 deletions src/pages/DatasetStatistics.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ export default function DatasetStatistics(props) {
const [isLoading, setIsLoading] = useState(true);

const applyForAccess = async () => {
const darDraft = await DAR.postDarDraft({ datasetId: [datasetId] });
history.push(`/dar_application/${darDraft.referenceId}`);
try {
const draftResponse = await DAR.postDarDraft({ datasetId: [datasetId] });
if (draftResponse.referenceId) {
history.push(`/dar_application/${draftResponse.referenceId}`);
} else if (draftResponse.message) {
Notifications.showError({ text: draftResponse.message + ' Please contact customer support for help.' });
} else {
Notifications.showError({ text: 'Error: Unable to create a Draft Data Access Request' });
fboulnois marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (error) {
Notifications.showError({ text: 'Error: Unable to create a Draft Data Access Request' });
}
};

useEffect(() => {
Expand Down Expand Up @@ -69,7 +79,7 @@ export default function DatasetStatistics(props) {
</div>
</div>
<div style={{ paddingTop: '20px', paddingLeft: '30px' }}>
<Button variant="contained" onClick={applyForAccess} sx={{ transform: 'scale(1.5)' }} >
<Button variant='contained' onClick={applyForAccess} sx={{ transform: 'scale(1.5)' }} >
Apply for Access
</Button>
</div>
Expand Down Expand Up @@ -109,8 +119,8 @@ export default function DatasetStatistics(props) {
<div style={Styles.READ_MORE} id={`${dar.darCode}`} key={`${dar.darCode}`}>
<ReadMore
props={props}
readLessText="Show less"
readMoreText="Show More"
readLessText='Show less'
readMoreText='Show More'
readStyle={{ fontWeight: 500, margin: '20px', height: 0 }}
content={[
<div key='dar' style={{ display: 'flex' }}>
Expand Down
Loading