Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LF-4711 Make the Online/Offline badge and make it into a Table Cell Kind #3676

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
8 changes: 7 additions & 1 deletion packages/webapp/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,13 @@
"STATUS": {
"ACTIVE": "Active",
"INACTIVE": "Inactive",
"INVITED": "Invited"
"INVITED": "Invited",
"OFFLINE": "Offline",
"ONLINE": "Online",
"SENSOR": {
"OFFLINE_TOOLTIP": "Device has not sent data for more than 12 hours",
"ONLINE_TOOLTIP": "Device has sent data within the last 12 hours"
}
},
"SURVEY_STACK": {
"PRODUCED": "Produced on",
Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/src/assets/images/status-indicator-dot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiteFarm.org
* Copyright 2024, 2025 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
Expand All @@ -18,16 +18,21 @@ import { Tooltip } from '@mui/material';
import styles from './styles.module.scss';
import { Semibold, Main } from '../Typography';

export interface HoverPillProps {
export interface HoverPillOverflowListProps {
items: string[];
noneText?: string;
}

export const HoverPill = ({ items }: HoverPillProps) => {
export const HoverPillOverflowList = ({ items, noneText = '' }: HoverPillOverflowListProps) => {
const { t } = useTranslation();

if (items.length === 0) {
return <Main className={styles.itemText}>{noneText}</Main>;
}

const hoverContent = (
<>
{items.map((item, index) => (
{items.slice(1).map((item, index) => (
<Main key={index} className={styles.detailText}>
{item}
</Main>
Expand All @@ -48,21 +53,26 @@ export const HoverPill = ({ items }: HoverPillProps) => {
};

return (
<Tooltip
title={hoverContent}
placement="bottom-end"
classes={{
tooltip: styles.hoverDetails,
}}
PopperProps={PopperProps}
enterTouchDelay={0}
leaveTouchDelay={900000}
>
<div className={styles.pill}>
<Semibold className={styles.pillText}>
{t('HOVERPILL.PLUS_OTHERS_COUNT', { count: items.length })}
</Semibold>
</div>
</Tooltip>
<div className={styles.container}>
<Main className={styles.itemText}>{items[0]}</Main>
{items.length > 1 && (
<Tooltip
title={hoverContent}
placement="bottom-end"
classes={{
tooltip: styles.hoverDetails,
}}
PopperProps={PopperProps}
enterTouchDelay={0}
leaveTouchDelay={900000}
>
<div className={styles.pill}>
<Semibold className={styles.pillText}>
{t('HOVERPILL.PLUS_OTHERS_COUNT', { count: items.length - 1 })}
</Semibold>
</div>
</Tooltip>
)}
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiteFarm.org
* Copyright 2024, 2025 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
Expand All @@ -13,6 +13,17 @@
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

.container {
display: flex;
gap: 8px;
}

.itemText {
color: var(--Colors-Neutral-Neutral-700);
font-size: 16px;
font-weight: 400;
}

.pillText,
.detailText {
user-select: none;
Expand Down
88 changes: 88 additions & 0 deletions packages/webapp/src/components/StatusIndicatorPill/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2025 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

import clsx from 'clsx';
import { useTranslation } from 'react-i18next';
import { Tooltip } from '@mui/material';
import { ReactComponent as StatusIndicatorDot } from '../../assets/images/status-indicator-dot.svg';
import styles from './styles.module.scss';
import { Semibold, Main } from '../Typography';

export enum Status {
ONLINE = 'ONLINE',
OFFLINE = 'OFFLINE',
}

export interface StatusIndicatorPillProps {
status: Status;
pillText: string;
tooltipText?: string;
showHoverTooltip?: boolean;
}

export const StatusIndicatorPill = ({
status,
pillText,
tooltipText = '',
showHoverTooltip = true,
}: StatusIndicatorPillProps) => {
const { t } = useTranslation();

const isOnline = status === Status.ONLINE;

const hoverContent = <Main className={styles.hoverText}>{t(tooltipText)}</Main>;

// https://mui.com/material-ui/react-tooltip/#distance-from-anchor
const PopperProps = {
modifiers: [
{
name: 'offset',
options: {
offset: [0, 4],
},
},
],
};

const statusPill = (
<div
className={clsx(
styles.pill,
isOnline ? styles.online : styles.offline,
showHoverTooltip && styles.hover,
)}
>
<StatusIndicatorDot />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this just be a new pure css component? A circle is also used for the filter dot (border radius should probably be 50%)

circle {
	width: 6px;
	height: 6px;
	border-radius: 3px;
	background-color: var(--teal600);
}

<Semibold className={styles.pillText}>{t(pillText)}</Semibold>
</div>
);

return showHoverTooltip ? (
<Tooltip
title={hoverContent}
placement="bottom-end"
classes={{
tooltip: styles.tooltipContainer,
}}
PopperProps={PopperProps}
enterTouchDelay={0}
leaveTouchDelay={900000}
>
{statusPill}
</Tooltip>
) : (
statusPill
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2025 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

.pill {
display: inline-flex;
align-items: center;
gap: 4px;

padding: 2px 4px;
border-radius: 40px;

&.hover {
cursor: default;
}
}

.pill.online {
background: var(--Colors-Secondary-Secondary-green-100);

.pillText {
color: var(--Colors-Secondary-Secondary-green-700);
}

&.hover:hover {
background: var(--Colors-Secondary-Secondary-green-700);

.pillText {
color: var(--Colors-Secondary-Secondary-green-50);
}

svg circle {
fill: var(--Colors-Secondary-Secondary-green-50);
}
}
}

.pill.offline {
background: var(--Colors-Accent---singles-Red-light);

svg circle {
fill: var(--Colors-Accent---singles-Red-full);
}

.pillText {
color: var(--Colors-Accent---singles-Red-full);
}

&.hover:hover {
background: var(--Colors-Accent---singles-Red-full);

.pillText {
color: var(--Colors-Accent---singles-Red-light);
}

svg circle {
fill: var(--Colors-Accent---singles-Red-light);
}
}
}

.pillText,
.hoverText {
font-family: 'Open Sans';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not inherited from somewhwere else? With that special malayalam font etc.

Copy link
Collaborator Author

@kathyavini kathyavini Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm 🤔 I never considered this! Does this mean that all the places in our codebase that still say Open Sans need to say at least '"Open Sans", "Manjari" by default?

(I'll double-check on this component, but often when the font is specified inheritance is not working for some reason so it does have to get restated sometimes)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats my understanding, but ideally then we shouldnt have to specify except globally and if really needed maybe font-family: inherit until it gets to where it needs to go? Or a mixin or something?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a fontFamily() mixin!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember for sure but I think the reason we have to specify this in a million places might be MUI styles getting in the way

user-select: none;
font-weight: 400;
}

.pillText {
font-size: 16px;
line-height: 20px;
}

.hoverText {
font-size: 14px;
line-height: normal;
color: #000;
}

.tooltipContainer {
margin: 0 !important; // override MUI's default margin
padding: 8px 16px;
border-radius: 8px;
background: var(--white, #fff);
box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.25);
}

This file was deleted.

16 changes: 11 additions & 5 deletions packages/webapp/src/components/Table/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,31 @@
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/
import Plain from './CellTypes/Plain';
import HoverPillOverflow from './CellTypes/HoverPillOverflow';
import RightChevronLink from './CellTypes/RightChevronLink';
import IconText from './CellTypes/IconText';
import { StatusIndicatorPill, StatusIndicatorPillProps } from '../../StatusIndicatorPill';
import { HoverPillOverflowList, HoverPillOverflowListProps } from '../../HoverPillOverflowList';
import { CellKind } from '../types';
import type { HoverPillOverflowProps } from './CellTypes/HoverPillOverflow';
import type { IconTextProps } from './CellTypes/IconText';
import type { PlainCellProps } from './CellTypes/Plain';
import type { RightChevronLinkProps } from './CellTypes/RightChevronLink';

type HoverPillOverflowPropsStrategy = HoverPillOverflowProps & {
type HoverPillOverflowPropsStrategy = HoverPillOverflowListProps & {
kind: CellKind.HOVER_PILL_OVERFLOW;
};
type IconTextPropsStrategy = IconTextProps & { kind: CellKind.ICON_TEXT };
type PlainCellPropsStrategy = PlainCellProps & { kind: CellKind.PLAIN };
type RightChevronLinkPropsStrategy = RightChevronLinkProps & { kind: CellKind.RIGHT_CHEVRON_LINK };
type StatusIndicatorPillPropsStrategy = StatusIndicatorPillProps & {
kind: CellKind.STATUS_INDICATOR_PILL;
};

type CellStrategyProps =
| HoverPillOverflowPropsStrategy
| IconTextPropsStrategy
| PlainCellPropsStrategy
| RightChevronLinkPropsStrategy;
| RightChevronLinkPropsStrategy
| StatusIndicatorPillPropsStrategy;

/**
* A component that selects between available Cell styles.
Expand All @@ -42,13 +46,15 @@ type CellStrategyProps =
const Cell = ({ kind, ...props }: CellStrategyProps) => {
switch (kind) {
case CellKind.HOVER_PILL_OVERFLOW:
return <HoverPillOverflow {...(props as HoverPillOverflowProps)} />;
return <HoverPillOverflowList {...(props as HoverPillOverflowListProps)} />;
case CellKind.ICON_TEXT:
return <IconText {...(props as IconTextProps)} />;
case CellKind.PLAIN:
return <Plain {...(props as PlainCellProps)} />;
case CellKind.RIGHT_CHEVRON_LINK:
return <RightChevronLink {...(props as RightChevronLinkProps)} />;
case CellKind.STATUS_INDICATOR_PILL:
return <StatusIndicatorPill {...(props as StatusIndicatorPillProps)} />;
default:
const _exhaustiveCheck: never = kind;
return null;
Expand Down
Loading
Loading