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

Fix change sets zero padding #3162

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
@@ -1,7 +1,5 @@
import { FileDirectoryIcon } from '@primer/octicons-react';
import {
Tabs, Stack, Heading, Button,
} from '@tokens-studio/ui';
import { Tabs, Stack, Heading, Button } from '@tokens-studio/ui';
import React, { useMemo } from 'react';
import { useDispatch, useSelector, useStore } from 'react-redux';
import { useForm, Controller } from 'react-hook-form';
Expand All @@ -24,7 +22,13 @@
import { TokenSetStatus } from '@/constants/TokenSetStatus';
import { ExportTokenSet } from '@/types/ExportTokenSet';

export default function ExportSetsTab({ selectedSets, setSelectedSets }: { selectedSets: ExportTokenSet[], setSelectedSets: (sets: ExportTokenSet[]) => void }) {
export default function ExportSetsTab({
selectedSets,
setSelectedSets,
}: {
selectedSets: ExportTokenSet[];
setSelectedSets: (sets: ExportTokenSet[]) => void;
}) {
const dispatch = useDispatch<Dispatch>();
const closeOnboarding = React.useCallback(() => {
dispatch.uiState.setOnboardingExplainerExportSets(false);
Expand All @@ -35,13 +39,9 @@

const store = useStore<RootState>();

const selectedTokenSets = React.useMemo(() => (
usedTokenSetSelector(store.getState())
), [store]);
const selectedTokenSets = React.useMemo(() => usedTokenSetSelector(store.getState()), [store]);

const {
control, getValues, reset,
} = useForm<FormValues>({
const { control, getValues, reset } = useForm<FormValues>({
defaultValues: {
tokenSets: { ...selectedTokenSets },
},
Expand Down Expand Up @@ -70,37 +70,40 @@
setPreviousSetSelection(getValues());
}, [getValues]);

const TokenSetThemeItemInput = React.useCallback((props: React.PropsWithChildren<{ item: TreeItem }>) => (
<Controller
name="tokenSets"
control={control}
// this is the only way to do this
// eslint-disable-next-line
render={({ field }) => (
<TokenSetThemeItem
{...props}
value={field.value}
onChange={field.onChange}
/>
)}
/>
), [control]);

const selectedEnabledSets = useMemo(() => selectedSets.filter((set) => set.status === TokenSetStatus.ENABLED), [selectedSets]);
const TokenSetThemeItemInput = React.useCallback(
(props: React.PropsWithChildren<{ item: TreeItem }>) => (
<Controller
name="tokenSets"
control={control}
// this is the only way to do this
// eslint-disable-next-line
render={({ field }) => <TokenSetThemeItem {...props} value={field.value} onChange={field.onChange} />}

Check failure

Code scanning / ESLint

Disallow `.bind()` or arrow functions in JSX props Error

JSX props should not use arrow functions
/>
),
[control],
);

const selectedEnabledSets = useMemo(
() => selectedSets.filter((set) => set.status === TokenSetStatus.ENABLED),
[selectedSets],
);

React.useEffect(() => {
if (!showChangeSets) {
const currentSelectedSets = getValues();
const internalSelectedTokenSets: ExportTokenSet[] = Object.keys(currentSelectedSets.tokenSets).reduce((acc: ExportTokenSet[], curr: string) => {
if (currentSelectedSets.tokenSets[curr] !== TokenSetStatus.DISABLED) {
const tokenSet = {
set: curr,
status: currentSelectedSets.tokenSets[curr],
} as ExportTokenSet;
acc.push(tokenSet);
}
return acc;
}, [] as ExportTokenSet[]);
const internalSelectedTokenSets: ExportTokenSet[] = Object.keys(currentSelectedSets.tokenSets).reduce(
(acc: ExportTokenSet[], curr: string) => {
if (currentSelectedSets.tokenSets[curr] !== TokenSetStatus.DISABLED) {
const tokenSet = {
set: curr,
status: currentSelectedSets.tokenSets[curr],
} as ExportTokenSet;
acc.push(tokenSet);
}
return acc;
},
[] as ExportTokenSet[],
);
setSelectedSets([...internalSelectedTokenSets]);
}
}, [showChangeSets, getValues, setSelectedSets]);
Expand Down Expand Up @@ -134,23 +137,22 @@
<span>
{selectedEnabledSets.length}
{' of '}
{allSets.length}
{' '}
{t('exportSetsTab.setsSelectedForExport')}
{allSets.length} {t('exportSetsTab.setsSelectedForExport')}
</span>
</Stack>
<Button variant="secondary" size="small" onClick={handleShowChangeSets}>{t('actions.changeSets')}</Button>
<Button variant="secondary" size="small" onClick={handleShowChangeSets}>
{t('actions.changeSets')}
</Button>
</Stack>
</StyledCard>
<Modal
size="fullscreen"
full
compact
isOpen={showChangeSets}
close={handleCancelChangeSets}
backArrow
title="Styles and Variables / Export Sets"
footer={(
footer={
<Stack direction="row" gap={4} justify="between">
<Button variant="secondary" onClick={handleCancelChangeSets}>
{t('actions.cancel')}
Expand All @@ -159,11 +161,9 @@
{t('actions.confirm')}
</Button>
</Stack>
)}
}
>
<Heading>
{t('exportSetsTab.changeSetsHeading')}
</Heading>
<Heading>{t('exportSetsTab.changeSetsHeading')}</Heading>
{/* Commenting until we have docs <Link target="_blank" href={docsLinks.sets}>{`${t('generic.learnMore')} – ${t('docs.referenceOnlyMode')}`}</Link> */}
<Stack
direction="column"
Expand Down
Loading