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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ An instance initializer registers the descriptors with the `resource-registry` s

Opening a resource loads the Fleet-Ops engine on demand and hands the record to its action service, so the engine bundle is only fetched when someone clicks. When Fleet-Ops itself boots it replaces these descriptors with its own, which open the same panels directly.

The helpers behind the descriptors and the styled placeholder images are exported from `@fleetbase/fleetops-data/utils/resource-descriptors` and `@fleetbase/fleetops-data/utils/placeholder-images` for other packages that build descriptors.
The helpers behind the descriptors and the styled placeholder images are exported from `@fleetbase/fleetops-data/utils/resource-descriptors` and `@fleetbase/fleetops-data/utils/placeholder-images` for other packages that build descriptors. `@fleetbase/fleetops-data/utils/identity-stub` builds a stand-in record for a relation a row only knows by name (`driver_name`, `pickupName`), so an identity cell can render it and load the real record on demand.


## Contributing
Expand Down
56 changes: 56 additions & 0 deletions addon/utils/identity-stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { get } from '@ember/object';

const inflight = new WeakMap();

/**
* A stand-in for a related record a row only knows by name: enough for an
* identity cell, pill or summary to render (`name`, `resourceType`) and a
* `loadResource()` they call when the real record is needed. The stub never
* carries a UUID in an identifier field, so nothing renders one as a plate
* or an id, and concurrent loads of the same row share one request.
*
* `load` receives the row and returns the record (or a promise of it); with
* no `load`, `loadResource()` resolves to null and the stub stays static.
*/
export function buildIdentityStub(row, { type, nameKey = `${type}_name`, name, load, extra = {} } = {}) {
const label = name ?? (row ? get(row, nameKey) : null);

if (!label) {
return null;
}

return {
...extra,
name: label,
display_name: label,
displayName: label,
resourceType: type,
isIdentityStub: true,
loadResource: async () => {
if (typeof load !== 'function') {
return null;
}

let loads = inflight.get(row);

if (!loads) {
loads = new Map();
inflight.set(row, loads);
}

if (!loads.has(type)) {
loads.set(
type,
Promise.resolve()
.then(() => load(row))
.catch(() => null)
.finally(() => loads.delete(type))
);
}

return loads.get(type);
},
};
}

export default buildIdentityStub;
22 changes: 16 additions & 6 deletions addon/utils/resource-descriptors/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ export function typeLabel(value) {
return null;
}

const head = String(value)
.split(':')[0]
.replace(/-fleet-ops$/, '')
.replace(/[-_]+/g, ' ')
.trim();
const [prefix, ...rest] = String(value).split(':');
// "customer-fleet-ops:contact" reads as "Customer"; a bare "fleet-ops:contact" has
// nothing before the extension name, so it reads as the type after the colon.
const head = (prefix.replace(/-?fleet-ops$/, '') || rest.join(':')).replace(/[-_]+/g, ' ').trim();

return head ? head.charAt(0).toUpperCase() + head.slice(1) : null;
}
Expand All @@ -138,7 +137,18 @@ export function polymorphicType(record, relationName, typeAttr) {

/** The universe extension manager, through either of its service names. */
export function extensionManager(owner) {
return lookupService(owner, 'universe/extension-manager') ?? lookupService(owner, 'universe')?.extensionManager ?? null;
const direct = lookupService(owner, 'universe/extension-manager');

if (direct) {
return direct;
}

// The universe service resolves its manager lazily and throws on a host that has none.
try {
return lookupService(owner, 'universe')?.extensionManager ?? null;
} catch {
return null;
}
}

/** Whether an engine is installed, so a resource it owns has somewhere to open. */
Expand Down
1 change: 0 additions & 1 deletion app/components/cell/contact-identity.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/cell/customer-identity.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/cell/driver-identity.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/cell/fleet-identity.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/cell/order-identity.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/cell/place-identity.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/cell/vehicle-identity.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/cell/vendor-identity.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/contact/pill.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/contact/summary.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/customer/pill.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/customer/summary.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/driver/pill.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/driver/summary.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/fleet/pill.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/fleet/summary.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/order/pill.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/order/summary.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/place/pill.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/place/summary.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/select-option/contact.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/select-option/customer.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/select-option/driver.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/select-option/fleet.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/select-option/order.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/select-option/place.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/select-option/vehicle.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/select-option/vendor.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/vehicle/pill.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/vehicle/summary.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/vendor/pill.js

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion app/components/vendor/summary.js

This file was deleted.

Loading
Loading