Skip to content
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
18 changes: 18 additions & 0 deletions addon-test-support/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { render } from '@ember/test-helpers';
import { shellState } from '@fleetbase/ember-ui/services/shell';
import { sheetStack } from '@fleetbase/ember-ui/utils/sheet-stack';

/**
* Test helpers for the canvas layout (`Layout::Canvas` and the pieces that
Expand Down Expand Up @@ -113,3 +115,19 @@ export async function renderShell(template, { theme = 'light' } = {}) {
export function shellToken(name, element = document.body) {
return getComputedStyle(element).getPropertyValue(`--fb-${name}`).trim();
}

/**
* The shell layout (`shellState`) and the open-sheet stack are page-wide
* module state, shared by the host and its engines. Reset both before each
* test so a layout set or a sheet left open in one test cannot leak into the
* next: `QUnit.testStart(resetShellState)` in `tests/test-helper.js`, or
* `setupShellState(hooks)` per module.
*/
export function resetShellState() {
shellState.reset();
sheetStack.reset();
}

export function setupShellState(hooks) {
hooks.beforeEach(resetShellState);
}
4 changes: 2 additions & 2 deletions addon/components/layout/canvas.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{#if (has-block "backdrop")}}
{{yield to="backdrop"}}
{{else}}
<Layout::Canvas::Backdrop::DotGrid />
<Layout::Canvas::BackdropHost />
{{/if}}
</div>
<main class="fb-canvas-content" data-canvas-layer="content">
Expand All @@ -14,4 +14,4 @@
{{yield to="chrome"}}
</div>
{{/if}}
</div>
</div>
24 changes: 24 additions & 0 deletions addon/components/layout/canvas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';

/**
* `Layout::Canvas` — the canvas shell root: backdrop, content and chrome layers.
*
* Without a `<:backdrop>` block the backdrop layer renders
* `Layout::Canvas::BackdropHost`, which shows the route's registered backdrop
* (a live map) or the dot grid. While mounted it marks the `shell` service's
* layout as `canvas`, so record panels render as sheets.
*/
export default class LayoutCanvasComponent extends Component {
@service shell;

constructor() {
super(...arguments);
this.shell.canvasDidMount();
}

willDestroy() {
super.willDestroy(...arguments);
this.shell.canvasWillUnmount();
}
}
22 changes: 22 additions & 0 deletions addon/components/layout/canvas/backdrop-host.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="fb-canvas-backdrop-host" data-backdrop-active={{if this.hasActive this.active.name}} ...attributes>
{{#each this.entries key="name" as |entry|}}
<div
class="fb-canvas-backdrop-slot {{if entry.isActive 'is-active'}}"
data-backdrop={{entry.name}}
aria-hidden={{if entry.isActive "false" "true"}}
inert={{entry.inert}}
>
{{#if entry.isEngineComponent}}
<LazyEngineComponent
@component={{entry.component}}
@params={{hash registration=entry.registration isActive=entry.isActive state=this.state backdrop=this.backdrop}}
/>
{{else}}
{{component entry.component registration=entry.registration isActive=entry.isActive state=this.state backdrop=this.backdrop}}
{{/if}}
</div>
{{/each}}
{{#unless this.hasActive}}
<Layout::Canvas::Backdrop::DotGrid />
{{/unless}}
</div>
90 changes: 90 additions & 0 deletions addon/components/layout/canvas/backdrop-host.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import Component from '@glimmer/component';
import { getOwner } from '@ember/application';
import { optionalService } from '../../../utils/shell';

/**
* `Layout::Canvas::BackdropHost` — renders the canvas backdrop from ember-core's
* `backdrop` service.
*
* Every registration in `backdrop.mounted` renders once, keyed by name, inside
* its own slot. Only the `active` one is visible; the others are hidden with
* `visibility: hidden` and `inert`, never torn down, so a keep-alive live map
* survives a visit to a page without one. With no active backdrop (or no
* `backdrop` service at all) the dot grid shows.
*
* A registration is `{ name, component, routes, priority, keepAlive }`. The
* component is a class, a component name, or an engine's `ExtensionComponent`.
* A class or name receives these arguments; an `ExtensionComponent` is rendered
* through `LazyEngineComponent` and receives the same values as `@params`
* (`@params.registration`, …):
* - `registration` the registration itself
* - `isActive` whether it is the visible backdrop
* - `state` the service's merged `state` (`{ layers, fitBounds, focus, mode }`)
* - `backdrop` the service, for `setInstance(map)` and `onReady()`
*
* The host never sets `pointer-events` on the backdrop layer or its slots, so
* an engine that portals its map into the slot keeps full interaction.
*
* While a backdrop is active, the canvas content layer stops taking the pointer
* in its gaps (see `layout/canvas.css`), so the map stays draggable around the
* floating cards.
*/
/**
* Whether a registration's component comes from an engine: an ember-core
* `ExtensionComponent` (`{ engine, path | class }`) or its string form
* `#extension-component:<engine>:<path>`. Those render through
* `LazyEngineComponent`, which loads the engine first.
*/
export function isEngineComponent(component) {
if (typeof component === 'string') {
return component.startsWith('#extension-component');
}
return typeof component === 'object' && component !== null && Boolean(component.engine);
}

export default class LayoutCanvasBackdropHostComponent extends Component {
get backdrop() {
return optionalService(getOwner(this), 'backdrop');
}

get active() {
return this.backdrop?.active ?? null;
}

get state() {
return this.backdrop?.state ?? null;
}

/**
* The registrations to render. Falls back to just the active one when the
* service has no `mounted` list.
*/
get entries() {
const backdrop = this.backdrop;
if (!backdrop) {
return [];
}

const active = this.active;
const mounted = Array.isArray(backdrop.mounted) ? backdrop.mounted : [];
const registrations = mounted.length || !active ? mounted : [active];

return registrations
.filter((registration) => registration && registration.name && registration.component)
.map((registration) => {
const isActive = Boolean(active) && registration.name === active.name;
return {
name: registration.name,
component: registration.component,
isEngineComponent: isEngineComponent(registration.component),
registration,
isActive,
inert: isActive ? undefined : true,
};
});
}

get hasActive() {
return this.entries.some((entry) => entry.isActive);
}
}
170 changes: 121 additions & 49 deletions addon/components/layout/resource/panel.hbs
Original file line number Diff line number Diff line change
@@ -1,63 +1,135 @@
<Overlay
@onLoad={{this.setOverlayContext}}
@onOpen={{this.onOpen}}
@onClose={{this.onClose}}
@onToggle={{this.onToggle}}
@position="right"
@noBackdrop={{true}}
@fullHeight={{true}}
@isResizable={{this.isResizable}}
@width={{this.width}}
@minResizeWidth={{@minResizeWidth}}
@maxResizeWidth={{@maxResizeWidth}}
...attributes
>
{{#if @headerComponent}}
{{! Invoked with angle brackets so `class` lands as an ATTRIBUTE. In the curly form it
arrives as the `@class` argument, which a Glimmer component drops — losing both the
caller's @headerClass and the addon's own resource-panel-header styling hook. }}
{{#let (component @headerComponent) as |CustomHeader|}}
<CustomHeader
{{#if this.isCanvas}}
<Sheet
@title={{this.sheetTitle}}
@side={{@side}}
@width={{this.sheetWidth}}
@resizable={{this.isResizable}}
@minWidth={{this.sheetMinWidth}}
@maxWidth={{this.sheetMaxWidth}}
@onClose={{this.onPressCancel}}
@showClose={{false}}
@onPark={{@onPark}}
@onActivate={{@onActivate}}
@stackIndex={{@stackIndex}}
@stackSize={{@stackSize}}
@onOpen={{this.setSheetContext}}
class="resource-panel-sheet"
...attributes
>
<:header>
{{#if @headerComponent}}
{{! Invoked with angle brackets so `class` lands as an ATTRIBUTE. In the curly form it
arrives as the `@class` argument, which a Glimmer component drops — losing both the
caller's @headerClass and the addon's own resource-panel-header styling hook. }}
{{#let (component @headerComponent) as |CustomHeader|}}
<CustomHeader
@authSchema={{this.authSchema}}
@resource={{this.resource}}
@saveTask={{@saveTask}}
@saveDisabled={{@saveDisabled}}
@pojoResource={{@pojoResource}}
@onPressCancel={{@onPressCancel}}
@actionButtons={{this.actionButtons}}
@headerClass={{@headerClass}}
@modelName={{@modelName}}
@saveOptions={{@saveOptions}}
@headerLeftClass={{@headerLeftClass}}
@headerLeftInnerClass={{@headerLeftInnerClass}}
@titleWrapperClass={{@titleWrapperClass}}
@titleClass={{@titleClass}}
@actionsWrapperClass={{@actionsWrapperClass}}
class="{{@headerClass}} resource-panel-header"
/>
{{/let}}
{{else}}
<Layout::Resource::Panel::Header
@authSchema={{this.authSchema}}
@resource={{this.resource}}
@title={{@headerTitle}}
@saveTask={{@saveTask}}
@saveDisabled={{@saveDisabled}}
@pojoResource={{@pojoResource}}
@saveOptions={{@saveOptions}}
@onPressCancel={{this.onPressCancel}}
@actionButtons={{this.actionButtons}}
@modelName={{@modelName}}
@headerLeftClass={{@headerLeftClass}}
@headerLeftInnerClass={{@headerLeftInnerClass}}
@titleWrapperClass={{@titleWrapperClass}}
@titleClass={{@titleClass}}
@actionsWrapperClass={{@actionsWrapperClass}}
class={{@headerClass}}
/>
{{/if}}
</:header>
<:body>
<div class="resource-panel-sheet-body {{@bodyClass}}">
{{yield this.resource}}
</div>
</:body>
</Sheet>
{{else}}
<Overlay
@onLoad={{this.setOverlayContext}}
@onOpen={{this.onOpen}}
@onClose={{this.onClose}}
@onToggle={{this.onToggle}}
@position="right"
@noBackdrop={{true}}
@fullHeight={{true}}
@isResizable={{this.isResizable}}
@width={{this.width}}
@minResizeWidth={{@minResizeWidth}}
@maxResizeWidth={{@maxResizeWidth}}
...attributes
>
{{#if @headerComponent}}
{{! Invoked with angle brackets so `class` lands as an ATTRIBUTE. In the curly form it
arrives as the `@class` argument, which a Glimmer component drops — losing both the
caller's @headerClass and the addon's own resource-panel-header styling hook. }}
{{#let (component @headerComponent) as |CustomHeader|}}
<CustomHeader
@authSchema={{this.authSchema}}
@resource={{this.resource}}
@saveTask={{@saveTask}}
@saveDisabled={{@saveDisabled}}
@pojoResource={{@pojoResource}}
@onPressCancel={{@onPressCancel}}
@actionButtons={{this.actionButtons}}
@headerClass={{@headerClass}}
@modelName={{@modelName}}
@saveOptions={{@saveOptions}}
@headerLeftClass={{@headerLeftClass}}
@headerLeftInnerClass={{@headerLeftInnerClass}}
@titleWrapperClass={{@titleWrapperClass}}
@titleClass={{@titleClass}}
@actionsWrapperClass={{@actionsWrapperClass}}
class="{{@headerClass}} resource-panel-header"
/>
{{/let}}
{{else}}
<Layout::Resource::Panel::Header
@authSchema={{this.authSchema}}
@resource={{this.resource}}
@title={{@headerTitle}}
@saveTask={{@saveTask}}
@saveDisabled={{@saveDisabled}}
@pojoResource={{@pojoResource}}
@onPressCancel={{@onPressCancel}}
@saveOptions={{@saveOptions}}
@onPressCancel={{this.onPressCancel}}
@actionButtons={{this.actionButtons}}
@headerClass={{@headerClass}}
@modelName={{@modelName}}
@saveOptions={{@saveOptions}}
@headerLeftClass={{@headerLeftClass}}
@headerLeftInnerClass={{@headerLeftInnerClass}}
@titleWrapperClass={{@titleWrapperClass}}
@titleClass={{@titleClass}}
@actionsWrapperClass={{@actionsWrapperClass}}
class="{{@headerClass}} resource-panel-header"
class={{@headerClass}}
/>
{{/let}}
{{else}}
<Layout::Resource::Panel::Header
@authSchema={{this.authSchema}}
@resource={{this.resource}}
@title={{@headerTitle}}
@saveTask={{@saveTask}}
@saveDisabled={{@saveDisabled}}
@pojoResource={{@pojoResource}}
@saveOptions={{@saveOptions}}
@onPressCancel={{this.onPressCancel}}
@actionButtons={{this.actionButtons}}
@modelName={{@modelName}}
@headerLeftClass={{@headerLeftClass}}
@headerLeftInnerClass={{@headerLeftInnerClass}}
@titleWrapperClass={{@titleWrapperClass}}
@titleClass={{@titleClass}}
@actionsWrapperClass={{@actionsWrapperClass}}
class={{@headerClass}}
/>
{{/if}}
{{/if}}

<Overlay::Body class="no-padding {{@bodyClass}}">
{{yield this.resource}}
</Overlay::Body>
</Overlay>
<Overlay::Body class="no-padding {{@bodyClass}}">
{{yield this.resource}}
</Overlay::Body>
</Overlay>
{{/if}}
Loading
Loading