mirror of
https://github.com/fluxscape/fluxscape.git
synced 2026-01-11 06:42:56 +01:00
feat(editor): Search panel show "(Cloud Function)" if result is in Cloud Functions sheet (#40)
This commit is contained in:
@@ -5,6 +5,8 @@ import { useSidePanelKeyboardCommands } from '@noodl-hooks/useKeyboardCommands';
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
|
import { ComponentModel } from '@noodl-models/componentmodel';
|
||||||
|
import { NodeGraphNode } from '@noodl-models/nodegraphmodel';
|
||||||
import { KeyCode, KeyMod } from '@noodl-utils/keyboard/KeyCode';
|
import { KeyCode, KeyMod } from '@noodl-utils/keyboard/KeyCode';
|
||||||
import { performSearch } from '@noodl-utils/universal-search';
|
import { performSearch } from '@noodl-utils/universal-search';
|
||||||
|
|
||||||
@@ -54,7 +56,7 @@ export function SearchPanel() {
|
|||||||
}
|
}
|
||||||
}, [debouncedSearchTerm]);
|
}, [debouncedSearchTerm]);
|
||||||
|
|
||||||
function onSearchItemClicked(searchResult) {
|
function onSearchItemClicked(searchResult: SearchResultItem) {
|
||||||
if (searchResult.type === 'Component') {
|
if (searchResult.type === 'Component') {
|
||||||
NodeGraphContextTmp.switchToComponent(searchResult.componentTarget, {
|
NodeGraphContextTmp.switchToComponent(searchResult.componentTarget, {
|
||||||
breadcrumbs: false,
|
breadcrumbs: false,
|
||||||
@@ -85,29 +87,7 @@ export function SearchPanel() {
|
|||||||
|
|
||||||
<div className={css.SearchResults}>
|
<div className={css.SearchResults}>
|
||||||
{searchResults.map((component) => (
|
{searchResults.map((component) => (
|
||||||
<Section
|
<SearchItem key={component.componentId} component={component} onSearchItemClicked={onSearchItemClicked} />
|
||||||
title={`${component.componentName} (${component.results.length} result${
|
|
||||||
component.results.length > 1 ? 's' : ''
|
|
||||||
})`}
|
|
||||||
key={component.componentId}
|
|
||||||
variant={SectionVariant.Panel}
|
|
||||||
>
|
|
||||||
{component.results.map((result, index) => (
|
|
||||||
<div
|
|
||||||
className={classNames(
|
|
||||||
css.SearchResultItem
|
|
||||||
// lastActiveComponentId === result.componentTarget.id && css['is-active']
|
|
||||||
)}
|
|
||||||
key={index}
|
|
||||||
onClick={() => onSearchItemClicked(result)}
|
|
||||||
>
|
|
||||||
<Label variant={TextType.Proud}>
|
|
||||||
{result.userLabel ? result.type + ' - ' + result.userLabel : result.type}
|
|
||||||
</Label>
|
|
||||||
<Text>{result.label}</Text>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</Section>
|
|
||||||
))}
|
))}
|
||||||
{searchResults.length === 0 && debouncedSearchTerm.length > 0 && (
|
{searchResults.length === 0 && debouncedSearchTerm.length > 0 && (
|
||||||
<Container hasXSpacing hasYSpacing>
|
<Container hasXSpacing hasYSpacing>
|
||||||
@@ -118,3 +98,51 @@ export function SearchPanel() {
|
|||||||
</BasePanel>
|
</BasePanel>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SearchResultItem = {
|
||||||
|
componentTarget: ComponentModel;
|
||||||
|
label: string;
|
||||||
|
nodeTarget: NodeGraphNode;
|
||||||
|
type: string;
|
||||||
|
userLabel: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type SearchItemProps = {
|
||||||
|
component: {
|
||||||
|
componentName: string;
|
||||||
|
componentId: string;
|
||||||
|
results: SearchResultItem[];
|
||||||
|
};
|
||||||
|
onSearchItemClicked: (item: SearchResultItem) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
function SearchItem({ component, onSearchItemClicked }: SearchItemProps) {
|
||||||
|
const resultCountText = `${component.results.length} result${component.results.length > 1 ? 's' : ''}`;
|
||||||
|
let titleText = `${component.componentName} (${resultCountText})`;
|
||||||
|
|
||||||
|
// We expect there to always be at least one result, to get the full component name.
|
||||||
|
const isInCloudFunctions = component.results[0].componentTarget.name.startsWith('/#__cloud__/');
|
||||||
|
if (isInCloudFunctions) {
|
||||||
|
titleText += ' (Cloud Function)';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Section title={titleText} variant={SectionVariant.Panel}>
|
||||||
|
{component.results.map((result, index) => (
|
||||||
|
<div
|
||||||
|
className={classNames(
|
||||||
|
css.SearchResultItem
|
||||||
|
// lastActiveComponentId === result.componentTarget.id && css['is-active']
|
||||||
|
)}
|
||||||
|
key={index}
|
||||||
|
onClick={() => onSearchItemClicked(result)}
|
||||||
|
>
|
||||||
|
<Label variant={TextType.Proud}>
|
||||||
|
{result.userLabel ? result.type + ' - ' + result.userLabel : result.type}
|
||||||
|
</Label>
|
||||||
|
<Text>{result.label}</Text>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</Section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user