Skip to content

Commit

Permalink
Add empty state
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Aug 22, 2024
1 parent cfead75 commit a4e2a84
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions ui/components/ui/delineator/delineator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const Header = ({
isCollapsible,
isExpanded,
isLoading,
isDisabled,
onHeaderClick,
type,
}: {
Expand All @@ -57,6 +58,7 @@ const Header = ({
isCollapsible: boolean;
isExpanded: boolean;
isLoading: boolean;
isDisabled: boolean;
onHeaderClick: () => void;
type?: DelineatorType;
}) => {
Expand All @@ -67,6 +69,7 @@ const Header = ({
delineator__header: true,
'delineator__header--expanded': isExpanded,
'delineator__header--loading': isLoading,
'delineator__header--disabled': isDisabled,
})}
display={Display.Flex}
alignItems={AlignItems.center}
Expand Down Expand Up @@ -138,6 +141,7 @@ export const Delineator: React.FC<DelineatorProps> = ({
isCollapsible = true,
isExpanded: isExpandedProp,
isLoading = false,
isDisabled = false,
onExpandChange,
type,
wrapperBoxProps,
Expand All @@ -147,13 +151,13 @@ export const Delineator: React.FC<DelineatorProps> = ({
const shouldShowContent = !isCollapsible || (isCollapsible && isExpanded);

const handleHeaderClick = useCallback(() => {
if (isLoading || !isCollapsible) {
if (isDisabled || isLoading || !isCollapsible) {
return;
}
const newExpandedState = !isExpanded;
onExpandChange?.(newExpandedState);
setIsExpanded(newExpandedState);
}, [isLoading, isCollapsible, isExpanded, onExpandChange]);
}, [isLoading, isCollapsible, isExpanded, isDisabled, onExpandChange]);

return (
<Container wrapperBoxProps={wrapperBoxProps}>
Expand All @@ -163,6 +167,7 @@ export const Delineator: React.FC<DelineatorProps> = ({
isCollapsible={isCollapsible}
isExpanded={isExpanded}
isLoading={isLoading}
isDisabled={isDisabled}
onHeaderClick={handleHeaderClick}
type={type}
/>
Expand Down
1 change: 1 addition & 0 deletions ui/components/ui/delineator/delineator.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type DelineatorProps = {
isCollapsible?: boolean;
isExpanded?: boolean;
isLoading?: boolean;
isDisabled?: boolean;
onExpandChange?: (isExpanded: boolean) => void;
type?: DelineatorType;
wrapperBoxProps?: React.ComponentProps<typeof Box>;
Expand Down
5 changes: 5 additions & 0 deletions ui/components/ui/delineator/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
&--loading {
cursor: default;
}

&--disabled {
cursor: default;
opacity: 0.5;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../../../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../../../hooks/useI18nContext';
import { getSnapMetadata } from '../../../../../../selectors';
import Tooltip from '../../../../../../components/ui/tooltip';

export type SnapInsightProps = {
snapId: string;
Expand Down Expand Up @@ -42,6 +43,16 @@ export const SnapInsight: React.FunctionComponent<SnapInsightProps> = ({
</Text>
);

const hasNoInsight = !loading && !interfaceId;

if (hasNoInsight) {
return (
<Tooltip position="top" title={t('snapsNoInsight')}>
<Delineator headerComponent={headerComponent} isDisabled={true} />
</Tooltip>
);
}

return (
<Delineator
headerComponent={headerComponent}
Expand Down

0 comments on commit a4e2a84

Please sign in to comment.