Skip to content
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

style: remove help texts in other settings #14196

Merged
merged 7 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export const FormComponentConfig = ({
propertyKey={propertyKey}
defaultValue={properties[propertyKey].default}
key={propertyKey}
helpText={properties[propertyKey]?.description}
mlqn marked this conversation as resolved.
Show resolved Hide resolved
/>
);
})}
Expand All @@ -137,7 +136,6 @@ export const FormComponentConfig = ({
<>
<EditBooleanValue
propertyKey='hasCustomFileEndings'
helpText={hasCustomFileEndings.description}
component={component}
defaultValue={hasCustomFileEndings.default}
handleComponentChange={(updatedComponent: FormComponent) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import React from 'react';
import { Switch } from '@digdir/designsystemet-react';
import type { IGenericEditComponent } from '../componentConfig';
import { useText } from '../../../hooks';
import { useText, useComponentPropertyLabel, useComponentPropertyHelpText } from '../../../hooks';
import { FormField } from '../../FormField';
import { useComponentPropertyLabel } from '../../../hooks/useComponentPropertyLabel';

export interface EditBooleanValueProps extends IGenericEditComponent {
propertyKey: string;
helpText?: string;
defaultValue?: boolean;
}

export const EditBooleanValue = ({
component,
handleComponentChange,
propertyKey,
helpText,
defaultValue,
}: EditBooleanValueProps) => {
const t = useText();
const componentPropertyLabel = useComponentPropertyLabel();
const componentPropertyHelpText = useComponentPropertyHelpText();

const handleChange = () => {
handleComponentChange({
Expand All @@ -44,7 +42,7 @@ export const EditBooleanValue = ({
helpText={
isValueExpression(component[propertyKey])
? t('ux_editor.component_properties.config_is_expression_message')
: helpText
: componentPropertyHelpText(propertyKey)
}
renderField={({ fieldProps }) => {
return (
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/ux-editor/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export { useValidateComponent } from './useValidateComponent';
export { useComponentPropertyLabel } from './useComponentPropertyLabel';
export { useAppContext } from './useAppContext';
export { useGetLayoutSetByName } from './useGetLayoutSetByName';
export { useComponentPropertyHelpText } from './useComponentPropertyHelpText';
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { renderHook } from '@testing-library/react';
import { useComponentPropertyHelpText } from './useComponentPropertyHelpText';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { KeyValuePairs } from 'app-shared/types/KeyValuePairs';

const somePropertyName = 'undefinedKey';

const customTextMockToHandleUndefined = (
keys: string | string[],
variables?: KeyValuePairs<string>,
) => {
const key = Array.isArray(keys) ? keys[0] : keys;
if (key === `ux_editor.component_properties_help_text.${somePropertyName}`) return key;
return variables
? '[mockedText(' + key + ', ' + JSON.stringify(variables) + ')]'
: '[mockedText(' + key + ')]';
};

jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: customTextMockToHandleUndefined,
}),
}));

describe('useComponentPropertyHelpText', () => {
it('Returns a function that returns the help text', () => {
const result = renderHook(() => useComponentPropertyHelpText()).result.current;
const propertyHelpText = result('test');
expect(propertyHelpText).toEqual(textMock('ux_editor.component_properties_help_text.test'));
});

it('Returns a function that returns undefined if there was no text key for the help text', () => {
const result = renderHook(() => useComponentPropertyHelpText()).result.current;
const propertyHelpText = result(somePropertyName);
expect(propertyHelpText).toEqual(undefined);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useTranslation } from 'react-i18next';
import { useCallback } from 'react';

export const useComponentPropertyHelpText = () => {
const { t } = useTranslation();

return useCallback(
(propertyKey: string): string | undefined => {
const translationKey: string = `ux_editor.component_properties_help_text.${propertyKey}`;
const translation = t(translationKey);

return translation !== translationKey ? translation : undefined;
},
[t],
);
};
Loading