Skip to content

Commit

Permalink
Merge pull request #8903 from meshery/revert-8893-theBeginner86/chore/24
Browse files Browse the repository at this point in the history
Revert "[extensions] Fix Collaborator Extension Point Re-rendering"
  • Loading branch information
theBeginner86 committed Sep 24, 2023
2 parents cea5d5e + 45040f2 commit 6640f6f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
5 changes: 1 addition & 4 deletions ui/components/ExtensionSandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import normalizeURI from "../utils/normalizeURI";
import dataFetch from "../lib/data-fetch";
import ExtensionPointSchemaValidator from "../utils/ExtensionPointSchemaValidator";
import LoadingScreen from "./LoadingComponents/LoadingComponent";
import { updateCollaboratorExtState } from "../lib/store";

/**
* getPath returns the current pathname
Expand Down Expand Up @@ -311,7 +310,7 @@ function createPathForRemoteComponent(componentName) {
* 4. collaborator - for collaborator extension
* @param {{ type: "navigator" | "user_prefs" | "account" | "collaborator", Extension: JSX.Element }} props
*/
function ExtensionSandbox ({ type, Extension, isDrawerCollapsed, toggleDrawer, capabilitiesRegistry, updateCollaboratorExtState }) {
function ExtensionSandbox({ type, Extension, isDrawerCollapsed, toggleDrawer, capabilitiesRegistry }) {
const [extension, setExtension] = useState([]);
const [isLoading, setIsLoading] = useState(true);

Expand Down Expand Up @@ -378,7 +377,6 @@ function ExtensionSandbox ({ type, Extension, isDrawerCollapsed, toggleDrawer, c
: (type === "collaborator")?
(
getComponentURIFromPathForCollaborator(extension).map(uri => {
updateCollaboratorExtState({ collaboratorExtState : true });
return <Extension url={createPathForRemoteComponent(uri)} key={uri} />
})
)
Expand All @@ -396,7 +394,6 @@ function ExtensionSandbox ({ type, Extension, isDrawerCollapsed, toggleDrawer, c

const mapDispatchToProps = (dispatch) => ({
toggleDrawer : bindActionCreators(toggleDrawer, dispatch),
updateCollaboratorExtState : bindActionCreators(updateCollaboratorExtState, dispatch),
});

const mapStateToProps = (state) => ({
Expand Down
22 changes: 11 additions & 11 deletions ui/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import {
successHandlerGenerator, errorHandlerGenerator
} from './ConnectionWizard/helpers/common';
import { promisifiedDataFetch } from '../lib/data-fetch';
import { updateK8SConfig, updateProgress, updateCapabilities, updateCollaboratorExtState } from '../lib/store';
import { updateK8SConfig, updateProgress, updateCapabilities } from '../lib/store';
import { bindActionCreators } from 'redux';
import BadgeAvatars from './CustomAvatar';
import { CapabilitiesRegistry as CapabilityRegistryClass } from '../utils/disabledComponents';
import _ from 'lodash';
import { SETTINGS } from '../constants/navigator';
import { cursorNotAllowed, disabledStyle } from '../css/disableComponent.styles';
import PromptComponent from './PromptComponent';
Expand Down Expand Up @@ -514,7 +516,7 @@ function K8sContextMenu({
)
}

class Header extends React.PureComponent {
class Header extends React.Component {

constructor(props) {
super(props);
Expand All @@ -525,7 +527,6 @@ class Header extends React.PureComponent {
}
}
componentDidMount() {
console.log("header component mounted")
dataFetch(
"/api/provider/capabilities",
{
Expand All @@ -538,7 +539,7 @@ class Header extends React.PureComponent {

this.setState({
collaboratorExt : ExtensionPointSchemaValidator("collaborator")(result?.extensions?.collaborator),
capabilityregistryObj : capabilitiesRegistryObj,
capabilitiesRegistryObj,
});
this.props.updateCapabilities({ capabilitiesRegistry : result })
}
Expand All @@ -550,12 +551,13 @@ class Header extends React.PureComponent {

}

shouldComponentUpdate(nextProps) {
if (!nextProps?.collaboratorExtState && this.state.capabilityregistryObj !== null) {
return true;
componentDidUpdate(prevProps) {
if (!_.isEqual(prevProps.capabilitiesRegistry, this.props.capabilitiesRegistry)) {
this.setState({ capabilityregistryObj : new CapabilityRegistryClass(this.props.capabilitiesRegistry) });
}
return false;

}

componentWillUnmount = () => {
this._isMounted = false;
}
Expand Down Expand Up @@ -654,16 +656,14 @@ const mapStateToProps = (state) => {
k8sconfig : state.get('k8sConfig'),
operatorState : state.get('operatorState'),
meshSyncState : state.get('meshSyncState'),
capabilitiesRegistry : state.get("capabilitiesRegistry"),
collaboratorExtState : state.get("collaboratorExtState"),
capabilitiesRegistry : state.get("capabilitiesRegistry")
})
};

const mapDispatchToProps = (dispatch) => ({
updateK8SConfig : bindActionCreators(updateK8SConfig, dispatch),
updateProgress : bindActionCreators(updateProgress, dispatch),
updateCapabilities : bindActionCreators(updateCapabilities, dispatch),
updateCollaboratorExtState : bindActionCreators(updateCollaboratorExtState, dispatch),
});


Expand Down
12 changes: 2 additions & 10 deletions ui/lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const initialState = fromJS({
// global gql-subscriptions
operatorState: null,
meshSyncState: null,
collaboratorExtState: false,
});

export const actionTypes = {
Expand Down Expand Up @@ -100,7 +99,7 @@ export const actionTypes = {
UPDATE_EXTENSION_TYPE: 'UPDATE_EXTENSION_TYPE',
UPDATE_CAPABILITY_REGISTRY: 'UPDATE_CAPABILITY_REGISTRY',
UPDATE_TELEMETRY_URLS : 'UPDATE_TELEMETRY_URLS',
UPDATE_COLLABORTOR_EXT_STATE: 'UPDATE_COLLABORTOR_EXT_STATE',

};

// REDUCERS
Expand Down Expand Up @@ -182,10 +181,7 @@ export const reducer = (state = initialState, action) => {
return state.merge({meshSyncState: action.meshSyncState});

case actionTypes.UPDATE_EXTENSION_TYPE:
return state.merge({ extensionType: action.extensionType });

case actionTypes.UPDATE_COLLABORTOR_EXT_STATE:
return state.merge({ collaboratorExtState: action.collaboratorExtState });
return state.merge({ extensionType: action.extensionType });

case actionTypes.UPDATE_CAPABILITY_REGISTRY:
return state.merge({capabilitiesRegistry: action.capabilitiesRegistry})
Expand Down Expand Up @@ -289,10 +285,6 @@ export const updateExtensionType = ({ extensionType }) => dispatch => {
return dispatch({type: actionTypes.UPDATE_EXTENSION_TYPE, extensionType})
}

export const updateCollaboratorExtState = ({ collaboratorExtState }) => dispatch => {
return dispatch({type: actionTypes.UPDATE_COLLABORTOR_EXT_STATE, collaboratorExtState})
}

export const updateCapabilities = ({capabilitiesRegistry}) => dispatch => {
return dispatch({type: actionTypes.UPDATE_CAPABILITY_REGISTRY, capabilitiesRegistry})
}
Expand Down
2 changes: 2 additions & 0 deletions ui/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ class MesheryApp extends App {
document.removeEventListener("fullscreenchange", this.fullScreenChanged);
}



componentDidUpdate(prevProps) {
const { k8sConfig, capabilitiesRegistry } = this.props;

Expand Down

0 comments on commit 6640f6f

Please sign in to comment.