-
Notifications
You must be signed in to change notification settings - Fork 367
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
refactor: [M3-7750] - Update launchdarkly-react-client-sdk
to latest
#10165
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Tech Stories | ||
--- | ||
|
||
Update `launchdarkly-react-client-sdk` ([#10165](https://github.com/linode/manager/pull/10165)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ import { | |
DocumentTitleSegment, | ||
withDocumentTitleProvider, | ||
} from 'src/components/DocumentTitle'; | ||
import withFeatureFlagConsumer from 'src/containers/withFeatureFlagConsumer.container'; | ||
import withFeatureFlagProvider from 'src/containers/withFeatureFlagProvider.container'; | ||
import TheApplicationIsOnFire from 'src/features/TheApplicationIsOnFire'; | ||
|
||
|
@@ -23,37 +22,35 @@ import { useSetupFeatureFlags } from './useSetupFeatureFlags'; | |
export const App = () => <BaseApp />; | ||
|
||
const BaseApp = withDocumentTitleProvider( | ||
withFeatureFlagProvider( | ||
withFeatureFlagConsumer(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The consumer is not needed here because we don't need to read |
||
const { isLoading } = useInitialRequests(); | ||
|
||
const { areFeatureFlagsLoading } = useSetupFeatureFlags(); | ||
|
||
if (isLoading || areFeatureFlagsLoading) { | ||
return <SplashScreen />; | ||
} | ||
|
||
return ( | ||
<ErrorBoundary fallback={<TheApplicationIsOnFire />}> | ||
{/** Accessibility helper */} | ||
<a className="skip-link" href="#main-content"> | ||
Skip to main content | ||
</a> | ||
<div hidden> | ||
<span id="new-window">Opens in a new window</span> | ||
<span id="external-site">Opens an external site</span> | ||
<span id="external-site-new-window"> | ||
Opens an external site in a new window | ||
</span> | ||
</div> | ||
<GoTo /> | ||
<DocumentTitleSegment segment="Akamai Cloud Manager" /> | ||
<MainContent /> | ||
<GlobalListeners /> | ||
</ErrorBoundary> | ||
); | ||
}) | ||
) | ||
withFeatureFlagProvider(() => { | ||
const { isLoading } = useInitialRequests(); | ||
|
||
const { areFeatureFlagsLoading } = useSetupFeatureFlags(); | ||
|
||
if (isLoading || areFeatureFlagsLoading) { | ||
return <SplashScreen />; | ||
} | ||
|
||
return ( | ||
<ErrorBoundary fallback={<TheApplicationIsOnFire />}> | ||
{/** Accessibility helper */} | ||
<a className="skip-link" href="#main-content"> | ||
Skip to main content | ||
</a> | ||
<div hidden> | ||
<span id="new-window">Opens in a new window</span> | ||
<span id="external-site">Opens an external site</span> | ||
<span id="external-site-new-window"> | ||
Opens an external site in a new window | ||
</span> | ||
</div> | ||
<GoTo /> | ||
<DocumentTitleSegment segment="Akamai Cloud Manager" /> | ||
<MainContent /> | ||
<GlobalListeners /> | ||
</ErrorBoundary> | ||
); | ||
}) | ||
); | ||
|
||
const GlobalListeners = () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a much cleaner rewrite of withFeatureFlagConsumer.container.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as React from 'react'; | ||
|
||
import { useFlags } from 'src/hooks/useFlags'; | ||
|
||
import type { FlagSet } from 'src/featureFlags' | ||
bnussman-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export interface WithFeatureFlagProps { | ||
flags: FlagSet; | ||
} | ||
|
||
export const withFeatureFlags = <Props>( | ||
Component: React.ComponentType<Props & WithFeatureFlagProps> | ||
) => { | ||
return (props: Props) => { | ||
const flags = useFlags(); | ||
|
||
return React.createElement(Component, { | ||
...props, | ||
flags, | ||
}); | ||
}; | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ import { | |
propEq, | ||
} from 'ramda'; | ||
import * as React from 'react'; | ||
import { compose as recompose } from 'recompose'; | ||
|
||
import { ActionsPanel } from 'src/components/ActionsPanel/ActionsPanel'; | ||
import { Button } from 'src/components/Button/Button'; | ||
|
@@ -37,9 +36,6 @@ import { TableHead } from 'src/components/TableHead'; | |
import { TableRow } from 'src/components/TableRow'; | ||
import { TableRowEmpty } from 'src/components/TableRowEmpty/TableRowEmpty'; | ||
import { Typography } from 'src/components/Typography'; | ||
import withFeatureFlags, { | ||
FeatureFlagConsumerProps, | ||
} from 'src/containers/withFeatureFlagConsumer.container'; | ||
import { | ||
getAPIErrorOrDefault, | ||
getErrorStringOrDefault, | ||
|
@@ -52,7 +48,7 @@ import { DomainRecordActionMenu } from './DomainRecordActionMenu'; | |
import { DomainRecordDrawer } from './DomainRecordDrawer'; | ||
import { StyledDiv, StyledGrid, StyledTableCell } from './DomainRecords.styles'; | ||
|
||
interface DomainRecordsProps { | ||
interface Props { | ||
domain: Domain; | ||
domainRecords: DomainRecord[]; | ||
updateDomain: (data: { id: number } & UpdateDomainPayload) => Promise<Domain>; | ||
|
@@ -79,8 +75,6 @@ interface State { | |
types: IType[]; | ||
} | ||
|
||
type CombinedProps = DomainRecordsProps & FeatureFlagConsumerProps; | ||
|
||
interface IType { | ||
columns: { | ||
render: (r: Domain | DomainRecord) => JSX.Element | null | string; | ||
|
@@ -99,8 +93,8 @@ const createLink = (title: string, handler: () => void) => ( | |
</Button> | ||
); | ||
|
||
class DomainRecords extends React.Component<CombinedProps, State> { | ||
constructor(props: CombinedProps) { | ||
class DomainRecords extends React.Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props); | ||
this.state = { | ||
confirmDialog: { | ||
|
@@ -112,7 +106,7 @@ class DomainRecords extends React.Component<CombinedProps, State> { | |
}; | ||
} | ||
|
||
componentDidUpdate(prevProps: CombinedProps) { | ||
componentDidUpdate(prevProps: Props) { | ||
if ( | ||
!equals(prevProps.domainRecords, this.props.domainRecords) || | ||
!equals(prevProps.domain, this.props.domain) | ||
|
@@ -879,12 +873,10 @@ const prependLinodeNS = compose<any, any, DomainRecord[]>( | |
); | ||
|
||
const getNSRecords = compose< | ||
DomainRecordsProps, | ||
Props, | ||
DomainRecord[], | ||
DomainRecord[], | ||
DomainRecord[] | ||
>(prependLinodeNS, filter(typeEq('NS')), pathOr([], ['domainRecords'])); | ||
|
||
export default recompose<CombinedProps, DomainRecordsProps>(withFeatureFlags)( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component does not consume feature flags |
||
DomainRecords | ||
); | ||
export default DomainRecords; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ import { | |
WithProfileProps, | ||
withProfile, | ||
} from 'src/containers/profile.container'; | ||
import withFeatureFlagConsumer from 'src/containers/withFeatureFlagConsumer.container'; | ||
import { BackupsCTA } from 'src/features/Backups/BackupsCTA'; | ||
import { MigrateLinode } from 'src/features/Linodes/MigrateLinode/MigrateLinode'; | ||
import { DialogType } from 'src/features/Linodes/types'; | ||
|
@@ -432,7 +431,6 @@ const sendGroupByAnalytic = (value: boolean) => { | |
|
||
export const enhanced = compose<CombinedProps, LinodesLandingProps>( | ||
withRouter, | ||
withFeatureFlagConsumer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component does not consume feature flags so this can be removed. |
||
withProfile | ||
); | ||
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to address a breaking change here. Launch Darkly no longer exports |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { | |
import userEvent from '@testing-library/user-event'; | ||
import mediaQuery from 'css-mediaquery'; | ||
import { Formik, FormikConfig, FormikValues } from 'formik'; | ||
import { Provider as LDProvider } from 'launchdarkly-react-client-sdk/lib/context'; | ||
import { LDProvider } from 'launchdarkly-react-client-sdk'; | ||
import { SnackbarProvider } from 'notistack'; | ||
import { mergeDeepRight } from 'ramda'; | ||
import * as React from 'react'; | ||
|
@@ -95,10 +95,10 @@ export const wrapWithTheme = (ui: any, options: Options = {}) => { | |
<QueryClientProvider client={passedQueryClient || queryClient}> | ||
<LinodeThemeWrapper theme={options.theme}> | ||
<LDProvider | ||
value={{ | ||
flagKeyMap: {}, | ||
flags: options.flags ?? {}, | ||
}} | ||
clientSideID={''} | ||
deferInitialization | ||
flags={options.flags ?? {}} | ||
options={{ bootstrap: options.flags }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, here is some context for others:
|
||
> | ||
<SnackbarProvider> | ||
<MemoryRouter {...options.MemoryRouter}> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm going to start pinning exact versions (without the
^
) so that if we ever have to re-generate the lockfile, the minor version won't update. Usually this is fine because minor versions shouldn't case breaking changes, but in this case for launch darkly, it did.Using the exact version will make things more predictable and safe