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

Settings menu items unavailable when none already selected. (PP-1022) #103

Merged
merged 3 commits into from
Feb 29, 2024
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
23 changes: 11 additions & 12 deletions src/components/InputList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ export interface InputListProps {
labelAndDescription?: (setting: SettingData) => JSX.Element[];
setting: SettingData | CustomListsSetting;
disabled: boolean;
value: Array<string | {} | JSX.Element>;
value: Array<string | object | JSX.Element>;
altValue?: string;
additionalData?: any;
onSubmit?: any;
onEmpty?: string;
title?: string;
capitalize?: boolean;
onChange?: (value: any) => {};
onChange?: (value: any) => object;
readOnly?: boolean;
disableButton?: boolean;
}

export interface InputListState {
listItems: Array<string | {}>;
listItems: Array<string | object>;
newItem?: string;
options?: JSX.Element[];
}
Expand Down Expand Up @@ -225,7 +225,7 @@ export default class InputList extends React.Component<
}
}

renderToolTip(item: {} | string, format: string) {
renderToolTip(item: object | string, format: string) {
const icons = {
geographic: <LocatorIcon />,
};
Expand Down Expand Up @@ -262,14 +262,13 @@ export default class InputList extends React.Component<
}
}
// Items that have already been selected, and should be eliminated from the menu.
const listItems = this.state
? this.state.listItems
: this.props.value || this.props.setting.default;
const listItems =
this.state?.listItems ||
this.props.value ||
this.props.setting.default ||
[];
// Items that haven't been selected yet.
const remainingOptions = listItems
? allOptions.filter((o) => listItems.indexOf(o.props.value) < 0)
: [];
return remainingOptions;
return allOptions.filter((o) => !listItems.includes(o.props.value));
}

updateNewItem() {
Expand All @@ -280,7 +279,7 @@ export default class InputList extends React.Component<
this.setState({ ...this.state, ...{ newItem: (ref as any).getValue() } });
}

async removeListItem(listItem: string | {}) {
async removeListItem(listItem: string | object) {
await this.setState({
listItems: this.state.listItems.filter(
(stateListItem) => stateListItem !== listItem
Expand Down
18 changes: 18 additions & 0 deletions src/components/__tests__/InputList-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,24 @@ describe("InputList", () => {
);
expect(wrapper.state()["listItems"].includes("Option 1")).to.be.true;
});
it("doesn't lose options when nothing is selected", () => {
const setting = {
...wrapper.prop("setting"),
...{ type: "menu", default: null, format: "narrow" },
};
wrapper = mount(
<InputList
createEditableInput={createEditableInput}
labelAndDescription={labelAndDescription}
value={null}
setting={setting}
disabled={false}
/>,
{ context }
);
const options = wrapper.find("option");
expect(options.length).to.equal(3);
});
tdilauro marked this conversation as resolved.
Show resolved Hide resolved
it("optionally eliminates already-selected options from the menu", () => {
let options = wrapper.find("option");
expect(options.length).to.equal(3);
Expand Down
Loading