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

Show hidden offers to admin #291

Open
wants to merge 58 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9c44fbb
feature: show hidden button style done on desktop
CarlosMealha Oct 28, 2022
83be2ed
feat: inserted the reset advanced search and show hidden offers butto…
CarlosMealha Nov 15, 2022
a4c292d
feat: showHidden is already working
CarlosMealha Nov 15, 2022
88a304f
test: adds showHidden test
CarlosMealha Jan 24, 2023
5edff56
feature: show hidden button style done on desktop
CarlosMealha Oct 28, 2022
6e9aad9
feat: inserted the reset advanced search and show hidden offers butto…
CarlosMealha Nov 15, 2022
20fa7ce
feat: showHidden is already working
CarlosMealha Nov 15, 2022
e807869
tests: adds various tests to showHidden
CarlosMealha Feb 7, 2023
afa9cb9
test: adds more showHidden tests
CarlosMealha Feb 12, 2023
f801bd7
feature: adds show hidden offers to mobile
diogofonte Feb 28, 2023
cc0a26e
fix: fixes search results bug in mobile
diogofonte Feb 28, 2023
c319a69
feature: adds show hidden to url
diogofonte Feb 28, 2023
950e19b
reset fields working with show hidden offers
diogofonte Mar 6, 2023
675de5d
fix lint error
diogofonte Mar 7, 2023
9665765
fix lint error
diogofonte Mar 7, 2023
b597651
feature: show hidden button style done on desktop
CarlosMealha Oct 28, 2022
af0b2cf
feat: showHidden is already working
CarlosMealha Nov 15, 2022
f5f4ef1
feature: show hidden button style done on desktop
CarlosMealha Oct 28, 2022
0032b1b
feat: inserted the reset advanced search and show hidden offers butto…
CarlosMealha Nov 15, 2022
3b7fc88
feat: showHidden is already working
CarlosMealha Nov 15, 2022
afe7a4c
tests: adds various tests to showHidden
CarlosMealha Feb 7, 2023
67b6cc6
feature: adds show hidden to url
diogofonte Feb 28, 2023
b064838
reset fields working with show hidden offers
diogofonte Mar 6, 2023
d6f9f65
fix lint error
diogofonte Mar 7, 2023
08d5ada
fix lint error
diogofonte Mar 7, 2023
1e4522b
fix: wrong tests
CarlosMealha Apr 11, 2023
52d174f
tests: progress
CarlosMealha May 22, 2023
bb00a39
tests: fixed frontend tests
CarlosMealha May 23, 2023
8329b29
feature: show hidden button style done on desktop
CarlosMealha Oct 28, 2022
a6c683e
feat: inserted the reset advanced search and show hidden offers butto…
CarlosMealha Nov 15, 2022
01cf55d
feat: showHidden is already working
CarlosMealha Nov 15, 2022
b64b57f
test: adds showHidden test
CarlosMealha Jan 24, 2023
223b565
feature: show hidden button style done on desktop
CarlosMealha Oct 28, 2022
a2f2c76
feat: inserted the reset advanced search and show hidden offers butto…
CarlosMealha Nov 15, 2022
5770874
feat: showHidden is already working
CarlosMealha Nov 15, 2022
2f89999
tests: adds various tests to showHidden
CarlosMealha Feb 7, 2023
9a7b4e2
test: adds more showHidden tests
CarlosMealha Feb 12, 2023
69792ce
feature: adds show hidden offers to mobile
diogofonte Feb 28, 2023
9fd299e
fix: fixes search results bug in mobile
diogofonte Feb 28, 2023
f4221fa
feature: adds show hidden to url
diogofonte Feb 28, 2023
56ea8a7
reset fields working with show hidden offers
diogofonte Mar 6, 2023
a9427b7
fix lint error
diogofonte Mar 7, 2023
5dcf960
fix lint error
diogofonte Mar 7, 2023
043e35a
feature: show hidden button style done on desktop
CarlosMealha Oct 28, 2022
9a3493d
feat: showHidden is already working
CarlosMealha Nov 15, 2022
4c8a84a
feature: show hidden button style done on desktop
CarlosMealha Oct 28, 2022
8248a74
feat: inserted the reset advanced search and show hidden offers butto…
CarlosMealha Nov 15, 2022
ba8601e
feat: showHidden is already working
CarlosMealha Nov 15, 2022
45389c2
tests: adds various tests to showHidden
CarlosMealha Feb 7, 2023
7c0378a
feature: adds show hidden to url
diogofonte Feb 28, 2023
bb39894
reset fields working with show hidden offers
diogofonte Mar 6, 2023
e01a861
fix lint error
diogofonte Mar 7, 2023
b7412a0
fix lint error
diogofonte Mar 7, 2023
b013fef
fix: wrong tests
CarlosMealha Apr 11, 2023
b4f729b
tests: progress
CarlosMealha May 22, 2023
0b58f92
tests: fixed frontend tests
CarlosMealha May 23, 2023
a06e434
fix: show hidden state
CarlosMealha May 23, 2023
1d046e2
Merge branch 'feature/showHiddenToAdmin' of github.com:NIAEFEUP/nijob…
CarlosMealha May 23, 2023
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
7 changes: 7 additions & 0 deletions src/actions/searchOffersActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const OfferSearchTypes = Object.freeze({
DISABLE_OFFER: "DISABLE_OFFER",
COMPANY_ENABLE_OFFER: "COMPANY_ENABLE_OFFER",
ADMIN_ENABLE_OFFER: "ADMIN_ENABLE_OFFER",
SET_SHOW_HIDDEN: "SET_SHOW_HIDDEN",
});

export const setLoadingOffers = (loading) => ({
Expand Down Expand Up @@ -99,10 +100,16 @@ export const adminEnableOffer = (offerIdx) => ({
offerIdx,
});

export const setShowHidden = (showHidden) => ({
type: OfferSearchTypes.SET_SHOW_HIDDEN,
showHidden,
});

export const resetAdvancedSearchFields = () => (dispatch) => {
dispatch(setJobType(INITIAL_JOB_TYPE));
dispatch(setShowJobDurationSlider(false));
dispatch(setJobDuration(INITIAL_JOB_DURATION, INITIAL_JOB_DURATION + 1));
dispatch(setFields([]));
dispatch(setTechs([]));
dispatch(setShowHidden(false));
};
12 changes: 12 additions & 0 deletions src/actions/searchOffersActions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
resetAdvancedSearchFields,
setOffersFetchError,
resetOffersFetchError,
setShowHidden,
} from "./searchOffersActions";

import { INITIAL_JOB_TYPE, INITIAL_JOB_DURATION } from "../reducers/searchOffersReducer";
Expand Down Expand Up @@ -54,6 +55,17 @@ describe("Search Offers actions", () => {
expect(setSearchValue(value)).toEqual(expectedAction);
});

it("should return Set Show Hidden action", () => {

const showHidden = true;
const expectedAction = {
type: OfferSearchTypes.SET_SHOW_HIDDEN,
showHidden,
};

expect(setShowHidden(showHidden)).toEqual(expectedAction);
});

it("should return Set Job Duration action", () => {

const jobDuration = [1, 2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FormHelperText,
Button,
} from "@material-ui/core";
import useSession from "../../../../hooks/useSession";

import JobOptions from "../../../utils/offers/JobOptions";
import useSearchAreaStyles from "../searchAreaStyle";
Expand Down Expand Up @@ -40,11 +41,19 @@ JobDurationCollapse.propTypes = {

const AdvancedSearchDesktop = () => {

const { data,
isValidating,
error,
isLoggedIn,
} = useSession();
const sessionData = (!isValidating && !error && isLoggedIn) ? data : null;

const classes = useSearchAreaStyles();

const {
advancedOptions, resetAdvancedSearch, FieldsSelectorProps, TechsSelectorProps, JobTypeSelectorProps, JobDurationSwitchProps,
ResetButtonProps, JobDurationSliderText, JobDurationCollapseProps, JobDurationSwitchLabel, JobDurationSliderProps,
ResetButtonProps, JobDurationSliderText, JobDurationCollapseProps, JobDurationSwitchLabel, ShowHiddenSwitchLabel,
JobDurationSliderProps, ShowHiddenSwitchProps,
} = useContext(AdvancedSearchControllerContext);

return (
Expand Down Expand Up @@ -94,8 +103,6 @@ const AdvancedSearchDesktop = () => {
className: "chip-wrapper",
}}
/>
</Collapse>
{advancedOptions &&
<div className={classes.resetBtnWrapper}>
<Button
{...ResetButtonProps}
Expand All @@ -106,7 +113,14 @@ const AdvancedSearchDesktop = () => {
Reset Advanced Fields
</Button>
</div>
}
{sessionData?.isAdmin &&
<FormControlLabel
className={classes.showHiddenToggle}
control={<Switch {...ShowHiddenSwitchProps} />}
label={ShowHiddenSwitchLabel}
/>
}
</Collapse>
</React.Fragment>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import FieldOptions from "../../../utils/offers/FieldOptions";
import TechOptions from "../../../utils/offers/TechOptions";
import { INITIAL_JOB_DURATION, INITIAL_JOB_TYPE } from "../../../../reducers/searchOffersReducer";
import { createTheme } from "@material-ui/core/styles";
import useSession from "../../../../hooks/useSession";

import { MemoryRouter } from "react-router-dom";

jest.mock("../../../../hooks/useSession");

const AdvancedSearchWrapper = ({
children,
enableAdvancedSearchDefault,
Expand All @@ -25,6 +28,8 @@ const AdvancedSearchWrapper = ({
setJobType = () => { },
fields = [],
setFields = () => { },
showHidden,
setShowHidden = () => { },
technologies = [],
setTechs = () => { },
resetAdvancedSearchFields,
Expand All @@ -43,6 +48,7 @@ const AdvancedSearchWrapper = ({
enableAdvancedSearchDefault, showJobDurationSlider, setShowJobDurationSlider, jobMinDuration,
jobMaxDuration, setJobDuration, jobType, setJobType, fields, setFields, technologies, setTechs,
resetAdvancedSearchFields, onSubmit, searchValue, searchOffers, onMobileClose, setSearchValue,
showHidden, setShowHidden,
},
AdvancedSearchControllerContext
);
Expand All @@ -67,6 +73,7 @@ describe("AdvancedSearchDesktop", () => {

describe("render", () => {
it("should render a job selector with all job types", () => {
useSession.mockImplementation(() => ({}));

renderWithStoreAndTheme(
<RouteWrappedComponent>
Expand All @@ -92,6 +99,8 @@ describe("AdvancedSearchDesktop", () => {

it("should toggle job duration slider (on)", () => {
const setShowJobDurationSliderMock = jest.fn();
useSession.mockImplementation(() => ({}));

renderWithStoreAndTheme(
<RouteWrappedComponent>
<AdvancedSearchWrapper
Expand All @@ -116,6 +125,8 @@ describe("AdvancedSearchDesktop", () => {

it("should toggle job duration slider (off)", () => {
const setShowJobDurationSliderMock = jest.fn();
useSession.mockImplementation(() => ({}));

renderWithStoreAndTheme(
<RouteWrappedComponent>
<AdvancedSearchWrapper
Expand All @@ -137,6 +148,54 @@ describe("AdvancedSearchDesktop", () => {
expect(setShowJobDurationSliderMock).toHaveBeenCalledWith(false);
});


it("should toggle show hidden (on)", () => {
const setShowHiddenMock = jest.fn();
useSession.mockImplementation(() => ({ isLoggedIn: true, data: { isAdmin: true } }));

renderWithStoreAndTheme(
<RouteWrappedComponent>
<AdvancedSearchWrapper
enableAdvancedSearchDefault
showHidden={false}
setShowHidden={setShowHiddenMock}
>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</RouteWrappedComponent>,
{ initialState, theme }
);

fireEvent.click(screen.getByLabelText("Show Hidden Offers"));
expect(setShowHiddenMock).toHaveBeenCalledWith(true);
// Can't test that element is visible now (after toggling), since we can't emulate redux logic, wihtout having the whole tree,
// So, I'll just assert that when showJobDurationSlider=true, it shows correctly in the next test
});

it("should toggle show hidden (off)", () => {
const setShowHiddenMock = jest.fn();
useSession.mockImplementation(() => ({ isLoggedIn: true, data: { isAdmin: true } }));

renderWithStoreAndTheme(
<RouteWrappedComponent>
<AdvancedSearchWrapper
enableAdvancedSearchDefault
showHidden={true}
setShowHidden={setShowHiddenMock}
>
<AdvancedSearchDesktop />
</AdvancedSearchWrapper>
</RouteWrappedComponent>,
{ initialState, theme }
);

fireEvent.click(screen.getByLabelText("Show Hidden Offers"));
expect(setShowHiddenMock).toHaveBeenCalledWith(false);
// Can't test that element is visible now (after toggling), since we can't emulate redux logic, wihtout having the whole tree,
// So, I'll just assert that when showJobDurationSlider=true, it shows correctly in the next test
});


it("should render a fields selector with all field types", () => {

renderWithStoreAndTheme(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import MultiOptionAutocomplete from "../../../utils/form/MultiOptionAutocomplete
import JobOptions from "../../../utils/offers/JobOptions";
import useSearchAreaStyles from "../searchAreaStyle";
import { AdvancedSearchControllerContext } from "../SearchArea";
import useSession from "../../../../hooks/useSession";

const JobDurationCollapse = ({ className, JobDurationCollapseProps, JobDurationSliderProps, sliderText }) => (
<Collapse
Expand Down Expand Up @@ -73,8 +74,8 @@ const AdvancedSearchMobile = () => {

const { advancedOptions, toggleAdvancedOptions, searchValue, submitForm,
setSearchValue, FieldsSelectorProps, TechsSelectorProps, resetAdvancedSearch, JobDurationSliderText, ResetButtonProps,
JobTypeSelectorProps, JobDurationSwitchProps, JobDurationCollapseProps, JobDurationSwitchLabel, JobDurationSliderProps,
onMobileClose,
JobTypeSelectorProps, JobDurationSwitchProps, JobDurationCollapseProps, JobDurationSwitchLabel, ShowHiddenSwitchLabel,
JobDurationSliderProps, onMobileClose, ShowHiddenSwitchProps,
} = useContext(AdvancedSearchControllerContext);

const handleResetClick = (e) => {
Expand All @@ -96,9 +97,15 @@ const AdvancedSearchMobile = () => {
const handleExit = () => {
if (shouldSubmitForm) submitForm();
if (onMobileClose) onMobileClose();

};

const { data,
isValidating,
error,
isLoggedIn,
} = useSession();
const sessionData = (!isValidating && !error && isLoggedIn) ? data : null;

const classes = useSearchAreaStyles();

return (
Expand Down Expand Up @@ -151,6 +158,13 @@ const AdvancedSearchMobile = () => {
JobDurationSliderProps={JobDurationSliderProps}
sliderText={JobDurationSliderText}
/>
{sessionData?.isAdmin &&
<FormControlLabel
className={classes.showHiddenToggle}
control={<Switch {...ShowHiddenSwitchProps} />}
label={ShowHiddenSwitchLabel}
/>
}
</FormGroup>
</DialogContent>
<DialogActions classes={{ root: classes.mobileAdvancedSearchActions }}>
Expand Down Expand Up @@ -190,6 +204,8 @@ AdvancedSearchMobile.propTypes = {
JobDurationSwitchLabel: PropTypes.string,
JobDurationSliderProps: PropTypes.object,
onMobileClose: PropTypes.func,
ShowHiddenSwitchProps: PropTypes.object,
ShowHiddenSwitchLabel: PropTypes.string,
};

export default AdvancedSearchMobile;
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const AdvancedSearchWrapper = ({
onMobileClose,
setSearchValue = () => { },
submitForm,
showHidden,
setShowHidden = () => { },
}) => {
const {
ContextProvider,
Expand All @@ -44,7 +46,7 @@ const AdvancedSearchWrapper = ({
enableAdvancedSearchDefault, showJobDurationSlider, setShowJobDurationSlider, jobMinDuration,
jobMaxDuration, setJobDuration, jobType, setJobType, fields, setFields, technologies, setTechs,
resetAdvancedSearchFields, onSubmit, searchValue, searchOffers, onMobileClose, setSearchValue,
submitForm,
submitForm, showHidden, setShowHidden,
},
AdvancedSearchControllerContext
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default ({
technologies,
setTechs,
resetAdvancedSearchFields,
showHidden,
setShowHidden,
}) => {

const jobDuration = [jobMinDuration, jobMaxDuration];
Expand All @@ -30,6 +32,8 @@ export default ({

const JobDurationSwitchLabel = "Filter Job Duration";

const ShowHiddenSwitchLabel = "Show Hidden Offers";

const [advancedOptions, toggleAdvancedOptions] = useToggle(enableAdvancedSearchDefault);

const JobTypeSelectorProps = {
Expand Down Expand Up @@ -70,11 +74,21 @@ export default ({
const FieldsSelectorProps = useFieldSelector(fields, setFields);
const TechsSelectorProps = useTechSelector(technologies, setTechs);

const toggleShowHidden = useCallback(() => {
setShowHidden(!showHidden);
}, [setShowHidden, showHidden]);

const ShowHiddenSwitchProps = {
checked: showHidden,
onChange: toggleShowHidden,
value: "filterShowHiddenOffers",
};

const advancedOptionsActive = showJobDurationSlider
|| (jobType !== INITIAL_JOB_TYPE)
|| fields.length !== 0
|| technologies.length !== 0;
|| technologies.length !== 0
|| showHidden;

const ResetButtonProps = {
disabled: !advancedOptionsActive,
Expand All @@ -101,5 +115,7 @@ export default ({
JobDurationSliderProps,
JobDurationSliderText,
ResetButtonProps,
ShowHiddenSwitchProps,
ShowHiddenSwitchLabel,
};
};
Loading