-
Notifications
You must be signed in to change notification settings - Fork 613
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
[WIP] Use connectToExtensions HOC for reactive extension consumption #2269
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vojtechszocs The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
5ecf2b5
to
9129322
Compare
/hold |
great work @vojtechszocs ! I wonder if it would be beneficial to store extensions in redux store and then the example you posted would look like import { connect } from 'react-redux';
import {
connectToExtensions,
Extension,
DashboardsCard,
DashboardsTab,
isDashboardsCard,
isDashboardsTab,
} from '@console/plugin-sdk';
const mapStateToProps = ({ k8s, extensions }) => ({
kindsInFlight: k8s.getIn(['RESOURCES', 'inFlight']),
k8sModels: k8s.getIn(['RESOURCES', 'models']),
pluginTabs: extensions.filter(isDashboardsTab),
pluginCards: extensions.filter(isDashboardsCard),
});
const DashboardsPage_: React.FC<DashboardsPageProps> = ({
match,
kindsInFlight,
k8sModels,
pluginTabs,
pluginCards,
}) => {
// no call to plugins.registry
};
export const DashboardsPage = connect(mapStateToProps)(DashboardsPage_);
type DashboardsPageProps = RouteComponentProps & {
kindsInFlight: boolean;
k8sModels: ImmutableMap<string, any>;
pluginCards: DashboardsCard[];
pluginTabs: DashboardsTab[];
}; is there any downside to this approach ? |
9129322
to
a2164b1
Compare
Rebased on latest |
a2164b1
to
9247c56
Compare
Fixed all ESLint issues. |
9247c56
to
98931bc
Compare
Thanks @rawagner for your review! π
This is similar to existing HOC creators like Removing import {
getExtensionsInUse,
isDashboardsTab,
isDashboardsCard,
} from '@console/plugin-sdk';
// in this example, "extensions" refers to *all* extensions stored in Redux
const mapStateToProps = ({ k8s, extensions }) => ({
kindsInFlight: k8s.getIn(['RESOURCES', 'inFlight']),
k8sModels: k8s.getIn(['RESOURCES', 'models']),
pluginTabs: getExtensionsInUse(extensions.filter(isDashboardsTab)),
pluginCards: getExtensionsInUse(extensions.filter(isDashboardsCard)),
}); but this could be optimized by storing const mapStateToProps = ({ k8s, extensionsInUse }) => ({
kindsInFlight: k8s.getIn(['RESOURCES', 'inFlight']),
k8sModels: k8s.getIn(['RESOURCES', 'models']),
pluginTabs: extensionsInUse.filter(isDashboardsTab),
pluginCards: extensionsInUse.filter(isDashboardsCard),
}); In terms of a reducer function (i.e. const activePlugins = (process.env.NODE_ENV !== 'test')
? require('@console/active-plugins').default as ActivePlugin[]
: []; breaking the constraint of reducer being a pure function. But we could work around this by passing pre-initialized // the second argument, "{}", is the initial Redux state
const store = createStore(reducers, {}, composeEnhancers(applyMiddleware(thunk))); TL;DRI'd favor more specific HOC creators like
As for how to store Console extensions, I'm fine with having them managed via Redux state too. I'm also curious what other people think about this. |
@christianvogt @spadgett @jelkosz The only remaining issue before removing the WIP label is
Reducer in However, by design, only Note: the default "Administrator" perspective ( So what's the best way to solve this problem?
|
Thanks for the HU on this @vojtechszocs |
@vojtechszocs: This pull request references a valid Bugzilla bug. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@vojtechszocs I dislike the behavior of |
Note to self (cc @christianvogt): remove |
@vojtechszocs: No Bugzilla bug is referenced in the title of this pull request. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/bugzilla refresh |
@vojtechszocs: No Bugzilla bug is referenced in the title of this pull request. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Original action items
Additional action items
Cleanup items
|
Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle stale |
@vojtechszocs: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Stale issues rot after 30d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle rotten |
Rotten issues close after 30d of inactivity. Reopen the issue by commenting /close |
@openshift-bot: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Fixes: CNV-1772, CNV-1773
π·ββοΈ Work In Progress:
needs rebase,ESLint fixups, rework default perspective handling π·ββοΈThis PR introduces
connectToExtensions
higher-order component (HOC) used to connect existing components to Console extensions. This is a direct analogy toconnect
from react-redux, but usingExtension[]
as the source of truth.Let's take
public/components/dashboards-page/dashboards.tsx
as an example.code before
code after
Components no longer reference the
plugins.registry
object directly. Instead, they specify how extensions that are currently in use are mapped to their props viamapExtensionsToProps
function.Extensions in use
An extension is in use (takes effect) when:
it is an always-on extension (i.e. not gated by any feature flags)
otherwise, its
flags
constraints must be satisfied:required
flags are resolved totrue
disallowed
flags are resolved tofalse
Extensions declared as always-on:
ModelFeatureFlag
- adding new feature flag based on CRDModelDefinition
- adding new (static) k8s model definitionsGating all plugin's extensions
ModelFeatureFlag
extension type has a newgateExtensions
property, which defaults totrue
.When enabled, the corresponding flag is automatically added to
flags.required
array for all the plugin's extensions (excluding always-on extensions).The default value of
true
reflects the general assumption that extensions contributed by plugin X should be gated by flag(s) introduced by plugin X.Gating specific extensions
Each extension can specify feature flags which are required and/or disallowed in order to put that particular extension into effect.
For example:
At runtime, above DevConsole extension's required flags will become:
due to a
FeatureFlag/Model
extension adding theSHOW_PIPELINE
flag./cc @spadgett @alecmerdler @christianvogt @jelkosz @rawagner