-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9345 from linode/staging
Release v1.96.2 - `staging` → `master`
- Loading branch information
Showing
62 changed files
with
437 additions
and
1,437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 35 additions & 86 deletions
121
packages/manager/src/containers/withLinodes.container.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,40 @@ | ||
import { Linode } from '@linode/api-v4/lib/linodes'; | ||
import { APIError, Filter, Params } from '@linode/api-v4/lib/types'; | ||
import { path } from 'ramda'; | ||
import { connect, InferableComponentEnhancerWithProps } from 'react-redux'; | ||
import { ApplicationState } from 'src/store'; | ||
import { requestLinodes } from 'src/store/linodes/linode.requests'; | ||
import { State } from 'src/store/linodes/linodes.reducer'; | ||
import { LinodeWithMaintenanceAndDisplayStatus } from 'src/store/linodes/types'; | ||
import { ThunkDispatch } from 'src/store/types'; | ||
import { GetAllData } from 'src/utilities/getAll'; | ||
|
||
export interface DispatchProps { | ||
getLinodes: ( | ||
params?: Params, | ||
filters?: Filter | ||
) => Promise<GetAllData<Linode>>; | ||
import React from 'react'; | ||
import { CreateLinodeRequest, Linode } from '@linode/api-v4/lib/linodes'; | ||
import { APIError } from '@linode/api-v4/lib/types'; | ||
import { | ||
useAllLinodesQuery, | ||
useCreateLinodeMutation, | ||
} from 'src/queries/linodes/linodes'; | ||
|
||
interface Actions { | ||
createLinode: (data: CreateLinodeRequest) => Promise<Linode>; | ||
} | ||
|
||
/* tslint:disable-next-line */ | ||
export interface StateProps { | ||
linodesError?: APIError[]; | ||
linodesLoading: State['loading']; | ||
linodesData: LinodeWithMaintenanceAndDisplayStatus[]; | ||
linodesLastUpdated: State['lastUpdated']; | ||
linodesResults: State['results']; | ||
export interface WithLinodesProps { | ||
linodesError: APIError[] | null; | ||
linodesLoading: boolean; | ||
linodesData: Linode[] | undefined; | ||
linodeActions: Actions; | ||
} | ||
|
||
type MapProps<ReduxStateProps, OwnProps> = ( | ||
ownProps: OwnProps, | ||
linodes: Linode[], | ||
loading: boolean, | ||
error?: APIError[] | ||
) => ReduxStateProps & Partial<StateProps>; | ||
|
||
export type Props = DispatchProps & StateProps; | ||
|
||
interface Connected { | ||
<ReduxStateProps, OwnProps>( | ||
mapStateToProps: MapProps<ReduxStateProps, OwnProps> | ||
): InferableComponentEnhancerWithProps< | ||
ReduxStateProps & Partial<StateProps> & DispatchProps & OwnProps, | ||
OwnProps | ||
>; | ||
<ReduxStateProps, OwnProps>(): InferableComponentEnhancerWithProps< | ||
ReduxStateProps & DispatchProps & OwnProps, | ||
OwnProps | ||
>; | ||
} | ||
|
||
const connected: Connected = <ReduxState extends {}, OwnProps extends {}>( | ||
mapStateToProps?: MapProps<ReduxState, OwnProps> | ||
) => | ||
connect< | ||
(ReduxState & Partial<StateProps>) | StateProps, | ||
DispatchProps, | ||
OwnProps, | ||
ApplicationState | ||
>( | ||
(state, ownProps) => { | ||
const { | ||
loading, | ||
error, | ||
itemsById, | ||
lastUpdated, | ||
results, | ||
} = state.__resources.linodes; | ||
const linodes = Object.values(itemsById); | ||
if (mapStateToProps) { | ||
return mapStateToProps( | ||
ownProps, | ||
linodes, | ||
loading, | ||
path(['read'], error) | ||
); | ||
} | ||
|
||
return { | ||
linodesError: path(['read'], error), | ||
linodesLoading: loading, | ||
linodesData: linodes, | ||
linodesResults: results, | ||
linodesLastUpdated: lastUpdated, | ||
}; | ||
export const withLinodes = <Props>( | ||
Component: React.ComponentType<Props & WithLinodesProps> | ||
) => (props: Props) => { | ||
const { | ||
data: linodesData, | ||
isLoading: linodesLoading, | ||
error: linodesError, | ||
} = useAllLinodesQuery(); | ||
|
||
const { mutateAsync: createLinode } = useCreateLinodeMutation(); | ||
|
||
return React.createElement(Component, { | ||
...props, | ||
linodesData, | ||
linodesLoading, | ||
linodesError, | ||
linodeActions: { | ||
createLinode, | ||
}, | ||
(dispatch: ThunkDispatch) => ({ | ||
getLinodes: (params, filter) => | ||
dispatch(requestLinodes({ params, filter })), | ||
}) | ||
); | ||
|
||
export default connected; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.