import React, { useContext, useMemo } from 'react'; import { ComponentGrid } from '@teambit/explorer.ui.gallery.component-grid'; import { EmptyWorkspace } from '@teambit/workspace.ui.empty-workspace'; import compact from 'lodash.compact'; import { ScopeID } from '@teambit/scopes.scope-id'; import { useCloudScopes } from '@teambit/cloud.hooks.use-cloud-scopes'; import { useWorkspaceMode } from '@teambit/workspace.ui.use-workspace-mode'; import { WorkspaceContext } from '../workspace-context'; import { useWorkspaceAggregation } from './use-workspace-aggregation'; import { useQueryParamWithDefault, useListParamWithDefault } from './use-query-param-with-default'; import { NamespaceHeader } from './namespace-header'; import { HopeComponentCard } from './hope-component-card'; import type { AggregationType } from './workspace-overview.types'; import { WorkspaceFilterPanel } from './workspace-filter-panel'; import styles from './workspace-overview.module.scss'; export function WorkspaceOverview() { const workspace = useContext(WorkspaceContext); const { components, componentDescriptors } = workspace; if (!components.length) return ; const { isMinimal } = useWorkspaceMode(); const uniqueScopes = [...new Set(components.map((c) => c.id.scope))]; const { cloudScopes } = useCloudScopes(uniqueScopes); const cloudMap = new Map((cloudScopes || []).map((s) => [s.id.toString(), s])); const compDescriptorMap = new Map(componentDescriptors.map((d) => [d.id.toString(), d])); const items = compact( components.map((component) => { if (component.deprecation?.isDeprecate) return null; const descriptor = compDescriptorMap.get(component.id.toString()); if (!descriptor) return null; const cloudScope = cloudMap.get(component.id.scope); const scope = cloudScope || (ScopeID.isValid(component.id.scope) && { id: ScopeID.fromString(component.id.scope) }) || undefined; return { component, componentDescriptor: descriptor, scope: scope ? { id: scope.id, icon: (scope as any).icon, backgroundIconColor: (scope as any).backgroundIconColor } : undefined, }; }) ); const [aggregation, setAggregation] = useQueryParamWithDefault('aggregation', 'namespaces'); const [activeNamespaces, setActiveNamespaces] = useListParamWithDefault('ns'); const [activeScopes, setActiveScopes] = useListParamWithDefault('scopes'); const filters = useMemo( () => ({ namespaces: activeNamespaces, scopes: activeScopes, statuses: new Set() as any }), [activeNamespaces, activeScopes] ); const { groups, groupType, availableAggregations, filteredCount } = useWorkspaceAggregation( items, aggregation, filters ); return ( {filteredCount === 0 && } {groups.map((group) => ( {groupType !== 'none' && ( )} {group.items.map((item) => ( ))} ))} ); }