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

Add ability to export favorites #706

Merged
merged 1 commit into from
Feb 11, 2020
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
28 changes: 26 additions & 2 deletions src/Components/FavoritePositions/FavoritePositions.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ExportButton from 'Components/ExportButton';
import { downloadPositionData } from 'actions/favoritePositions';
import { FAVORITE_POSITIONS_ARRAY, BID_RESULTS } from '../../Constants/PropTypes';
import ProfileSectionTitle from '../ProfileSectionTitle';
import Spinner from '../Spinner';
Expand All @@ -19,8 +21,10 @@ const TYPE_ALL = 'all';
class FavoritePositions extends Component {
constructor(props) {
super(props);
this.export = this.export.bind(this);
this.state = {
selected: TYPE_ALL,
isLoading: false,
};
}
getPositions() {
Expand All @@ -35,8 +39,25 @@ class FavoritePositions extends Component {
return [...favorites, ...favoritesPV];
}
}
render() {
export() {
const { selected } = this.state;
const args = [
!!(selected === TYPE_PV),
!!(selected === TYPE_OPEN),
];

this.setState({ isLoading: true }, () => {
downloadPositionData(...args)
.then(() => {
this.setState({ isLoading: false });
})
.catch(() => {
this.setState({ isLoading: false });
});
});
}
render() {
const { isLoading, selected } = this.state;
const { favorites, favoritesPV, favoritePositionsIsLoading,
favoritePositionsHasErrored, bidList, onSortChange } = this.props;
const positions = this.getPositions();
Expand Down Expand Up @@ -66,7 +87,7 @@ class FavoritePositions extends Component {
selected={this.state.selected}
denominator={favorites.length + favoritesPV.length}
/>
<div className="usa-grid-full favorites-top-section">
<div className="usa-grid-full favorites-top-section favorites-top-section--controls">
<div className="results-dropdown results-dropdown-sort">
<SelectForm
id="sort"
Expand All @@ -76,6 +97,9 @@ class FavoritePositions extends Component {
disabled={favoritePositionsIsLoading}
/>
</div>
<div className="export-button-container">
<ExportButton onClick={this.export} isLoading={isLoading} />
</div>
</div>
{
favoritePositionsIsLoading && !favoritePositionsHasErrored &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports[`FavoritePositionsComponent matches snapshot 1`] = `
selected="all"
/>
<div
className="usa-grid-full favorites-top-section"
className="usa-grid-full favorites-top-section favorites-top-section--controls"
>
<div
className="results-dropdown results-dropdown-sort"
Expand Down Expand Up @@ -103,6 +103,17 @@ exports[`FavoritePositionsComponent matches snapshot 1`] = `
transformValue={[Function]}
/>
</div>
<div
className="export-button-container"
>
<ExportButton
className=""
isLoading={false}
onClick={[Function]}
primaryClass="usa-button-secondary"
text="Export"
/>
</div>
</div>
<HomePagePositionsList
bidList={
Expand Down
16 changes: 16 additions & 0 deletions src/actions/favoritePositions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import { get } from 'lodash';
import { downloadFromResponse } from 'utilities';
import { toastError } from './toast';
import api from '../api';
import { checkFlag } from '../flags';

const getUsePV = () => checkFlag('flags.projected_vacancy');

export function downloadPositionData(excludeAP = false, excludePV = false) {
const url = `/available_position/favorites/export/?exclude_available=${excludeAP}&exclude_projected=${excludePV}`;
return api().get(url, {
responseType: 'stream',
})
.then((response) => {
downloadFromResponse(response, 'TalentMap_favorites_export');
})
.catch(() => {
// eslint-disable-next-line global-require
require('../store').store.dispatch(toastError('Export unsuccessful. Please try again.', 'Error exporting'));
});
}

export function favoritePositionsHasErrored(bool) {
return {
type: 'FAVORITE_POSITIONS_HAS_ERRORED',
Expand Down
9 changes: 9 additions & 0 deletions src/sass/_profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,17 @@
.saved-searches-container {
position: relative;

.export-button-container > button {
margin-top: 0;
}

.favorites-top-section {
margin-bottom: 1.2em;

&.favorites-top-section--controls {
display: flex;
justify-content: flex-end;
}
}

.condensed-card {
Expand Down