Skip to content

Commit 6d1b61c

Browse files
authored
Fix migration bugs (#7007)
1 parent d106458 commit 6d1b61c

File tree

17 files changed

+118
-58
lines changed

17 files changed

+118
-58
lines changed

frontend/src/components/CreateCollectionModal/components/Content/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ const Content: FC<Props> = (props) => {
183183
<Form ref={formEl} autoComplete="off">
184184
{/* Collection detail */}
185185
{/* TODO(SDSv20): Another example where using a component as a CSS selector expects parent component to pass in the selector's props */}
186+
{/* (masoudmanson): The error occurred because the isSelected prop was required. Adding a '?' fixed the issue. */}
186187
<CollectionDetail>
187188
{/* Title */}
188189
<Title>Collection Details</Title>
@@ -397,7 +398,10 @@ const Content: FC<Props> = (props) => {
397398
* Handles change to selection of consortia.
398399
* @param selectedConsortia - Selected consortia.
399400
*/
400-
function handleConsortiaChange(selectedConsortia: DropdownValue) {
401+
function handleConsortiaChange(
402+
_: React.SyntheticEvent,
403+
selectedConsortia: DropdownValue
404+
) {
401405
setConsortia(sortConsortia(selectedConsortia));
402406
}
403407

frontend/src/components/Header/components/CuratorAPIKeyGenerator/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export default function CuratorAPIKeyGenerator(): JSX.Element {
4848
[]
4949
);
5050

51+
const handleButtonClose = useCallback((_: DialogOnCloseParams[0]) => {
52+
setIsOpen(false);
53+
}, []);
54+
5155
const copyAPIKey = useCallback(() => {
5256
navigator.clipboard.writeText(apiKeyResponse.current.key || "");
5357
Toast.show({
@@ -76,7 +80,9 @@ export default function CuratorAPIKeyGenerator(): JSX.Element {
7680
</DialogContent>
7781
<DialogActions>
7882
{/* TODO(SDSv20): Fix handler */}
79-
<SDSButton onClick={handleClose}>Close</SDSButton>
83+
{/* (masoudmanson): The Button onClick handler does not include a reason parameter,
84+
and it should be distinct from the Dialog close handler */}
85+
<SDSButton onClick={handleButtonClose}>Close</SDSButton>
8086
<SDSButton sdsType="primary" sdsStyle="square" onClick={copyAPIKey}>
8187
Copy API Key
8288
</SDSButton>

frontend/src/components/common/Form/Dropdown/index.tsx

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
2-
DefaultDropdownMenuOption,
2+
DefaultAutocompleteOption,
3+
DropdownProps,
34
Dropdown as SDSDropdown,
45
} from "@czi-sds/components";
6+
import { AutocompleteValue } from "@mui/base";
57
import {
68
FormLabelText,
79
Optional,
@@ -11,21 +13,24 @@ import {
1113
DropdownPopper,
1214
} from "src/components/common/Form/Dropdown/style";
1315

14-
type onChangeFn = (options: Value) => void;
15-
export type Value =
16-
| DefaultDropdownMenuOption
17-
| DefaultDropdownMenuOption[]
18-
| null;
16+
export type Value = AutocompleteValue<
17+
DefaultAutocompleteOption,
18+
boolean | undefined,
19+
false,
20+
false
21+
>;
1922

20-
interface Props {
23+
interface Props
24+
extends DropdownProps<
25+
DefaultAutocompleteOption,
26+
boolean | undefined,
27+
false,
28+
false
29+
> {
2130
disablePortal?: boolean;
2231
label: string;
23-
multiple?: boolean;
24-
onChange: onChangeFn;
2532
optionalField?: boolean;
26-
options: DefaultDropdownMenuOption[];
2733
text?: string;
28-
value: Value;
2934
}
3035

3136
const DropdownMenuProps = {
@@ -59,26 +64,26 @@ export default function Dropdown({
5964
{optionalField && <Optional>(optional)</Optional>}
6065
</FormLabelText>
6166
)}
62-
<SDSDropdown
67+
<SDSDropdown<DefaultAutocompleteOption, boolean | undefined, false, false>
6368
closeOnBlur
6469
DropdownMenuProps={DropdownMenuProps}
6570
InputDropdownProps={{ sdsStyle: "square" }}
6671
isTriggerChangeOnOptionClick
67-
label={getDropdownLabel(value, label)}
72+
label={getDropdownLabel(label, value)}
6873
multiple={multiple}
6974
onChange={onChange} // TODO(SDSv20): Come back to this
7075
options={options}
71-
PopperComponent={({ ...props }) => (
72-
<DropdownPopper
73-
disablePortal={disablePortal}
74-
open={props.open}
75-
placement="bottom-start"
76-
style={{
77-
width: props.anchorEl?.offsetWidth, // Set Popper width to equal the dropdown button.
78-
}}
79-
{...props}
80-
/>
81-
)}
76+
PopperComponent={(popperProps) => {
77+
const { anchorEl } = popperProps;
78+
79+
return (
80+
<DropdownPopper
81+
disablePortal={disablePortal}
82+
{...popperProps}
83+
style={{ width: (anchorEl as HTMLButtonElement)?.offsetWidth }}
84+
/>
85+
);
86+
}}
8287
value={value}
8388
/>
8489
</DropdownForm>
@@ -92,7 +97,7 @@ export default function Dropdown({
9297
* @param label - Default "placeholder" label.
9398
* @returns dropdown label.
9499
*/
95-
function getDropdownLabel(value: Value, label: string): string {
100+
function getDropdownLabel(label: string, value?: Value): string {
96101
if (!value || (Array.isArray(value) && value.length === 0)) {
97102
return label;
98103
}
@@ -106,7 +111,7 @@ function getDropdownLabel(value: Value, label: string): string {
106111
* @param value - Selected value.
107112
* @returns true is an option is selected.
108113
*/
109-
function isOptionSelected(value: Value): boolean {
114+
function isOptionSelected(value?: Value): boolean {
110115
if (!value) {
111116
return false;
112117
}

frontend/src/components/common/Form/Dropdown/style.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { css } from "@emotion/react";
88

99
interface DropdownFormProps extends CommonThemeProps {
10-
isSelected: boolean;
10+
isSelected?: boolean;
1111
}
1212

1313
const scrollbar = css`

frontend/src/components/common/MoreDropdown/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MoreButton } from "src/components/common/MoreDropdown/style";
44

55
interface Props {
66
popoverProps?: PopoverProps;
7-
buttonProps?: Partial<ButtonIconProps<"dotsHorizontal", "small">>; // TODO(SDSv20): unsure what the error is
7+
buttonProps?: Partial<ButtonIconProps>;
88
}
99

1010
const MoreDropdown = ({

frontend/src/views/CellGuide/components/CellGuideCard/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ import {
4343
TISSUE_AGNOSTIC,
4444
} from "./components/MarkerGeneTables/constants";
4545
import {
46-
DefaultDropdownMenuOption,
4746
Dropdown,
4847
InputDropdownProps,
4948
Button,
49+
DefaultAutocompleteOption,
5050
} from "@czi-sds/components";
5151
import { useComponentWidth } from "./components/common/hooks/useIsComponentPastBreakpoint";
5252
import { DEFAULT_ONTOLOGY_HEIGHT } from "../common/OntologyDagView/common/constants";
@@ -57,7 +57,7 @@ import { useComputationalMarkerGenesTableRowsAndFilters } from "./components/Mar
5757
import { useConnect } from "./connect";
5858
import { SDSOrgan } from "src/views/CellGuide/components/CellGuideCard/types";
5959
import { getCellTypeLink } from "src/views/CellGuide/common/utils";
60-
import { TextField } from "@mui/material";
60+
import { AutocompleteValue, TextField } from "@mui/material";
6161

6262
export const SDS_INPUT_DROPDOWN_PROPS: InputDropdownProps = {
6363
sdsStyle: "square",
@@ -135,7 +135,8 @@ export default function CellGuideCard({
135135
const titleizedCellTypeName = titleize(cellTypeName);
136136

137137
const handleChangeOrgan = (
138-
option: DefaultDropdownMenuOption | null = null
138+
_: React.SyntheticEvent, // event
139+
option: AutocompleteValue<DefaultAutocompleteOption, false, false, false>
139140
) => {
140141
const { name, id } = (option || {}) as SDSOrgan;
141142

@@ -154,7 +155,10 @@ export default function CellGuideCard({
154155
router.push(url, url, { scroll: false });
155156
};
156157

157-
const handleChangeOrganism = (option: DefaultDropdownMenuOption | null) => {
158+
const handleChangeOrganism = (
159+
_: React.SyntheticEvent,
160+
option: AutocompleteValue<DefaultAutocompleteOption, false, false, false>
161+
) => {
158162
if (!option || option.name === selectedOrganism.name) return;
159163
setSelectedOrganism(option);
160164
track(EVENTS.CG_SELECT_ORGANISM, { organism: option.name });
@@ -213,7 +217,7 @@ export default function CellGuideCard({
213217
}). ${rawSeoDescription}`;
214218

215219
const OrganismSelectorDropdown = (
216-
<Dropdown
220+
<Dropdown<DefaultAutocompleteOption, false, false, false>
217221
InputDropdownProps={SDS_INPUT_DROPDOWN_PROPS}
218222
search
219223
label={selectedOrganism?.name}
@@ -226,7 +230,7 @@ export default function CellGuideCard({
226230
const dropdownComponents = (
227231
<CellGuideCardHeaderInnerWrapper>
228232
{OrganismSelectorDropdown}
229-
<Dropdown
233+
<Dropdown<DefaultAutocompleteOption, false, false, false>
230234
InputDropdownProps={SDS_INPUT_DROPDOWN_PROPS}
231235
search
232236
label={tissueName}

frontend/src/views/CellGuide/components/TissueCard/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ import { StyledOntologyId } from "../CellGuideCard/components/Description/style"
4141
import { useComponentWidth } from "../CellGuideCard/components/common/hooks/useIsComponentPastBreakpoint";
4242
import { track } from "src/common/analytics";
4343
import { EVENTS } from "src/common/analytics/events";
44-
import { DefaultDropdownMenuOption, Dropdown } from "@czi-sds/components";
44+
import { DefaultAutocompleteOption, Dropdown } from "@czi-sds/components";
4545
import { SDS_INPUT_DROPDOWN_PROPS } from "../CellGuideCard";
4646
import { ORGANISM_NAME_TO_TAXON_ID_MAPPING } from "src/common/queries/cellGuide";
47+
import { AutocompleteValue } from "@mui/base";
4748

4849
interface Props {
4950
// From getServerSideProps
@@ -65,7 +66,10 @@ export default function TissueCard({ description, name }: Props): JSX.Element {
6566
Object.keys(ORGANISM_NAME_TO_TAXON_ID_MAPPING)[0]
6667
);
6768

68-
const handleChangeOrganism = (option: DefaultDropdownMenuOption | null) => {
69+
const handleChangeOrganism = (
70+
_: React.SyntheticEvent,
71+
option: AutocompleteValue<DefaultAutocompleteOption, false, false, false>
72+
) => {
6973
if (!option || option.name === tissueCardSelectedOrganism) return;
7074
setTissueCardSelectedOrganism(option.name);
7175
track(EVENTS.CG_SELECT_ORGANISM, { organism: option.name });
@@ -185,7 +189,7 @@ export default function TissueCard({ description, name }: Props): JSX.Element {
185189
/>
186190
</a>
187191
</TissueCardHeaderInnerWrapper>
188-
<Dropdown
192+
<Dropdown<DefaultAutocompleteOption, false, false, false>
189193
InputDropdownProps={SDS_INPUT_DROPDOWN_PROPS}
190194
search
191195
label={tissueCardSelectedOrganism}

frontend/src/views/WheresMyGeneV2/components/Filters/components/ColorScale/connect.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { COLOR_SCALE_OPTIONS } from "./constants";
88
import { track } from "src/common/analytics";
99
import { EVENTS } from "src/common/analytics/events";
1010
import { selectSortBy } from "src/views/WheresMyGeneV2/common/store/actions";
11-
import { Props } from "./types";
11+
import { ColorScaleOptionType, Props } from "./types";
12+
import { AutocompleteValue } from "@mui/base";
1213

1314
export const useConnect = ({
1415
setIsScaled,
@@ -26,7 +27,8 @@ export const useConnect = ({
2627
}, [sortBy]);
2728

2829
function colorScaleOnChange(
29-
value: { id?: SORT_BY; name: string } | null
30+
_: React.SyntheticEvent, // event
31+
value: AutocompleteValue<ColorScaleOptionType, false, false, false>
3032
): void {
3133
if (!dispatch || !value || colorScaledOption.name === value.name) return;
3234
track(EVENTS.WMG_OPTION_SELECT_COLOR_SCALE, {

frontend/src/views/WheresMyGeneV2/components/Filters/components/ColorScale/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010
} from "src/views/WheresMyGeneV2/components/CellInfoSideBar/style";
1111
import { COLOR_SCALE_TOOLTIP_TEXT } from "src/views/WheresMyGeneV2/common/constants";
1212
import { COLOR_SCALE_OPTIONS } from "./constants";
13-
import { DEFAULT_INPUT_DROPDOWN_PROPS, Props } from "./types";
13+
import {
14+
ColorScaleOptionType,
15+
DEFAULT_INPUT_DROPDOWN_PROPS,
16+
Props,
17+
} from "./types";
1418
import { useConnect } from "./connect";
1519

1620
export default function ColorScale({ setIsScaled }: Props): JSX.Element {
@@ -42,7 +46,10 @@ export default function ColorScale({ setIsScaled }: Props): JSX.Element {
4246
</Tooltip>
4347
</LabelWrapper>
4448

45-
<StyledDropdown
49+
{/* Generic variables are
50+
<T: Dropdown's option type, Multiple, DisableClearable, FreeSolo>
51+
*/}
52+
<StyledDropdown<ColorScaleOptionType, false, false, false>
4653
data-testid="color-scale-dropdown"
4754
onChange={colorScaleOnChange} // TODO(SDSv20): Come back to this
4855
label={colorScaledOption.name}

frontend/src/views/WheresMyGeneV2/components/Filters/components/ColorScale/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { InputDropdownProps as IInputDropdownProps } from "@czi-sds/components";
2+
import { SORT_BY } from "src/views/WheresMyGeneV2/common/types";
23

34
export interface Props {
45
setIsScaled: (prevIsScaled: boolean) => void;
@@ -7,3 +8,5 @@ export interface Props {
78
export const DEFAULT_INPUT_DROPDOWN_PROPS: Partial<IInputDropdownProps> = {
89
sdsStyle: "square",
910
};
11+
12+
export type ColorScaleOptionType = { id?: SORT_BY; name: string };

frontend/src/views/WheresMyGeneV2/components/Filters/components/Compare/connect.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
DefaultDropdownMenuOption,
2+
DefaultAutocompleteOption,
33
InputDropdownProps as IInputDropdownProps,
44
} from "@czi-sds/components";
55
import { useCallback, useContext, useMemo } from "react";
@@ -13,6 +13,7 @@ import {
1313
} from "src/views/WheresMyGeneV2/common/store";
1414
import { selectCompare } from "src/views/WheresMyGeneV2/common/store/actions";
1515
import { Props } from "./types";
16+
import { AutocompleteValue } from "@mui/base";
1617

1718
const DEFAULT_INPUT_DROPDOWN_PROPS: Partial<IInputDropdownProps> = {
1819
sdsStyle: "square",
@@ -30,12 +31,15 @@ export const useConnect = ({ areFiltersDisabled }: Props) => {
3031
[areFiltersDisabled]
3132
);
3233

33-
const optionLabel: DefaultDropdownMenuOption | undefined = useMemo(() => {
34+
const optionLabel: DefaultAutocompleteOption | undefined = useMemo(() => {
3435
return COMPARE_OPTIONS.find((option) => option.id === compare);
3536
}, [compare]);
3637

3738
const handleChange = useCallback(
38-
(value: DefaultDropdownMenuOption | null) => {
39+
(
40+
_: React.SyntheticEvent,
41+
value: AutocompleteValue<DefaultAutocompleteOption, false, false, false>
42+
) => {
3943
if (!dispatch || !value || optionLabel === value) return;
4044

4145
track(EVENTS.WMG_OPTION_SELECT_GROUP_BY, {

frontend/src/views/WheresMyGeneV2/components/Filters/components/Compare/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
GROUP_BY_TOOLTIP_TEXT,
66
SELECT_TISSUE_GENE_TEXT,
77
} from "src/views/WheresMyGeneV2/common/constants";
8-
import { Tooltip } from "@czi-sds/components";
8+
import { DefaultAutocompleteOption, Tooltip } from "@czi-sds/components";
99
import {
1010
StyledIconImage,
1111
StyledTooltip,
@@ -54,7 +54,7 @@ export default function Compare({ areFiltersDisabled }: Props): JSX.Element {
5454
</Label>
5555
</LabelWrapper>
5656
<Wrapper>
57-
<StyledDropdown
57+
<StyledDropdown<DefaultAutocompleteOption, false, false, false>
5858
data-testid="compare-dropdown"
5959
onChange={handleChange} // TODO(SDSv20): Come back tot his
6060
label={optionLabel?.name || "None"}

frontend/src/views/WheresMyGeneV2/components/Filters/components/Organism/connect.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { selectOrganism } from "src/views/WheresMyGeneV2/common/store/actions";
99
import { track } from "src/common/analytics";
1010
import { EVENTS } from "src/common/analytics/events";
1111
import { selectHasCustomFiltersOrGenesSelected } from "src/views/WheresMyGeneV2/common/store/selectors";
12+
import { AutocompleteValue } from "@mui/base";
1213

1314
export const useConnect = () => {
1415
const dispatch = useContext(DispatchContext);
@@ -51,7 +52,10 @@ export const useConnect = () => {
5152
return result;
5253
}, [organisms]);
5354

54-
function handleOnChange(organism: IOrganism | null): void {
55+
function handleOnChange(
56+
_: React.SyntheticEvent,
57+
organism: AutocompleteValue<IOrganism, false, false, false>
58+
): void {
5559
if (!dispatch || !organism || selectedOrganismId === organism.id) return;
5660

5761
setPendingOrganism(organism);

0 commit comments

Comments
 (0)