Skip to content

Commit

Permalink
refactor: I have moved some of my code and added the component to the…
Browse files Browse the repository at this point in the history
… storybook

I have also deleted some of my unneeded code #1994
  • Loading branch information
franpb14 authored and julianguyen committed Feb 19, 2024
1 parent 1dfe7cc commit d985808
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 32 deletions.
47 changes: 23 additions & 24 deletions app/helpers/moments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,6 @@ def hash_for_multiselect
{ options: options_for_multiselect, filters: filters_of_multiselect }
end

def filters_of_multiselect
['secret_share_identifier IS NOT NULL', { viewers: [] },
'length(viewers) > 0', { comment: true },
{ published_at: nil }, 'published_at IS NOT NULL']
end

def options_for_multiselect
options = [t('moments.filters.secret_share'),
t('moments.filters.no_viewers'),
t('moments.filters.one_viewer'),
t('moments.filters.coments_enabled'),
t('moments.filters.draft_enabled'),
t('moments.filters.published')]
options_hash = []
options.each_with_index do |element, index|
options_hash.push({
id: element,
label: element,
value: index
})
end
options_hash
end

private

def element_actions(element, present_object)
Expand Down Expand Up @@ -169,5 +145,28 @@ def get_share_link_info(is_strategy, element)
return if is_strategy || element.secret_share_identifier.blank?

t('moments.secret_share.link_info')

def filters_of_multiselect
['secret_share_identifier IS NOT NULL', { viewers: [] },
'length(viewers) > 0', { comment: true },
{ published_at: nil }, 'published_at IS NOT NULL']
end

def options_for_multiselect
options = [t('moments.filters.secret_share'),
t('moments.filters.no_viewers'),
t('moments.filters.one_viewer'),
t('moments.filters.coments_enabled'),
t('moments.filters.draft_enabled'),
t('moments.filters.published')]
options_hash = []
options.each_with_index do |element, index|
options_hash.push({
id: element,
label: element,
value: index
})
end
options_hash
end
end
1 change: 0 additions & 1 deletion client/app/components/Input/InputMultiSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type Props = {
ariaLabel?: string,
label?: string,
value?: any,
onChange?: Function,
};

export function InputMultiSelect({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('InputMultiSelect', () => {
ariaLabel={ariaLabel}
value={value}
options={options}
onChange={someEvent}
/>,
);
const multiSelect = screen.getByRole('button', { className: 'buttonL' });
Expand All @@ -42,7 +41,6 @@ describe('InputMultiSelect', () => {
id={id}
ariaLabel={ariaLabel}
options={options}
onChange={someEvent}
/>,
);
// toggle the first value
Expand Down
1 change: 0 additions & 1 deletion client/app/components/Input/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export const Input = ({
label={label}
value={value}
options={options}
onChange={onChange}
/>
);
}
Expand Down
10 changes: 10 additions & 0 deletions client/app/mocks/InputMocks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ const inputSelectProps = {
options,
};

const inputMultiSelectProps = {
type: 'multi_select',
ariaLabel: 'some-select-label',
id: 'some-select-id',
label: 'some-select-arialabel',
name: 'some-select-label',
options,
};

const inputRadioProps = {
id: 'some-radio-id',
type: 'radio',
Expand Down Expand Up @@ -146,6 +155,7 @@ export const InputMocks = {
inputTextareaProps,
inputTextareaTemplateProps,
inputSelectProps,
inputMultiSelectProps,
inputRadioProps,
inputCheckboxProps,
inputCheckboxGroupProps,
Expand Down
10 changes: 6 additions & 4 deletions client/app/stories/Input.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,13 @@ const SelectTemplate = (args) => (
</>
);

export const Select = SelectTemplate.bind({});
export const MultiSelect = () => (
<>
{InputMocks.createInput(InputMocks.inputMultiSelectProps)}
</>
);

const SelectWithAccordionTemplate = (args) => (
export const SelectWithAccordion = () => (
<>
{InputMocks.createInput(InputMocks.inputSelectProps, {
onChange: InputMocks.event,
Expand Down Expand Up @@ -372,8 +376,6 @@ const SelectWithAccordionTemplate = (args) => (
</>
);

export const SelectWithAccordion = SelectWithAccordionTemplate.bind({});

SelectWithAccordion.storyName = 'Select with accordion';

const TagTemplate = (args) => (
Expand Down

0 comments on commit d985808

Please sign in to comment.