Skip to content

Commit

Permalink
[BACKPORT 2.12][PLAT-5193] - Master flag lists shows incorrect defaul…
Browse files Browse the repository at this point in the history
…t value

Summary:
Handled for different metadata versions

Show default values when current value does not exist ( For < 2.8 branch )
Show current value ( For > 2.12 branch)

Test Plan: Tested Manually

Reviewers: ssutar, cpadinjareveettil, asathyan, kkannan

Reviewed By: asathyan, kkannan

Subscribers: jenkins-bot, ui, yugaware

Differential Revision: https://phabricator.dev.yugabyte.com/D19135
  • Loading branch information
Lingeshwar committed Aug 24, 2022
1 parent 52f9fc8 commit 200731c
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions managed/ui/src/components/universes/UniverseForm/AddGFlag.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ const AddGFlag = ({ formProps, gFlagProps }) => {

const handleFlagSelect = (flag) => {
let flagvalue = null;
const defaultKey = flag?.hasOwnProperty('current') ? 'current' : 'default'; // Guard condition to handle inconstintency in gflag metadata
if (flag?.type === 'bool')
if (['false', false].includes(flag?.default)) flagvalue = false;
if (['false', false].includes(flag[defaultKey])) flagvalue = false;
else flagvalue = true;
else if (!['bool', 'string'].includes(flag?.type)) flagvalue = Number(flag?.default);
else flagvalue = flag?.default;
else if (!['bool', 'string'].includes(flag?.type)) flagvalue = Number(flag[defaultKey]);
else flagvalue = flag[defaultKey];
setSelectedFlag(flag);
formProps.setValues({
...gFlagProps,
Expand Down Expand Up @@ -70,12 +71,13 @@ const AddGFlag = ({ formProps, gFlagProps }) => {
setMostUsedFlags([flag?.data]);
setFilteredArr([flag?.data]);
setSelectedFlag(flag?.data);
if (flagvalue === undefined)
if (flagvalue === undefined) {
const defaultKey = flag?.data?.hasOwnProperty('current') ? 'current' : 'default';
formProps.setValues({
...gFlagProps,
flagvalue: flag?.data?.default
flagvalue: flag?.data[defaultKey]
});
else formProps.setValues(gFlagProps);
} else formProps.setValues(gFlagProps);
setLoader(false);
} catch (e) {
setAPIError(e?.error);
Expand Down Expand Up @@ -136,6 +138,7 @@ const AddGFlag = ({ formProps, gFlagProps }) => {

//renderers
const renderFormComponent = (flag) => {
const defaultKey = selectedFlag?.hasOwnProperty('current') ? 'current' : 'default';
switch (flag?.type) {
case 'bool':
return (
Expand All @@ -154,7 +157,7 @@ const AddGFlag = ({ formProps, gFlagProps }) => {
/>{' '}
{`${target}`}{' '}
<span className="default-text">
{[target, `${target}`].includes(selectedFlag?.default) ? '(Default)' : ''}
{[target, `${target}`].includes(selectedFlag[defaultKey]) ? '(Default)' : ''}
</span>
</span>
))}
Expand Down Expand Up @@ -244,7 +247,8 @@ const AddGFlag = ({ formProps, gFlagProps }) => {

const renderFlagDetails = () => {
const showDocLink = mode !== EDIT && (toggleMostUsed || isMostUsed(selectedFlag?.name));
if (selectedFlag)
if (selectedFlag) {
const defaultKey = selectedFlag?.hasOwnProperty('current') ? 'current' : 'default';
return (
<>
<div className="gflag-detail-container">
Expand All @@ -253,10 +257,10 @@ const AddGFlag = ({ formProps, gFlagProps }) => {
{renderFieldInfo('Description', selectedFlag?.meaning)}
<div className="gflag-detail-value">
<FlexContainer direction="column">
{selectedFlag?.default && (
{selectedFlag[defaultKey] && (
<>
<span className="gflag-description-title">Default Value</span>
<Badge className="gflag-badge">{selectedFlag?.default}</Badge>
<Badge className="gflag-badge">{selectedFlag[defaultKey]}</Badge>
</>
)}
{showDocLink && documentationLink}
Expand All @@ -267,7 +271,7 @@ const AddGFlag = ({ formProps, gFlagProps }) => {
<div className="gflag-form">{renderFormComponent(selectedFlag)}</div>
</>
);
else return infoText;
} else return infoText;
};

return (
Expand Down

0 comments on commit 200731c

Please sign in to comment.