Skip to content

Commit

Permalink
WRS-2228 old studio ff cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-mereuta committed Jan 21, 2025
1 parent df00681 commit 9b06f06
Show file tree
Hide file tree
Showing 16 changed files with 13 additions and 122 deletions.
1 change: 0 additions & 1 deletion src/_dev-execution/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ import { TokenManager } from './token-manager';
},
},
featureFlags: {
STUDIO_LABEL_PROPERTY_ENABLED: true,
STUDIO_DATA_SOURCE: true,
},
});
Expand Down
6 changes: 1 addition & 5 deletions src/components/variablesComponents/BooleanVariable.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { InputLabel, Switch } from '@chili-publish/grafx-shared-components';
import type { BooleanVariable } from '@chili-publish/studio-sdk';
import { useEffect, useState } from 'react';
import { useFeatureFlagContext } from '../../contexts/FeatureFlagProvider';
import { getDataIdForSUI, getDataTestIdForSUI } from '../../utils/dataIds';
import { BooleanVariableContainer, HelpTextWrapper } from './VariablesComponents.styles';
import { IBooleanVariable } from './VariablesComponents.types';

function BooleanVariable(props: IBooleanVariable) {
const { variable, handleValueChange } = props;
const { featureFlags } = useFeatureFlagContext();
const [toggled, setToggled] = useState((variable as BooleanVariable).value);

useEffect(() => {
Expand All @@ -25,9 +23,7 @@ function BooleanVariable(props: IBooleanVariable) {
id={`ui-${variable.id}`}
label={{
key: 'visible',
value: featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED
? variable.label ?? variable.name
: variable.name,
value: variable.label ?? variable.name,
}}
onChange={(val: boolean) => {
handleValueChange(val);
Expand Down
15 changes: 1 addition & 14 deletions src/components/variablesComponents/NumberVariable.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Input, InputLabel, Label, ValidationTypes } from '@chili-publish/grafx-shared-components';
import { ChangeEvent } from 'react';
import { useFeatureFlagContext } from '../../contexts/FeatureFlagProvider';
import { getDataIdForSUI, getDataTestIdForSUI } from '../../utils/dataIds';
import { HelpTextWrapper } from './VariablesComponents.styles';
import { INumberVariable } from './VariablesComponents.types';

function NumberVariable(props: INumberVariable) {
const { variable, validationError, onValueChange } = props;
const { featureFlags } = useFeatureFlagContext();

return (
<HelpTextWrapper>
Expand All @@ -18,18 +16,7 @@ function NumberVariable(props: INumberVariable) {
max={variable.maxValue}
precision={variable.numberOfDecimals}
label={
<Label
translationKey={
featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED
? variable.label ?? variable.name
: variable.name
}
value={
featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED
? variable.label ?? variable.name
: variable.name
}
/>
<Label translationKey={variable.label ?? variable.name} value={variable.label ?? variable.name} />
}
value={`${variable.value}`}
step={variable.showStepper ? variable.stepSize : undefined}
Expand Down
15 changes: 1 addition & 14 deletions src/components/variablesComponents/TextVariable.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Input, InputLabel, Label, ValidationTypes } from '@chili-publish/grafx-shared-components';
import { LongTextVariable, ShortTextVariable } from '@chili-publish/studio-sdk';
import React, { ChangeEvent, useEffect, useState } from 'react';
import { useFeatureFlagContext } from '../../contexts/FeatureFlagProvider';
import { getDataIdForSUI, getDataTestIdForSUI } from '../../utils/dataIds';
import { HelpTextWrapper } from './VariablesComponents.styles';
import { ITextVariable } from './VariablesComponents.types';
import { getVariablePlaceholder } from './variablePlaceholder.util';

function TextVariable(props: ITextVariable) {
const { variable, validationError, onValueChange } = props;
const { featureFlags } = useFeatureFlagContext();

const [variableValue, setVariableValue] = useState(
(variable as ShortTextVariable).value || (variable as LongTextVariable).value,
Expand Down Expand Up @@ -42,18 +40,7 @@ function TextVariable(props: ITextVariable) {
}}
name={variable.id}
label={
<Label
translationKey={
featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED
? variable.label ?? variable.name
: variable.name
}
value={
featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED
? variable.label ?? variable.name
: variable.name
}
/>
<Label translationKey={variable.label ?? variable.name} value={variable.label ?? variable.name} />
}
validation={validationError ? ValidationTypes.ERROR : undefined}
validationErrorMessage={validationError}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DatePicker, InputLabel, useMobileSize } from '@chili-publish/grafx-shared-components';
import { useMemo } from 'react';
import { useFeatureFlagContext } from '../../../contexts/FeatureFlagProvider';
import { APP_WRAPPER_ID } from '../../../utils/constants';
import { getDataIdForSUI, getDataTestIdForSUI } from '../../../utils/dataIds';
import useDateVariable from '../useDateVariable';
Expand All @@ -21,7 +20,6 @@ function DateVariable(props: IDateVariable) {
onBlur,
} = props;

const { featureFlags } = useFeatureFlagContext();
const { minDate, maxDate } = useDateVariable(variable);
const isMobileSize = useMobileSize();

Expand All @@ -42,8 +40,8 @@ function DateVariable(props: IDateVariable) {

const variableLabel = useMemo(() => {
if (isOpenOnMobile) return '';
return featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED ? variable.label ?? variable.name : variable.name;
}, [featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED, isOpenOnMobile, variable.label, variable.name]);
return variable.label ?? variable.name;
}, [isOpenOnMobile, variable.label, variable.name]);

return (
<HelpTextWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ImagePicker, InputLabel, Label } from '@chili-publish/grafx-shared-components';
import { useMemo } from 'react';
import { useFeatureFlagContext } from '../../../contexts/FeatureFlagProvider';
import { useVariablePanelContext } from '../../../contexts/VariablePanelContext';
import { isAuthenticationRequired, verifyAuthentication } from '../../../utils/connectors';
import { getDataIdForSUI, getDataTestIdForSUI } from '../../../utils/dataIds';
Expand All @@ -13,7 +12,6 @@ import { useVariableConnector } from './useVariableConnector';

function ImageVariable(props: IImageVariable) {
const { variable, validationError, handleImageRemove } = props;
const { featureFlags } = useFeatureFlagContext();

const placeholder = getVariablePlaceholder(variable);

Expand Down Expand Up @@ -48,18 +46,7 @@ function ImageVariable(props: IImageVariable) {
dataIntercomId={`image-picker-${variable.name}`}
id={variable.id}
label={
<Label
translationKey={
featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED
? variable.label ?? variable.name
: variable.name
}
value={
featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED
? variable.label ?? variable.name
: variable.name
}
/>
<Label translationKey={variable.label ?? variable.name} value={variable.label ?? variable.name} />
}
required={variable.isRequired}
placeholder={placeholder}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InputLabel, SelectOptions } from '@chili-publish/grafx-shared-components';
import { useFeatureFlagContext } from '../../../contexts/FeatureFlagProvider';
import StudioDropdown from '../../shared/StudioDropdown';
import { ComponentWrapper } from '../../variables/VariablesPanel.styles';
import { getVariablePlaceholder } from '../variablePlaceholder.util';
Expand All @@ -8,7 +7,6 @@ import { IListVariable } from '../VariablesComponents.types';

function ListVariable(props: IListVariable) {
const { variable, validationError, onChange } = props;
const { featureFlags } = useFeatureFlagContext();

const options = variable.items.map((item) => ({
label: item.displayValue || item.value,
Expand Down Expand Up @@ -36,11 +34,7 @@ function ListVariable(props: IListVariable) {
<div>
<StudioDropdown
dataId={variable.id}
label={
featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED
? variable.label ?? variable.name
: variable.name
}
label={variable.label ?? variable.name}
selectedValue={selectedValue || ''}
options={options}
placeholder={placeholder}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SelectOptions } from '@chili-publish/grafx-shared-components';
import { ListVariable } from '@chili-publish/studio-sdk/lib/src/next';

import { useFeatureFlagContext } from '../../../contexts/FeatureFlagProvider';
import { getVariablePlaceholder } from '../variablePlaceholder.util';
import StudioMobileDropdown from '../../shared/StudioMobileDropdown/StudioMobileDropdown';
import { getDataIdForSUI } from '../../../utils/dataIds';
Expand All @@ -25,7 +24,6 @@ function MobileListVariable({
onMenuClose,
onItemSelected,
}: MobileListVariableProps) {
const { featureFlags } = useFeatureFlagContext();
const options = variable.items.map((item) => ({
label: item.displayValue || item.value,
value: item.value,
Expand All @@ -47,7 +45,7 @@ function MobileListVariable({
<StudioMobileDropdown
dataId={getDataIdForSUI(`variable-list-${variable.id}`)}
isOpen={isOpen}
label={featureFlags?.STUDIO_LABEL_PROPERTY_ENABLED ? variable.label ?? variable.name : variable.name}
label={variable.label ?? variable.name}
selectedValue={selectedValue}
options={options}
placeholder={placeholder}
Expand Down
6 changes: 0 additions & 6 deletions src/tests/VariablesComponents.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import userEvent from '@testing-library/user-event';
import { act } from 'react-dom/test-utils';
import VariableComponent from '../components/variablesComponents/VariablesComponents';
import AppProvider from '../contexts/AppProvider';
import * as FeatureFlagContext from '../contexts/FeatureFlagProvider';
import { variables } from './mocks/mockVariables';
import { APP_WRAPPER } from './shared.util/app';

Expand All @@ -24,11 +23,6 @@ Object.defineProperty(navigator, 'language', {
configurable: true,
});

jest.spyOn(FeatureFlagContext, 'useFeatureFlagContext').mockImplementation(() => {
return {
featureFlags: { STUDIO_LABEL_PROPERTY_ENABLED: true },
};
});
describe('Variable Component', () => {
beforeEach(() => {
window.StudioUISDK.connector.getMappings = jest.fn().mockResolvedValue({
Expand Down
11 changes: 5 additions & 6 deletions src/tests/VariablesList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ describe('Variables List', () => {
{ container: document.body.appendChild(APP_WRAPPER) },
);

const variable1 = await screen.findByText(variables[0].name);
const variable12 = await screen.findByText(variables[1].name);
const shortVariable1 = screen.getByText(variables[2].name);
const longVariable1 = screen.queryByText(variables[3].name);
const variable1 = await screen.findByText(variables[0].label ?? variables[0].name);
const variable12 = await screen.findByText(variables[1].label ?? variables[1].name);
const shortVariable1 = screen.getByText(variables[2].label ?? variables[2].name);
const longVariable1 = screen.queryByText(variables[3].label ?? variables[3].name);

expect(variable1).toBeInTheDocument();
expect(variable12).toBeInTheDocument();
Expand All @@ -64,13 +64,12 @@ describe('Variables List', () => {
'grafx-select__dropdown-indicator',
)[0];
expect(selectIndicator).toBeInTheDocument();

act(() => {
selectEvent.openMenu(selectIndicator as unknown as HTMLElement);
});

await waitFor(() => {
expect(screen.getByText('List')).toBeInTheDocument();
expect(screen.getByText('List label')).toBeInTheDocument();
expect(screen.getByText('Val 1')).toBeInTheDocument();
expect(screen.getByText('val 2')).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { render, screen } from '@testing-library/react';
import { variables } from '@tests/mocks/mockVariables';
import BooleanVariable from '../../../../components/variablesComponents/BooleanVariable';

jest.mock('../../../../contexts/FeatureFlagProvider', () => ({
useFeatureFlagContext: () => ({
featureFlags: {
STUDIO_LABEL_PROPERTY_ENABLED: true,
},
}),
}));

describe('BooleanVariable', () => {
it('should display label as variable label if label is empty', () => {
const booleanVar = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import DateVariable from '../../../../components/variablesComponents/dateVariabl
import { APP_WRAPPER_ID } from '../../../../utils/constants';
import { APP_WRAPPER } from '../../../shared.util/app';

jest.mock('../../../../contexts/FeatureFlagProvider', () => ({
useFeatureFlagContext: () => ({
featureFlags: {
STUDIO_LABEL_PROPERTY_ENABLED: true,
},
}),
}));

describe('DateVariable', () => {
it('should display the configured placeholder', async () => {
const PLACEHOLDER = 'placeholder text';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ jest.mock('@chili-publish/grafx-shared-components', () => {
};
});

jest.mock('../../../../contexts/FeatureFlagProvider', () => ({
useFeatureFlagContext: () => ({
featureFlags: {
STUDIO_LABEL_PROPERTY_ENABLED: true,
},
}),
}));

describe('"ImageVariable" component ', () => {
afterEach(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { render, screen } from '@testing-library/react';
import { variables } from '@tests/mocks/mockVariables';
import ListVariable from '../../../../components/variablesComponents/listVariable/ListVariable';

jest.mock('../../../../contexts/FeatureFlagProvider', () => ({
useFeatureFlagContext: () => ({
featureFlags: {
STUDIO_LABEL_PROPERTY_ENABLED: true,
},
}),
}));

describe('ListVariable', () => {
it('should display label as variable name if label is empty', () => {
const variable = variables.find((item) => item.id === '10');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { render, screen } from '@testing-library/react';
import { variables } from '@tests/mocks/mockVariables';
import NumberVariable from '../../../../components/variablesComponents/NumberVariable';

jest.mock('../../../../contexts/FeatureFlagProvider', () => ({
useFeatureFlagContext: () => ({
featureFlags: {
STUDIO_LABEL_PROPERTY_ENABLED: true,
},
}),
}));

describe('NumberVariable', () => {
it('should display label as variable label if label exists and empty', () => {
const variable = variables.find((item) => item.id === 'number-variable');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { render, screen } from '@testing-library/react';
import { variables } from '@tests/mocks/mockVariables';
import TextVariable from '../../../../components/variablesComponents/TextVariable';

jest.mock('../../../../contexts/FeatureFlagProvider', () => ({
useFeatureFlagContext: () => ({
featureFlags: {
STUDIO_LABEL_PROPERTY_ENABLED: true,
},
}),
}));

describe('TextVariable', () => {
it('should display the configured placeholder', () => {
const PLACEHOLDER = 'placeholder text';
Expand Down

0 comments on commit 9b06f06

Please sign in to comment.