Skip to content

Commit

Permalink
refactor: rename nested VMs
Browse files Browse the repository at this point in the history
  • Loading branch information
leopuleo committed Nov 21, 2024
1 parent f56f16b commit 94a6cb3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/admin-ui/src/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,14 @@ const DecoratableSelect = (props: SelectProps) => {
<SelectRenderer
selectRootProps={{ ...selectRootProps }}
selectTriggerProps={{
...vm.selectTriggerVm,
...vm.selectTrigger,
size,
variant,
startIcon,
endIcon,
invalid
}}
selectOptionsProps={vm.selectOptionsVm}
selectOptionsProps={vm.selectOptions}
onValueChange={changeValue}
onValueReset={resetValue}
/>
Expand Down
14 changes: 7 additions & 7 deletions packages/admin-ui/src/Select/SelectPresenter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ import { SelectPresenter } from "./SelectPresenter";
describe("SelectPresenter", () => {
const onValueChange = jest.fn();

it("should return the compatible `selectTriggerVm` based on props", () => {
it("should return the compatible `vm.selectTrigger` based on props", () => {
const onValueChange = jest.fn();

// `placeholder`
{
const presenter = new SelectPresenter();
presenter.init({ onValueChange, placeholder: "Custom placeholder" });
expect(presenter.vm.selectTriggerVm.placeholder).toEqual("Custom placeholder");
expect(presenter.vm.selectTrigger.placeholder).toEqual("Custom placeholder");
}

{
// default: no props
const presenter = new SelectPresenter();
presenter.init({ onValueChange });
expect(presenter.vm.selectTriggerVm.placeholder).toEqual("Select an option");
expect(presenter.vm.selectTriggerVm.hasValue).toEqual(false);
expect(presenter.vm.selectTrigger.placeholder).toEqual("Select an option");
expect(presenter.vm.selectTrigger.hasValue).toEqual(false);
}
});

it("should return the compatible `selectOptionsVm` based on props", () => {
it("should return the compatible `vm.selectOptions` based on props", () => {
// with `options` as string
{
const presenter = new SelectPresenter();
presenter.init({ onValueChange, options: ["Option 1", "Option 2"] });
expect(presenter.vm.selectOptionsVm.options).toEqual([
expect(presenter.vm.selectOptions.options).toEqual([
{
value: "Option 1",
label: "Option 1",
Expand Down Expand Up @@ -78,7 +78,7 @@ describe("SelectPresenter", () => {
}
]
});
expect(presenter.vm.selectOptionsVm.options).toEqual([
expect(presenter.vm.selectOptions.options).toEqual([
{
value: "option-1",
label: "Option 1",
Expand Down
8 changes: 4 additions & 4 deletions packages/admin-ui/src/Select/SelectPresenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ interface SelectPresenterParams {

interface ISelectPresenter<TParams extends SelectPresenterParams = SelectPresenterParams> {
vm: {
selectTriggerVm: SelectTriggerVm;
selectOptionsVm: SelectOptionsVm;
selectTrigger: SelectTriggerVm;
selectOptions: SelectOptionsVm;
};
init: (params: TParams) => void;
changeValue: (value: string) => void;
Expand All @@ -37,11 +37,11 @@ class SelectPresenter implements ISelectPresenter {

get vm() {
return {
selectTriggerVm: {
selectTrigger: {
placeholder: this.params?.placeholder || "Select an option",
hasValue: !!this.params?.value
},
selectOptionsVm: {
selectOptions: {
options: this.options?.map(option => SelectOptionMapper.toFormatted(option)) ?? []
}
};
Expand Down

0 comments on commit 94a6cb3

Please sign in to comment.