1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00

fix: run use effect when value changes, not object (#315)

* fix: run use effect when value changes, not object

* fix: add user to archived toggle view

* fix: remove console log
This commit is contained in:
Fredrik Strand Oseberg 2021-07-16 11:21:53 +02:00 committed by GitHub
parent f1a714e7e1
commit 1c2381d9a0
3 changed files with 24 additions and 5 deletions

View File

@ -11,7 +11,14 @@ import cloneDeep from 'lodash.clonedeep';
import styles from './form-addon-component.module.scss';
import PageContent from '../common/PageContent/PageContent';
const AddonFormComponent = ({ editMode, provider, addon, fetch, cancel, submit }) => {
const AddonFormComponent = ({
editMode,
provider,
addon,
fetch,
cancel,
submit,
}) => {
const [config, setConfig] = useState(addon);
const [errors, setErrors] = useState({
parameters: {},
@ -25,8 +32,10 @@ const AddonFormComponent = ({ editMode, provider, addon, fetch, cancel, submit }
}, [fetch, provider]); // empty array => fetch only first time
useEffect(() => {
console.log(addon);
setConfig({ ...addon });
}, [addon]);
/* eslint-disable-next-line */
}, [addon.description, addon.provider]);
useEffect(() => {
if (provider && !config.provider) {
@ -98,7 +107,11 @@ const AddonFormComponent = ({ editMode, provider, addon, fetch, cancel, submit }
}
};
const { name, description, documentationUrl = 'https://unleash.github.io/docs/addons' } = provider ? provider : {};
const {
name,
description,
documentationUrl = 'https://unleash.github.io/docs/addons',
} = provider ? provider : {};
return (
<PageContent headerContent={`Configure ${name} addon`}>
@ -121,7 +134,12 @@ const AddonFormComponent = ({ editMode, provider, addon, fetch, cancel, submit }
className={styles.nameInput}
/>
<FormControlLabel
control={<Switch checked={config.enabled} onChange={onEnabled} />}
control={
<Switch
checked={config.enabled}
onChange={onEnabled}
/>
}
label={config.enabled ? 'Enabled' : 'Disabled'}
/>
</section>

View File

@ -11,6 +11,7 @@ export default connect(
.toArray()
.find(toggle => toggle.name === props.featureToggleName),
tagTypes: state.tagTypes.toJS(),
user: state.user.toJS(),
featureTags: state.featureTags.toJS(),
activeTab: props.activeTab,
}),

View File

@ -166,7 +166,7 @@ export default class MetricComponent extends React.Component {
</Grid>
</Grid>
<hr />
<StrategiesList strategies={featureToggle.strategies} />
<StrategiesList strategies={featureToggle.strategies || []} />
</div>
);
}