Skip to content

Commit 364ad3f

Browse files
authored
chore: Add info message collapse (#4634)
1 parent 4bca509 commit 364ad3f

14 files changed

+138
-61
lines changed

frontend/web/components/EnvironmentDocumentCodeHelp.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ const EnvironmentDocumentCodeHelp: FC<EnvironmentDocumentCodeHelpType> = ({
6969
<Tabs uncontrolled theme='pill'>
7070
<TabItem tabLabel={'Client-side'}>
7171
<div className='mt-3'>
72-
<InfoMessage className='mb-2'>
72+
<InfoMessage
73+
collapseId={'server-side-only-flags'}
74+
className='mb-2'
75+
>
7376
<div>
7477
This will not return any features marked as{' '}
7578
<a
@@ -98,7 +101,7 @@ const EnvironmentDocumentCodeHelp: FC<EnvironmentDocumentCodeHelpType> = ({
98101
snippets={Constants.codeHelp.OFFLINE_LOCAL(data?.[0]?.key)}
99102
/>
100103
) : (
101-
<InfoMessage>
104+
<InfoMessage collapseId={'local-evaluation-mode'}>
102105
In order to setup local evaluation mode you need at least 1
103106
API key, this can be created in{' '}
104107
{envAdmin ? (

frontend/web/components/InfoMessage.js

-43
This file was deleted.
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import React, { PureComponent, useEffect, useState } from 'react'
2+
import Icon, { IconName } from './Icon'
3+
import { chevronForward, close as closeIcon, chevronDown } from 'ionicons/icons'
4+
import { IonIcon } from '@ionic/react'
5+
import { FC } from 'react'
6+
7+
type InfoMessageType = {
8+
buttonText?: string
9+
children?: React.ReactNode
10+
collapseId?: string
11+
icon?: IconName
12+
isClosable?: boolean
13+
title?: string
14+
url?: string
15+
close?: () => void
16+
}
17+
18+
const InfoMessage: FC<InfoMessageType> = ({
19+
buttonText,
20+
children,
21+
close,
22+
collapseId,
23+
icon,
24+
isClosable,
25+
title = 'NOTE',
26+
url,
27+
}) => {
28+
// Retrieve initial collapse state from localStorage
29+
const [isCollapsed, setIsCollapsed] = useState<boolean>(() => {
30+
if (collapseId) {
31+
return JSON.parse(
32+
localStorage.getItem(`infoMessageCollapsed_${collapseId}`) || 'false',
33+
)
34+
}
35+
return false
36+
})
37+
38+
useEffect(() => {
39+
if (collapseId) {
40+
localStorage.setItem(
41+
`infoMessageCollapsed_${collapseId}`,
42+
JSON.stringify(isCollapsed),
43+
)
44+
}
45+
}, [isCollapsed, collapseId])
46+
47+
const handleOpenNewWindow = () => {
48+
if (url) {
49+
window.open(url, '_blank')
50+
}
51+
}
52+
53+
// Toggle collapse state
54+
const handleToggleCollapse = () => {
55+
setIsCollapsed((prevState) => !prevState)
56+
}
57+
58+
return (
59+
<div className={'alert alert-info flex-1'}>
60+
<div className={'flex-fill flex-column gap-2'}>
61+
<div className='d-flex'>
62+
<div
63+
className='user-select-none flex-fill align-items-center d-flex gap-2'
64+
onClick={handleToggleCollapse}
65+
style={{ cursor: 'pointer' }}
66+
>
67+
<Icon
68+
width={22}
69+
height={22}
70+
fill={'#0AADDF'}
71+
name={icon || 'info'}
72+
/>
73+
<div className='title'>{title}</div>
74+
{collapseId && (
75+
<span className='ml-auto lh-1'>
76+
<IonIcon icon={isCollapsed ? chevronForward : chevronDown} />
77+
</span>
78+
)}
79+
</div>
80+
</div>
81+
{!isCollapsed && (
82+
<>
83+
<div className='flex-fill mt-1'>{children}</div>
84+
{url && buttonText && (
85+
<button className='btn my-2 ml-2' onClick={handleOpenNewWindow}>
86+
{buttonText}
87+
</button>
88+
)}
89+
</>
90+
)}
91+
</div>
92+
{isClosable && (
93+
<a onClick={close} className='mt-n2 mr-n2 pl-2'>
94+
<span className={`icon close-btn`}>
95+
<IonIcon icon={closeIcon} />
96+
</span>
97+
</a>
98+
)}
99+
</div>
100+
)
101+
}
102+
103+
export default InfoMessage

frontend/web/components/OrganisationUsage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ const OrganisationUsage: FC<OrganisationUsageType> = ({ organisationId }) => {
241241
</BarChart>
242242
</ResponsiveContainer>
243243
)}
244-
<InfoMessage>
244+
<InfoMessage >
245245
Please be aware that usage data can be delayed by up to 3 hours.
246246
</InfoMessage>
247247
<div>

frontend/web/components/SegmentOverrides.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ class TheComponent extends Component {
676676
<div className='overflow-visible'>
677677
{!this.props.id && (
678678
<div className='my-4'>
679-
<InfoMessage className='mb-4 text-left faint'>
679+
<InfoMessage collapseId={'segment-overrides'} className='mb-4 text-left faint'>
680680
Segment overrides override the environment defaults,
681681
prioritise them by dragging it to the top of the
682682
list. Segment overrides will only apply when you

frontend/web/components/UserGroupList.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const UserGroupList: FC<UserGroupListType> = ({
182182
return (
183183
<FormGroup>
184184
<div className='col-md-6'>
185-
<InfoMessage>
185+
<InfoMessage collapseId={'user-groups'}>
186186
Group admins and users with the organisation permission{' '}
187187
<strong>Manage Groups</strong> can invite additional members to
188188
groups.

frontend/web/components/modals/AssociatedSegmentOverrides.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class TheComponent extends Component {
123123
</div>
124124
) : (
125125
<div className='mt-4'>
126-
<InfoMessage>
126+
<InfoMessage collapseId={'associated-segment-overrides'}>
127127
This shows the list of segment overrides associated with this segment.
128128
<br />
129129
Segment overrides will only apply when you identify via the SDK.{' '}

frontend/web/components/modals/CreateFlag.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ const CreateFlag = class extends Component {
757757
{!!regex && !isEdit && (
758758
<div className='mt-2'>
759759
{' '}
760-
<InfoMessage>
760+
<InfoMessage collapseId={'flag-regex'}>
761761
{' '}
762762
This must conform to the regular expression{' '}
763763
<pre>{regex}</pre>
@@ -1496,7 +1496,11 @@ const CreateFlag = class extends Component {
14961496
}
14971497
</Tooltip>
14981498
<div className='fw-normal transform-none mt-4'>
1499-
<InfoMessage>
1499+
<InfoMessage
1500+
collapseId={
1501+
'identity-overrides'
1502+
}
1503+
>
15001504
Identity overrides override
15011505
feature values for individual
15021506
identities. The overrides take
@@ -1853,15 +1857,21 @@ const CreateFlag = class extends Component {
18531857
{!identity && (
18541858
<div className='text-right mb-3'>
18551859
{project.prevent_flag_defaults ? (
1856-
<InfoMessage className='text-right modal-caption fs-small lh-sm'>
1860+
<InfoMessage
1861+
collapseId={'create-flag'}
1862+
className='text-right modal-caption fs-small lh-sm'
1863+
>
18571864
This will create the feature for{' '}
18581865
<strong>all environments</strong>, you
18591866
can edit this feature per environment
18601867
once the feature's enabled state and
18611868
environment once the feature is created.
18621869
</InfoMessage>
18631870
) : (
1864-
<InfoMessage className='text-right modal-caption fs-small lh-sm'>
1871+
<InfoMessage
1872+
collapseId={'create-flag'}
1873+
className='text-right modal-caption fs-small lh-sm'
1874+
>
18651875
This will create the feature for{' '}
18661876
<strong>all environments</strong>, you
18671877
can edit this feature per environment

frontend/web/components/modals/CreateSegment.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ const CreateSegment: FC<CreateSegmentType> = ({
399399
<form id='create-segment-modal' onSubmit={save}>
400400
{!condensed && (
401401
<div className='mt-3'>
402-
<InfoMessage>
402+
<InfoMessage collapseId={'value-type-conversions'}>
403403
Learn more about rule and trait value type conversions{' '}
404404
<a href='https://docs.flagsmith.com/basic-features/segments#rule-typing'>
405405
here
@@ -606,7 +606,7 @@ const CreateSegment: FC<CreateSegmentType> = ({
606606
</TabItem>
607607
<TabItem tabLabel='Users'>
608608
<div className='my-4'>
609-
<InfoMessage>
609+
<InfoMessage collapseId={'random-identity-sample'}>
610610
This is a random sample of Identities who are either in or out
611611
of this Segment based on the current Segment rules.
612612
</InfoMessage>

frontend/web/components/modals/Payment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const Payment = class extends Component {
8181
if (isAWS) {
8282
return (
8383
<div className='col-md-8'>
84-
<InfoMessage>
84+
<InfoMessage collapseId={'aws-marketplace'}>
8585
Customers with AWS Marketplace subscriptions will need to{' '}
8686
<a
8787
href='https://www.flagsmith.com/contact-us'

frontend/web/components/mv/VariationOptions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function VariationOptions({
3636
)}
3737
{!preventRemove && (
3838
<p className='mb-4'>
39-
<InfoMessage>
39+
<InfoMessage collapseId={'variation-value'}>
4040
Changing a Variation Value will affect{' '}
4141
<strong>all environments</strong>, their weights are specific to
4242
this environment. Existing users will see the new variation value if

frontend/web/components/pages/SegmentsPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ const SegmentsPage: FC<SegmentsPageType> = (props) => {
327327
/>
328328
</FormGroup>
329329

330-
<InfoMessage>
330+
<InfoMessage collapseId={'segment-identify'}>
331331
Segments require you to identitfy users, setting traits will add
332332
users to segments.
333333
</InfoMessage>

frontend/web/components/pages/UserPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ const UserPage = class extends Component {
384384
<div>
385385
Features
386386
<div className='fw-normal mt-2 fs-medium'>
387-
<InfoMessage>
387+
<InfoMessage collapseId={'identity-priority'}>
388388
Overriding features here will take
389389
priority over any segment override.
390390
Any features that are not overridden

frontend/web/styles/project/_alert.scss

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@
3636
background-color: $alert-warning-bg;
3737
border-color: $alert-warning-border-color;
3838
}
39-
39+
.alert {
40+
padding-top: $spacer / 2;
41+
padding-bottom: $spacer / 2;
42+
padding-left: $spacer / 2;
43+
padding-right: $spacer / 2;
44+
}
4045
.alert-info {
4146
background-color: $alert-info-bg;
4247
border-color: $alert-info-border-color;
@@ -48,7 +53,6 @@
4853
}
4954
.title {
5055
font-weight: 500;
51-
margin-bottom: 2px;
5256
color: $body-color;
5357
}
5458
a {

0 commit comments

Comments
 (0)