-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: Added a common dropdown component #5826
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from "react"; | ||
import { TCycleEstimateType } from "@plane/types"; | ||
import { CustomSelect } from "@plane/ui"; | ||
import { useCycle, useProjectEstimates } from "@/hooks/store"; | ||
import { cycleEstimateOptions } from "../analytics-sidebar"; | ||
|
||
type TProps = { | ||
value: TCycleEstimateType; | ||
onChange: (value: TCycleEstimateType) => Promise<void>; | ||
showDefault?: boolean; | ||
projectId: string; | ||
cycleId: string; | ||
}; | ||
|
||
export const EstimateTypeDropdown = (props: TProps) => { | ||
const { value, onChange, projectId, cycleId, showDefault = false } = props; | ||
const { getIsPointsDataAvailable } = useCycle(); | ||
const { areEstimateEnabledByProjectId } = useProjectEstimates(); | ||
const isCurrentProjectEstimateEnabled = projectId && areEstimateEnabledByProjectId(projectId) ? true : false; | ||
return getIsPointsDataAvailable(cycleId) || isCurrentProjectEstimateEnabled ? ( | ||
<div className="relative flex items-center gap-2"> | ||
<CustomSelect | ||
value={value} | ||
label={<span>{cycleEstimateOptions.find((v) => v.value === value)?.label ?? "None"}</span>} | ||
onChange={onChange} | ||
maxHeight="lg" | ||
buttonClassName="bg-custom-background-90 border-none rounded text-sm font-medium " | ||
> | ||
{cycleEstimateOptions.map((item) => ( | ||
<CustomSelect.Option key={item.value} value={item.value}> | ||
{item.label} | ||
</CustomSelect.Option> | ||
))} | ||
</CustomSelect> | ||
</div> | ||
) : showDefault ? ( | ||
<span className="capitalize">{value}</span> | ||
) : null; | ||
}; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./filters"; | ||
export * from "./estimate-type-dropdown"; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { isFuture, isPast, isToday } from "date-fns"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import isEmpty from "lodash/isEmpty"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import set from "lodash/set"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import sortBy from "lodash/sortBy"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { action, computed, observable, makeObservable, runInAction } from "mobx"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -58,6 +59,8 @@ export interface ICycleStore { | |||||||||||||||||||||||||||||||||||||||||||||||||||
getProjectCycleIds: (projectId: string) => string[] | null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
getPlotTypeByCycleId: (cycleId: string) => TCyclePlotType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
getEstimateTypeByCycleId: (cycleId: string) => TCycleEstimateType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
getIsPointsDataAvailable: (cycleId: string) => boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// actions | ||||||||||||||||||||||||||||||||||||||||||||||||||||
updateCycleDistribution: (distributionUpdates: DistributionUpdates, cycleId: string) => void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
validateDate: (workspaceSlug: string, projectId: string, payload: CycleDateCheckData) => Promise<any>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -271,6 +274,18 @@ export class CycleStore implements ICycleStore { | |||||||||||||||||||||||||||||||||||||||||||||||||||
return this.cycleMap?.[this.currentProjectActiveCycleId!] ?? null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
getIsPointsDataAvailable = computedFn((cycleId: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log(this.cycleMap[cycleId]?.version); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const cycle = this.cycleMap[cycleId]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!cycle) return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (this.cycleMap[cycleId].version === 2) return cycle.progress.some((p) => p.total_estimate_points > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
else if (this.cycleMap[cycleId].version === 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log({ ...cycle.estimate_distribution?.completion_chart }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const completionChart = cycle.estimate_distribution?.completion_chart || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return !isEmpty(completionChart) && Object.keys(completionChart).some((p) => completionChart[p]! > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} else return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve The new method looks good overall, but there are a few improvements we can make:
Here's a suggested refactor: getIsPointsDataAvailable = computedFn((cycleId: string) => {
- console.log(this.cycleMap[cycleId]?.version);
const cycle = this.cycleMap[cycleId];
if (!cycle) return false;
- if (this.cycleMap[cycleId].version === 2) return cycle.progress.some((p) => p.total_estimate_points > 0);
- else if (this.cycleMap[cycleId].version === 1) {
- console.log({ ...cycle.estimate_distribution?.completion_chart });
+
+ switch(cycle.version) {
+ case 2:
+ return cycle.progress.some((p) => p.total_estimate_points > 0);
+ case 1:
const completionChart = cycle.estimate_distribution?.completion_chart || {};
return !isEmpty(completionChart) && Object.keys(completionChart).some((p) => completionChart[p]! > 0);
- } else return false;
+ default:
+ return false;
+ }
}); This refactored version improves readability and handles all cases more explicitly. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
* returns active cycle progress for a project | ||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding prop validation for improved robustness.
The component is well-structured and follows the Single Responsibility Principle. To further improve its robustness, consider adding prop validation.
You can use PropTypes (if you prefer runtime checking) or leverage TypeScript's built-in type checking by explicitly declaring the component's prop types:
This change will provide better type inference and catch potential prop-related errors at compile-time.
🧰 Tools
🪛 Biome