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

[GEN-1680]: added new "toggle buttons" component #1723

Merged
merged 29 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f97a5a1
Merge pull request #4 from odigos-io/new-ui
BenElferink Oct 27, 2024
afa1268
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 27, 2024
536f32f
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 28, 2024
fa352be
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 28, 2024
a4f03d8
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 28, 2024
b3fa682
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
f0a397f
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
2c13a75
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
3ab5c0c
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
977c57b
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 30, 2024
d95b6fe
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 30, 2024
cde9bdd
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 31, 2024
7ca44f7
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 31, 2024
29d2e0d
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
5647431
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
8d22beb
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
e53746d
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
6fa1955
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 4, 2024
a6b6ec2
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 5, 2024
746f560
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 5, 2024
5c55719
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 5, 2024
834e5ed
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 6, 2024
8f1cd3e
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 7, 2024
f4435c0
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 7, 2024
1cd0a4b
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 10, 2024
eec5074
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 10, 2024
c94d982
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 10, 2024
2a57f9d
feat: added new "toggle buttons" component
BenElferink Nov 10, 2024
3c2ea8a
fix: code review
BenElferink Nov 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components';
import { type ActionInput } from '@/types';
import ActionCustomFields from './custom-fields';
import { type ActionOption } from '../choose-action-modal/action-options';
import { DocsButton, Input, Text, TextArea, Toggle, MonitoringCheckboxes, SectionTitle } from '@/reuseable-components';
import { DocsButton, Input, Text, TextArea, MonitoringCheckboxes, SectionTitle, ToggleButtons } from '@/reuseable-components';

const FieldWrapper = styled.div`
width: 100%;
Expand All @@ -27,34 +27,19 @@ const ChooseActionBody: React.FC<ChooseActionContentProps> = ({ isUpdate, action
{isUpdate && (
<FieldWrapper>
<FieldTitle>Status</FieldTitle>
<Toggle
title={!formData.disable ? 'Active' : 'Inactive'}
initialValue={!formData.disable}
onChange={(bool) => handleFormChange('disable', !bool)}
/>
<ToggleButtons initialValue={!formData.disable} onChange={(bool) => handleFormChange('disable', !bool)} />
</FieldWrapper>
)}

{!isUpdate && (
<SectionTitle title='' description={action.docsDescription as string} actionButton={<DocsButton endpoint={action.docsEndpoint} />} />
)}
{!isUpdate && <SectionTitle title='' description={action.docsDescription as string} actionButton={<DocsButton endpoint={action.docsEndpoint} />} />}

<FieldWrapper>
<MonitoringCheckboxes
allowedSignals={action.allowedSignals}
selectedSignals={formData.signals}
setSelectedSignals={(value) => handleFormChange('signals', value)}
/>
<MonitoringCheckboxes allowedSignals={action.allowedSignals} selectedSignals={formData.signals} setSelectedSignals={(value) => handleFormChange('signals', value)} />
</FieldWrapper>

{!isUpdate && (
<FieldWrapper>
<Input
title='Action name'
placeholder='Use a name that describes the action'
value={formData.name}
onChange={({ target: { value } }) => handleFormChange('name', value)}
/>
<Input title='Action name' placeholder='Use a name that describes the action' value={formData.name} onChange={({ target: { value } }) => handleFormChange('name', value)} />
</FieldWrapper>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components';
import RuleCustomFields from './custom-fields';
import type { InstrumentationRuleInput } from '@/types';
import type { RuleOption } from '../add-rule-modal/rule-options';
import { DocsButton, Input, Text, TextArea, Toggle, SectionTitle } from '@/reuseable-components';
import { DocsButton, Input, Text, TextArea, SectionTitle, ToggleButtons } from '@/reuseable-components';

const FieldWrapper = styled.div`
width: 100%;
Expand All @@ -27,24 +27,15 @@ const ChooseRuleBody: React.FC<Props> = ({ isUpdate, rule, formData, handleFormC
{isUpdate && (
<FieldWrapper>
<FieldTitle>Status</FieldTitle>
<Toggle
title={!formData.disabled ? 'Active' : 'Inactive'}
initialValue={!formData.disabled}
onChange={(bool) => handleFormChange('disabled', !bool)}
/>
<ToggleButtons initialValue={!formData.disabled} onChange={(bool) => handleFormChange('disabled', !bool)} />
</FieldWrapper>
)}

{!isUpdate && <SectionTitle title='' description={rule.docsDescription as string} actionButton={<DocsButton endpoint={rule.docsEndpoint} />} />}

{!isUpdate && (
<FieldWrapper>
<Input
title='Rule name'
placeholder='Use a name that describes the rule'
value={formData.ruleName}
onChange={({ target: { value } }) => handleFormChange('ruleName', value)}
/>
<Input title='Rule name' placeholder='Use a name that describes the rule' value={formData.ruleName} onChange={({ target: { value } }) => handleFormChange('ruleName', value)} />
</FieldWrapper>
)}

Expand Down
8 changes: 8 additions & 0 deletions frontend/webapp/public/icons/common/circled-check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions frontend/webapp/public/icons/common/circled-cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/webapp/reuseable-components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './dropdown';
export * from './divider';
export * from './counter';
export * from './toggle';
export * from './toggle-buttons';
export * from './checkbox';
export * from './modal';
export * from './modal/warning-modal';
Expand Down
97 changes: 97 additions & 0 deletions frontend/webapp/reuseable-components/toggle-buttons/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import Image from 'next/image';
import { Tooltip } from '../tooltip';
import styled from 'styled-components';
import React, { useEffect, useState } from 'react';

interface ToggleProps {
activeText?: string;
inactiveText?: string;
tooltip?: string;
initialValue?: boolean;
onChange?: (value: boolean) => void;
disabled?: boolean;
}

const Container = styled.div`
width: 100%;
display: flex;
align-items: center;
`;

const BaseButton = styled.button`
width: 100%;
padding: 12px;
gap: 4px;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid ${({ theme }) => theme.colors.border};
color: ${({ theme }) => theme.colors.secondary};
font-family: ${({ theme }) => theme.font_family.secondary};
font-size: 14px;
text-decoration: underline;
text-transform: uppercase;
cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')};
opacity: ${({ disabled }) => (disabled ? 0.6 : 1)};
`;

const ActiveButton = styled(BaseButton)`
border-radius: 32px 0 0 32px;
background-color: ${({ theme }) => theme.colors.blank_background};
&.colored {
background-color: ${({ theme }) => theme.colors.dark_green};
}
&:hover {
border-color: ${({ theme }) => theme.colors.secondary};
}
transition: background-color 0.3s;
`;

const InactiveButton = styled(BaseButton)`
border-radius: 0 32px 32px 0;
background-color: ${({ theme }) => theme.colors.blank_background};
&.colored {
background-color: ${({ theme }) => theme.colors.darker_red};
}
&:hover {
border-color: ${({ theme }) => theme.colors.secondary};
}
transition: background-color 0.3s;
`;

const ToggleButtons: React.FC<ToggleProps> = ({ activeText = 'Active', inactiveText = 'Inactive', tooltip, initialValue = false, onChange, disabled }) => {
const [isActive, setIsActive] = useState(initialValue);
useEffect(() => setIsActive(initialValue), [initialValue]);

const handleToggle = (forcedBool?: boolean) => {
if (disabled) return;

let newValue = initialValue;

setIsActive((prev) => {
newValue = typeof forcedBool === 'boolean' ? forcedBool : !prev;
return newValue;
});

if (onChange) onChange(newValue);
};

return (
<Tooltip text={tooltip || ''}>
<Container>
<ActiveButton className={isActive ? 'colored' : ''} onClick={() => handleToggle(true)} disabled={disabled}>
<Image src='/icons/common/circled-check.svg' alt='' width={16} height={16} />
{activeText}
</ActiveButton>
<InactiveButton className={isActive ? '' : 'colored'} onClick={() => handleToggle(false)} disabled={disabled}>
<Image src='/icons/common/circled-cross.svg' alt='' width={16} height={16} />
{inactiveText}
</InactiveButton>
</Container>

{tooltip && <Image src='/icons/common/info.svg' alt='' width={16} height={16} style={{ margin: '0 8px' }} />}
</Tooltip>
);
};

export { ToggleButtons };
25 changes: 13 additions & 12 deletions frontend/webapp/reuseable-components/toggle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,29 @@ const ToggleSwitch = styled.div<{ isActive: boolean; disabled?: boolean }>`

const Toggle: React.FC<ToggleProps> = ({ title, tooltip, initialValue = false, onChange, disabled }) => {
const [isActive, setIsActive] = useState(initialValue);

useEffect(() => {
setIsActive(initialValue);
}, [initialValue]);
useEffect(() => setIsActive(initialValue), [initialValue]);

const handleToggle = () => {
if (!disabled) {
const newValue = !isActive;
setIsActive(newValue);
if (onChange) {
onChange(newValue);
}
}
if (disabled) return;

let newValue = initialValue;

setIsActive((prev) => {
newValue = !prev;
return newValue;
});

if (onChange) onChange(newValue);
};

return (
<Tooltip text={tooltip || ''}>
<Container disabled={disabled} onClick={handleToggle}>
<ToggleSwitch isActive={isActive} disabled={disabled} />
<Text size={14}>{title}</Text>
{tooltip && <Image src='/icons/common/info.svg' alt='' width={16} height={16} />}
</Container>

{tooltip && <Image src='/icons/common/info.svg' alt='' width={16} height={16} />}
</Tooltip>
);
};
Expand Down
3 changes: 2 additions & 1 deletion frontend/webapp/styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const colors = {
blank_background: '#11111100',

dark_red: '#802828',
dark_green: '#2d4323',
darker_red: '#611F1F',
dark_green: '#2D4323',

warning: '#472300',
error: '#431919',
Expand Down
Loading