refactor(angular): action sheet provider imports correct instance from core (#28474)

Issue number: N/A

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

As a takeaway from our learning session about a menuController bug in
Ionic Angular, the team would like to update our other providers to use
the same architecture as the menuController to prevent this kind of
issue from happening again in the future.

We also noticed that the common provider does not provide much value and
it's easier to just have two separate implementations in `src` and
`standalone`. (There wasn't much code we could de-duplicate)

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Removed the common action sheet provider in favor of separate ones in
src/standalone
## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
This commit is contained in:
Liam DeBeasi
2023-11-08 12:46:25 -05:00
committed by GitHub
parent c053fd9c68
commit c5dd622bbe
12 changed files with 70 additions and 6 deletions

View File

@@ -1,4 +1,3 @@
export { ActionSheetController } from './providers/action-sheet-controller';
export { AlertController } from './providers/alert-controller';
export { LoadingController } from './providers/loading-controller';
export { MenuController } from './providers/menu-controller';
@@ -39,5 +38,6 @@ export * from './directives/control-value-accessors';
export { ProxyCmp } from './utils/proxy';
export { IonicRouteStrategy } from './utils/routing';
export { OverlayBaseController } from './utils/overlay';
export { raf } from './utils/util';

View File

@@ -20,7 +20,6 @@ export * from './directives/validators';
// PROVIDERS
export {
ActionSheetController,
AlertController,
LoadingController,
ModalController,
@@ -42,6 +41,7 @@ export {
ViewDidLeave,
} from '@ionic/angular/common';
export { MenuController } from './providers/menu-controller';
export { ActionSheetController } from './providers/action-sheet-controller';
// PACKAGE MODULE
export { IonicModule } from './ionic-module';

View File

@@ -0,0 +1,13 @@
import { Injectable } from '@angular/core';
import { OverlayBaseController } from '@ionic/angular/common';
import type { ActionSheetOptions } from '@ionic/core';
import { actionSheetController } from '@ionic/core';
@Injectable({
providedIn: 'root',
})
export class ActionSheetController extends OverlayBaseController<ActionSheetOptions, HTMLIonActionSheetElement> {
constructor() {
super(actionSheetController);
}
}

View File

@@ -6,8 +6,8 @@ export { IonRouterLink, IonRouterLinkWithHref } from './navigation/router-link-d
export { IonTabs } from './navigation/tabs';
export { provideIonicAngular } from './providers/ionic-angular';
export { MenuController } from './providers/menu-controller';
export { ActionSheetController } from './providers/action-sheet-controller';
export {
ActionSheetController,
AlertController,
LoadingController,
ModalController,

View File

@@ -1,9 +1,8 @@
import { Injectable } from '@angular/core';
import { OverlayBaseController } from '@ionic/angular/common';
import type { ActionSheetOptions } from '@ionic/core/components';
import { actionSheetController } from '@ionic/core/components';
import { OverlayBaseController } from '../utils/overlay';
@Injectable({
providedIn: 'root',
})

View File

@@ -33,5 +33,11 @@ describe('Providers', () => {
cy.get('#set-menu-count').click();
cy.get('#registered-menu-count').should('have.text', '1');
});
it('should open an action sheet', () => {
cy.get('button#open-action-sheet').click();
cy.get('ion-action-sheet').should('be.visible');
});
});

View File

@@ -0,0 +1,11 @@
describe('Action Sheet Controller', () => {
beforeEach(() => {
cy.visit('/standalone/action-sheet-controller');
})
it('should open an action sheet', () => {
cy.get('button#open-action-sheet').click();
cy.get('ion-action-sheet').should('be.visible');
});
})

View File

@@ -45,4 +45,5 @@
</p>
<button id="set-menu-count" (click)="setMenuCount()">Set Menu Count</button>
<button id="open-action-sheet" (click)="openActionSheet()">Open Action Sheet</button>
</ion-content>

View File

@@ -24,7 +24,7 @@ export class ProvidersComponent {
registeredMenuCount = 0;
constructor(
actionSheetCtrl: ActionSheetController,
private actionSheetCtrl: ActionSheetController,
alertCtrl: AlertController,
loadingCtrl: LoadingController,
private menuCtrl: MenuController,
@@ -88,4 +88,12 @@ export class ProvidersComponent {
const menus = await this.menuCtrl.getMenus();
this.registeredMenuCount = menus.length;
}
async openActionSheet() {
const actionSheet = await this.actionSheetCtrl.create({
buttons: ['Button']
});
await actionSheet.present();
}
}

View File

@@ -0,0 +1,4 @@
<ul id="content">
<button id="open-action-sheet" (click)="openActionSheet()">Open Action Sheets</button>
</ul>

View File

@@ -0,0 +1,21 @@
import { Component } from '@angular/core';
import { ActionSheetController } from '@ionic/angular/standalone';
@Component({
selector: 'app-action-sheet-controller',
templateUrl: './action-sheet-controller.component.html',
standalone: true
})
export class ActionSheetControllerComponent {
registeredMenuCount = 0;
constructor(private actionSheetCtrl: ActionSheetController) {}
async openActionSheet() {
const actionSheet = await this.actionSheetCtrl.create({
buttons: ['Button']
});
await actionSheet.present();
}
}

View File

@@ -7,6 +7,7 @@ export const routes: Routes = [
component: AppComponent,
children: [
{ path: 'menu-controller', loadComponent: () => import('../menu-controller/menu-controller.component').then(c => c.MenuControllerComponent) },
{ path: 'action-sheet-controller', loadComponent: () => import('../action-sheet-controller/action-sheet-controller.component').then(c => c.ActionSheetControllerComponent) },
{ path: 'popover', loadComponent: () => import('../popover/popover.component').then(c => c.PopoverComponent) },
{ path: 'modal', loadComponent: () => import('../modal/modal.component').then(c => c.ModalComponent) },
{ path: 'router-outlet', loadComponent: () => import('../router-outlet/router-outlet.component').then(c => c.RouterOutletComponent) },