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

[TTAHUB-199] add all regions to activity report dropdown if user has central office #503

Merged
merged 2 commits into from
Jul 15, 2021
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ parameters:
default: "main"
type: string
sandbox_git_branch: # change to feature branch to test deployment
default: "js-specify-buildpack-version"
default: "TTAHUB-199/all-regions-selector-ar-page"
type: string
prod_new_relic_app_id:
default: "877570491"
Expand Down
2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@
"<rootDir>/src/index.js",
"<rootDir>/src/setupProxy.js",
"<rootDir>/src/pages/NotFound/index.js",
"<rootDir>/src/pages/Widgets/index.js",
"<rootDir>/src/widgets/Example.js",
"<rootDir>/src/polyfills.js"
],
"coverageThreshold": {
Expand Down
48 changes: 33 additions & 15 deletions frontend/src/pages/Landing/RegionalSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const DropdownIndicator = (props) => (

const Placeholder = (props) => <components.Placeholder {...props} />;

export const getUserOptions = (regions) => regions.map((region) => ({ value: region, label: `Region ${region}` }));
export const getUserOptions = (regions) => regions.map((region) => ({ value: region, label: `Region ${region}` })).sort((a, b) => a.value - b.value);

const styles = {
container: (provided, state) => {
Expand All @@ -42,6 +42,7 @@ const styles = {
paddingBottom: '4px',
whiteSpace: 'nowrap',
color: 'white',
minWidth: '140px',
width: '120px',
}),
indicatorSeparator: () => ({ display: 'none' }),
Expand All @@ -68,11 +69,10 @@ const styles = {

function RegionalSelect(props) {
const {
regions, onApply,
regions, onApply, hasCentralOffice,
} = props;

const [selectedItem, setSelectedItem] = useState();
const [appliedItem, setAppliedItem] = useState();
const [menuIsOpen, setMenuIsOpen] = useState(false);

// const delayedCloseMenu = () => setTimeout(setMenuIsOpen(false), 1000);
Expand All @@ -88,7 +88,6 @@ function RegionalSelect(props) {
className="float-left margin-2 smart-hub--filter-button"
onClick={() => {
onApply(selectedItem);
setAppliedItem(selectedItem);
setMenuIsOpen(false);
}}
>
Expand Down Expand Up @@ -118,17 +117,33 @@ function RegionalSelect(props) {
data: PropTypes.shape({
value: PropTypes.number,
label: PropTypes.string,
}),
innerRef: PropTypes.func,
}).isRequired,
innerRef: PropTypes.func.isRequired,
// eslint-disable-next-line react/forbid-prop-types
innerProps: PropTypes.object.isRequired,
};

CustomOption.defaultProps = {
data: {},
innerRef: () => 0,
let options = [...getUserOptions(regions), { custom: true }];

if (hasCentralOffice) {
options = [...getUserOptions(regions), { label: 'All Regions', value: 14 }, { custom: true }];
}

const getValue = () => {
if (selectedItem) {
return {
value: selectedItem.value,
label: selectedItem.label,
};
}

if (hasCentralOffice) {
return { label: 'All Regions', value: 14 };
}

return options[0];
};

const options = [...getUserOptions(regions), { custom: true }];
return (
<Select
options={options}
Expand All @@ -138,23 +153,26 @@ function RegionalSelect(props) {
onBlur={() => setMenuIsOpen(false)}
// onBlur={() => delayedCloseMenu()}
name="RegionalSelect"
defaultValue={options[0]}
value={{
value: selectedItem ? selectedItem.value : options[0].value,
label: appliedItem ? appliedItem.label : options[0].label,
}}
defaultValue={hasCentralOffice ? { label: 'All Regions', value: 14 } : options[0]}
value={getValue()}
styles={styles}
components={{ Placeholder, DropdownIndicator, Option: CustomOption }}
placeholder="Select Region"
closeMenuOnSelect={false}
maxMenuHeight={600}
className="ttahub-region-select"
/>
);
}

RegionalSelect.propTypes = {
regions: PropTypes.arrayOf(PropTypes.number).isRequired,
onApply: PropTypes.func.isRequired,
hasCentralOffice: PropTypes.bool,
};

RegionalSelect.defaultProps = {
hasCentralOffice: false,
};

export default RegionalSelect;
7 changes: 4 additions & 3 deletions frontend/src/pages/Landing/__tests__/RegionalSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const renderRegionalSelect = () => {
<RegionalSelect
regions={[1, 2]}
onApply={onApplyRegion}
hasCentralOffice
/>
</Router>,
);
Expand All @@ -27,15 +28,15 @@ const renderRegionalSelect = () => {
describe('Regional Select', () => {
test('displays correct region in input', async () => {
renderRegionalSelect();
const input = await screen.findByText(/region 1/i);
const input = await screen.findByText(/all regions/i);
expect(input).toBeVisible();
});

test('changes input value on apply', async () => {
renderRegionalSelect();
let input = await screen.findByText(/region 1/i);
let input = await screen.findByText(/all regions/i);
expect(input).toBeVisible();
await selectEvent.select(screen.getByText(/region 1/i), [/region 2/i]);
await selectEvent.select(input, [/region 2/i]);
const applyButton = await screen.findByText(/apply/i);
fireEvent.click(applyButton);
input = await screen.findByText(/region 2/i);
Expand Down
Loading