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 dnd support to search panel, highlight searched rule, UI adjustments #640

Merged
merged 15 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 10 additions & 4 deletions frontend/degree-plan/components/FourYearPlanPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const PanelWrapper = styled(Pane)`
height: 100%;
display: flex;
flex-direction: row;
gap: 2rem;
gap: 0.8rem;
`

const PanelInteriorWrapper = styled.div<{ $maxWidth?: string; $minWidth?: string }>`
Expand Down Expand Up @@ -104,6 +104,7 @@ const FourYearPlanPage = ({
const ref = useRef(null);

// search panel
const [searchedRuleId, setSearchedRuleId] = useState(-1);
yuntongf marked this conversation as resolved.
Show resolved Hide resolved
const [searchPanelOpen, setSearchPanelOpen] = useState<boolean>(false);
const [searchRuleId, setSearchRuleId] = useState<Rule["id"] | null>(null);
const [searchRuleQuery, setSearchRuleQuery] = useState<string | null>(null); // a query object
Expand Down Expand Up @@ -160,7 +161,10 @@ const FourYearPlanPage = ({
// @ts-ignore */}
<SplitPane
split="vertical"
maxSize={windowWidth ? windowWidth * 0.65 : 1000}
// maxSize={windowWidth ? windowWidth * 0.60 : 1000}
maxSize={searchPanelOpen ?
(windowWidth ? windowWidth : 1000) * 0.45
: (windowWidth ? windowWidth : 1000) * 0.6}
defaultSize="50%"
style={{
padding: "1.5rem",
Expand Down Expand Up @@ -194,12 +198,14 @@ const FourYearPlanPage = ({
setModalKey={setModalKey}
setModalObject={setModalObject}
isLoading={isLoadingDegreeplans}
searchedRuleId={searchedRuleId}
setSearchedRuleId={setSearchedRuleId}
activeDegreeplan={activeDegreeplan}
/>
</PanelInteriorWrapper>
{searchPanelOpen && (
<PanelInteriorWrapper $minWidth={"40%"} $maxWidth={"45%"}>
<SearchPanel activeDegreeplanId={activeDegreeplan ? activeDegreeplan.id : null} />
<PanelInteriorWrapper $minWidth={"40%"} $maxWidth={"43%"}>
<SearchPanel activeDegreeplanId={activeDegreeplan ? activeDegreeplan.id : null} setSearchedRuleId={setSearchedRuleId}/>
</PanelInteriorWrapper>
)}
</PanelWrapper>
Expand Down
53 changes: 45 additions & 8 deletions frontend/degree-plan/components/Requirements/QObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,18 @@ const Attributes = ({ attributes }: { attributes: string[] }) => {
</AttributeWrapper>
}

const SearchConditionWrapper = styled(BaseCourseContainer)`
const SearchConditionWrapper = styled(BaseCourseContainer)<{$isSearched: boolean}>`
display: flex;
flex-wrap: wrap;
gap: .5rem;
background-color: var(--primary-color-light);
box-shadow: 0px 0px 14px 2px rgba(0, 0, 0, 0.05);
cursor: pointer;
padding: .5rem .75rem;
${props => !!props.$isSearched && `
border-radius: 10px;
box-shadow: 8px 6px 10px 8px #00000026;
`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shadow looks a little weird bc it's so strong. Maybe we could change the color or apply some other effect to the surface of the search condition when clicked? let me know what you think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to lighter and less aggressive shadow, similar to the one shown for droppable boxes

`

const Wrap = styled.span`
Expand Down Expand Up @@ -176,15 +180,19 @@ interface SearchConditionProps extends SearchConditionInnerProps {
ruleIsSatisfied: boolean,
ruleId: Rule["id"];
ruleQuery: string;
activeDegreeplanId: DegreePlan["id"]
activeDegreeplanId: DegreePlan["id"];
searchedRuleId: number;
setSearchedRuleId: (arg0: number) => void;
}
const SearchCondition = ({ ruleId, ruleQuery, fulfillments, ruleIsSatisfied, q, activeDegreeplanId}: SearchConditionProps) => {
const SearchCondition = ({ ruleId, ruleQuery, fulfillments, ruleIsSatisfied, q, activeDegreeplanId, searchedRuleId, setSearchedRuleId}: SearchConditionProps) => {
const { setSearchPanelOpen, setSearchRuleQuery, setSearchRuleId, setSearchFulfillments } = useContext(SearchPanelContext);

return (
<SearchConditionWrapper
$isDisabled={false}
$isUsed={false}
$isSearched={searchedRuleId == ruleId}

>
<SearchConditionInner q={q} />
<DarkGrayIcon onClick={() => {
Expand Down Expand Up @@ -260,8 +268,10 @@ interface QObjectProps {
rule: Rule;
satisfied: boolean;
activeDegreePlanId: number;
searchedRuleId: number;
setSearchedRuleId: (arg0: number) => void;
}
const QObject = ({ q, fulfillments, rule, satisfied, activeDegreePlanId }: QObjectProps) => {
const QObject = ({ q, fulfillments, rule, satisfied, activeDegreePlanId, searchedRuleId, setSearchedRuleId }: QObjectProps) => {

// recursively render
switch (q.type) {
Expand Down Expand Up @@ -300,7 +310,15 @@ const QObject = ({ q, fulfillments, rule, satisfied, activeDegreePlanId }: QObje
const displaySearchConditions = searchConditions.map(search => {
const courses = Array.from(fulfillmentsMap.values())
fulfillmentsMap.clear()
return <SearchCondition fulfillments={courses} q={search.q} ruleIsSatisfied={satisfied} ruleId={rule.id} ruleQuery={rule.q} activeDegreeplanId={activeDegreePlanId}/>
return <SearchCondition
fulfillments={courses}
q={search.q}
ruleIsSatisfied={satisfied}
ruleId={rule.id}
ruleQuery={rule.q}
activeDegreeplanId={activeDegreePlanId}
searchedRuleId={searchedRuleId}
setSearchedRuleId={setSearchedRuleId}/>
})

return <Row $wrap>
Expand All @@ -310,7 +328,16 @@ const QObject = ({ q, fulfillments, rule, satisfied, activeDegreePlanId }: QObje
)}
</Row>
case "SEARCH":
return <SearchCondition q={q.q} ruleIsSatisfied={satisfied} fulfillments={fulfillments} ruleId={rule.id} ruleQuery={rule.q} activeDegreeplanId={activeDegreePlanId}/>;
return <SearchCondition
q={q.q}
ruleIsSatisfied={satisfied}
fulfillments={fulfillments}
ruleId={rule.id}
ruleQuery={rule.q}
activeDegreeplanId={activeDegreePlanId}
searchedRuleId={searchedRuleId}
setSearchedRuleId={setSearchedRuleId}
/>;
case "COURSE":
const [fulfillment] = fulfillments.filter(fulfillment => fulfillment.full_code == q.full_code && (!q.semester || q.semester === fulfillment.semester))
return <CourseInReq course={{...q, rules: fulfillment ? fulfillment.rules : []}} fulfillment={fulfillment} isDisabled={satisfied && !fulfillment} isUsed={!!fulfillment} rule_id={rule.id} activeDegreePlanId={activeDegreePlanId}/>;
Expand All @@ -324,6 +351,8 @@ interface RuleLeafProps {
rule: Rule;
satisfied: boolean;
activeDegreePlanId: number;
searchedRuleId: number;
setSearchedRuleId: (arg0: number) => void;
}

export const SkeletonRuleLeaf = () => (
Expand All @@ -344,15 +373,23 @@ export const SkeletonRuleLeaf = () => (
const RuleLeafWrapper = styled(Row)`
margin-bottom: .5rem;
`
const RuleLeaf = ({ q_json, fulfillmentsForRule, rule, satisfied, activeDegreePlanId }: RuleLeafProps) => {
const RuleLeaf = ({ q_json, fulfillmentsForRule, rule, satisfied, activeDegreePlanId, searchedRuleId, setSearchedRuleId }: RuleLeafProps) => {
const t1 = transformDepartmentInClauses(q_json);
const t2 = transformCourseClauses(t1);
const t3 = transformSearchConditions(t2)
q_json = t3 as TransformedQObject;

return (
<RuleLeafWrapper $wrap>
<QObject q={q_json} fulfillments={fulfillmentsForRule} rule={rule} satisfied={satisfied} activeDegreePlanId={activeDegreePlanId} />
<QObject
q={q_json}
fulfillments={fulfillmentsForRule}
rule={rule}
satisfied={satisfied}
activeDegreePlanId={activeDegreePlanId}
searchedRuleId={searchedRuleId}
setSearchedRuleId={setSearchedRuleId}
/>
</RuleLeafWrapper>
)
}
Expand Down
12 changes: 9 additions & 3 deletions frontend/degree-plan/components/Requirements/ReqPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const computeRuleTree = ({ activeDegreePlanId, rule, rulesToFulfillments }: Rule
}


const Degree = ({degree, rulesToFulfillments, activeDegreeplan, editMode, setModalKey, setModalObject, isLoading}: any) => {
const Degree = ({degree, rulesToFulfillments, activeDegreeplan, editMode, setModalKey, setModalObject, isLoading, searchedRuleId, setSearchedRuleId}: any) => {
const [collapsed, setCollapsed] = useState(false);
if (isLoading) {
return (
Expand Down Expand Up @@ -216,7 +216,9 @@ const Degree = ({degree, rulesToFulfillments, activeDegreeplan, editMode, setMod
<DegreeBody>
{degree && degree.rules.map((rule: any) => (
<RuleComponent
{...computeRuleTree({ activeDegreePlanId: activeDegreeplan.id, rule, rulesToFulfillments })}
ruleTree={{...computeRuleTree({ activeDegreePlanId: activeDegreeplan.id, rule, rulesToFulfillments })}}
searchedRuleId={searchedRuleId}
setSearchedRuleId={setSearchedRuleId}
/>
))}
</DegreeBody>}
Expand All @@ -229,8 +231,10 @@ interface ReqPanelProps {
setModalObject: (arg0: DegreePlan | null) => void;
activeDegreeplan: DegreePlan | null;
isLoading: boolean;
searchedRuleId: number;
setSearchedRuleId: (arg0: number) => void;
}
const ReqPanel = ({setModalKey, setModalObject, activeDegreeplan, isLoading}: ReqPanelProps) => {
const ReqPanel = ({setModalKey, setModalObject, activeDegreeplan, isLoading, searchedRuleId, setSearchedRuleId}: ReqPanelProps) => {
const [editMode, setEditMode] = React.useState(false);
const { data: activeDegreeplanDetail = null, isLoading: isLoadingDegrees } = useSWR<DegreePlan>(activeDegreeplan ? `/api/degree/degreeplans/${activeDegreeplan.id}` : null);
const { data: fulfillments, isLoading: isLoadingFulfillments } = useSWR<Fulfillment[]>(activeDegreeplan ? `/api/degree/degreeplans/${activeDegreeplan.id}/fulfillments` : null);
Expand Down Expand Up @@ -271,6 +275,8 @@ const ReqPanel = ({setModalKey, setModalObject, activeDegreeplan, isLoading}: Re
setModalKey={setModalKey}
setModalObject={setModalObject}
isLoading={isLoading}
searchedRuleId={searchedRuleId}
setSearchedRuleId={setSearchedRuleId}
/>
))}
{editMode && <AddButton role="button" onClick={() => {
Expand Down
25 changes: 20 additions & 5 deletions frontend/degree-plan/components/Requirements/Rule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ const RuleLeafLabel = styled.div`
`

const RuleLeafContainer = styled(Column)`
margin-top: 0.25rem;
margin: 0.25rem;
}
`


Expand Down Expand Up @@ -147,7 +148,13 @@ export const SkeletonRule: React.FC<React.PropsWithChildren> = ({ children }) =>
/**
* Recursive component to represent a rule.
*/
const RuleComponent = (ruleTree : RuleTree) => {
interface RuleComponentProps {
ruleTree: RuleTree,
searchedRuleId: number,
setSearchedRuleId: (arg0: number) => void
}

const RuleComponent = ({ruleTree, searchedRuleId, setSearchedRuleId} : RuleComponentProps) => {
const { type, activeDegreePlanId, rule, progress } = ruleTree;
const satisfied = progress === 1;

Expand Down Expand Up @@ -181,7 +188,15 @@ const RuleComponent = (ruleTree : RuleTree) => {
<RuleLeafContainer>
<RuleLeafLabel>{rule.title}</RuleLeafLabel>
<RuleLeafWrapper $isDroppable={canDrop} $isOver={isOver} ref={drop}>
<RuleLeaf q_json={rule.q_json} rule={rule} fulfillmentsForRule={fulfillments} satisfied={satisfied} activeDegreePlanId={activeDegreePlanId}/>
<RuleLeaf
q_json={rule.q_json}
rule={rule}
fulfillmentsForRule={fulfillments}
satisfied={satisfied}
activeDegreePlanId={activeDegreePlanId}
searchedRuleId={searchedRuleId}
setSearchedRuleId={setSearchedRuleId}
/>
<Row>
{!!satisfied && <SatisfiedCheck />}
<Column>
Expand Down Expand Up @@ -210,7 +225,7 @@ const RuleComponent = (ruleTree : RuleTree) => {
</PickNTitle>
{children.map((ruleTree) => (
<div>
<RuleComponent {...ruleTree} />
<RuleComponent ruleTree={{...ruleTree}} searchedRuleId={searchedRuleId} setSearchedRuleId={setSearchedRuleId}/>
</div>
))}
</PickNWrapper>
Expand Down Expand Up @@ -239,7 +254,7 @@ const RuleComponent = (ruleTree : RuleTree) => {
<Column>
{children.map((ruleTree) => (
<div>
<RuleComponent {...ruleTree} />
<RuleComponent ruleTree={{...ruleTree}} searchedRuleId={searchedRuleId} setSearchedRuleId={setSearchedRuleId}/>
</div>
))}
</Column>
Expand Down
16 changes: 12 additions & 4 deletions frontend/degree-plan/components/Search/CourseInSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Course as CourseType, DnDCourse, Rule } from "@/types";
import Skeleton from "react-loading-skeleton";
import 'react-loading-skeleton/dist/skeleton.css'
import { ReviewPanelTrigger } from "../Infobox/ReviewPanel";
import CourseComponent from "../Course/Course";


const RowSelectors = styled.li`
Expand Down Expand Up @@ -155,6 +156,13 @@ export default function Course({
// isDragging: !!monitor.isDragging(),
// })
// }))
const [{ isDragging }, drag] = useDrag<DnDCourse, never, { isDragging: boolean }>(() => ({
type: ItemTypes.COURSE_IN_PLAN,
item: {full_code: course.id},
collect: (monitor) => ({
isDragging: !!monitor.isDragging()
})
}), [course])

const [isMouseOver, setIsMouseOver] = useState(false);

Expand All @@ -166,12 +174,12 @@ export default function Course({
role="button"
>
<CourseIdentityContainer >
<CourseIDContainer>
<CourseIDContainer ref={drag} className="draggable">
<CourseID>{course.id.replace(/-/g, " ")}</CourseID>
{isMouseOver &&
{/* {isMouseOver &&
<AddButton onClick={onClick}>
<i className="fas fa-md fa-plus-circle" aria-hidden="true"></i>
</AddButton>}
</AddButton>} */}
</CourseIDContainer>
<CourseTitle>{course.title}</CourseTitle>
</CourseIdentityContainer>
Expand All @@ -188,4 +196,4 @@ export default function Course({
</ReviewPanelTrigger>
</RowSelectors>
);
}
}
2 changes: 1 addition & 1 deletion frontend/degree-plan/components/Search/ResultsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const ResultsList = ({
// star means the course is a fulfillment
isStar={!!fulfillments.find((fulfillment) => fulfillment.full_code == course.id)}
/>) :
Array.from(Array(3).keys()).map(() => <SkeletonCourse />)
Array.from(Array(5).keys()).map(() => <SkeletonCourse />)
}
</CoursesContainer>
</CourseListContainer>
Expand Down
17 changes: 14 additions & 3 deletions frontend/degree-plan/components/Search/SearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ const SearchPanelHeader = styled(PanelHeader)`
font-size: 1.25rem;
`

export const SearchPanel = ({ activeDegreeplanId }: { activeDegreeplanId: DegreePlan["id"] | null }) => {
interface SearchPanelProp {
activeDegreeplanId: DegreePlan["id"] | null;
setSearchedRuleId: (arg0: number) => void;
}

export const SearchPanel = ({ activeDegreeplanId, setSearchedRuleId }: SearchPanelProp) => {
const {
setSearchPanelOpen,
searchRuleId: ruleId,
Expand All @@ -95,11 +100,17 @@ export const SearchPanel = ({ activeDegreeplanId }: { activeDegreeplanId: Degree
setQueryString("");
}, [ruleId])

const handleCloseSearch = () => {
setQueryString("");
setSearchPanelOpen(false);
setSearchedRuleId(-1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the value should be null instead of -1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea makes sense

}

return (
<PanelContainer>
<SearchPanelHeader>
<PanelTitle>Search</PanelTitle>
<label onClick={() => {setQueryString(""); setSearchPanelOpen(false);}}>
<label onClick={handleCloseSearch}>
<i className="fa fa-times" />
</label>
</SearchPanelHeader>
Expand All @@ -116,7 +127,7 @@ export const SearchPanel = ({ activeDegreeplanId }: { activeDegreeplanId: Degree
value={queryString}
onChange={(e) => {setQueryString(e.target.value)}}
autoComplete="off"
placeholder={!ruleId ? "Search for a course!" : `Filtering for ${ruleQuery ? ruleQuery : 'a requirement'}`}
placeholder={!ruleId ? "Search for a course!" : `Filtering for a requirement`}
/>
</SearchContainer>
<SearchResults ruleId={ruleId} query={queryString} activeDegreeplanId={activeDegreeplanId} fulfillments={fulfillments}/>
Expand Down
Loading