Filter the script library and show customer context across pages
This commit is contained in:
+21
-8
@@ -635,22 +635,31 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
|
||||
const [orderFilters, setOrderFilters] = useState(emptyOrderFilters);
|
||||
const detailRoute = (route.page === 'genehmigungen' && detailKind === 'pruefen')
|
||||
|| (route.page === 'auftraege' && (detailKind === 'ansehen' || detailKind === 'entwurf'));
|
||||
const customer = detailRoute && detailTenant ? detailTenant : selectedCustomer;
|
||||
const deviceCustomer = route.page === 'geraete' && detailKind && detailTenant && detailId ? detailKind : '';
|
||||
const fixedCustomer = detailRoute ? detailTenant : deviceCustomer;
|
||||
const customer = fixedCustomer || selectedCustomer;
|
||||
const [inboxRevision, refreshInbox] = useState(0);
|
||||
const pendingCount = usePendingApprovals(true, inboxRevision);
|
||||
const [fleetFilter, setFleetFilter] = useState('');
|
||||
const [allDeviceCustomers, setAllDeviceCustomers] = useState(true);
|
||||
const fleetFilter = allDeviceCustomers ? '' : selectedCustomer;
|
||||
const [selection, setSelection] = useState<{ customer: string; ids: string[] }>({
|
||||
customer: '',
|
||||
ids: []
|
||||
});
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
if (fixedCustomer && fixedCustomer !== selectedCustomer && customers.some(c => c.tenant_id === fixedCustomer)) {
|
||||
setCustomer(fixedCustomer);
|
||||
setSelection({ customer: '', ids: [] });
|
||||
}
|
||||
}, [customers, fixedCustomer, selectedCustomer]);
|
||||
function switchCustomer(id: string) {
|
||||
if (id === selectedCustomer && !detailRoute) return;
|
||||
if (id === selectedCustomer) return;
|
||||
setSelection({ customer: '', ids: [] });
|
||||
setCustomer(id);
|
||||
}
|
||||
function selectFleetCustomer(id: string) {
|
||||
setFleetFilter(id);
|
||||
setAllDeviceCustomers(!id);
|
||||
setSelection({ customer: '', ids: [] });
|
||||
if (id) switchCustomer(id);
|
||||
}
|
||||
@@ -666,6 +675,7 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
|
||||
// Gate rendering during a tenant change; a previously loaded session is scoped to its own customer.
|
||||
const scoped = current.data?.id === customer ? current.data.auth : null;
|
||||
const customerName = customers.find((c) => c.tenant_id === customer)?.name ?? '';
|
||||
const canChooseCustomer = !fixedCustomer && route.page !== 'genehmigungen' && customers.length > 0;
|
||||
function openOperation(tenantId: string, id: string, jobId?: string) {
|
||||
switchCustomer(tenantId);
|
||||
go('auftraege', orderDetailRoute(tenantId, id, jobId));
|
||||
@@ -738,10 +748,10 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
|
||||
<i aria-hidden="true">/</i>
|
||||
<b>{pages[route.page]}</b>
|
||||
</div>
|
||||
{!['geraete', 'kunden','genehmigungen'].includes(route.page) && !detailRoute && (
|
||||
{canChooseCustomer ? (
|
||||
<label className="context">
|
||||
<span>Kunde</span>
|
||||
<select aria-label="Kunde" value={customer} onChange={(e) => switchCustomer(e.target.value)}>
|
||||
<select aria-label="Kunde" title={customerName} value={customer} onChange={(e) => selectFleetCustomer(e.target.value)}>
|
||||
{customers.map((c) => (
|
||||
<option value={c.tenant_id} key={c.tenant_id}>
|
||||
{c.name}
|
||||
@@ -749,7 +759,10 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
) : <div className="context" aria-label={fixedCustomer ? 'Kunde der Detailansicht' : 'Aktiver Kunde'}>
|
||||
<span>{fixedCustomer ? 'Kunde' : 'Aktiver Kunde'}</span>
|
||||
<strong>{customerName || (tenants.data ? 'Nicht verfügbar' : 'Wird geladen …')}</strong>
|
||||
</div>}
|
||||
</header>
|
||||
{auth.principal.simulated && (
|
||||
<aside className="simulation" role="status">
|
||||
@@ -764,7 +777,7 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
|
||||
{route.page === 'geraete' && (
|
||||
<Devices
|
||||
detailPath={route.tab}
|
||||
auth={scoped ?? auth}
|
||||
auth={scoped ?? { ...auth, permissions: [] }}
|
||||
customers={customers}
|
||||
filter={fleetFilter}
|
||||
onFilter={selectFleetCustomer}
|
||||
|
||||
Reference in New Issue
Block a user