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

2837 20 unable to create variable collections from sets #2844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
757e3a4
feat: add token format option to get exact resolved value
robinhoodie0823 Apr 12, 2024
64f7b9d
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Apr 15, 2024
f2d07fa
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Apr 16, 2024
9dc89e0
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Apr 16, 2024
0cffbfd
revert the DTCG format
robinhoodie0823 Apr 16, 2024
912f318
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Apr 18, 2024
6193450
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Apr 19, 2024
6088f3e
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Apr 24, 2024
493c938
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Apr 29, 2024
3ccab01
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Apr 29, 2024
1a05a7e
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Apr 30, 2024
9e63e5c
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 1, 2024
92e52b8
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 1, 2024
7a40c4a
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 3, 2024
b425dbb
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 6, 2024
b04d373
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 8, 2024
dce0e98
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 13, 2024
b9c6fef
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 13, 2024
def9936
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 16, 2024
4fadfb8
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 21, 2024
0e1b690
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 23, 2024
2057bbb
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 26, 2024
50e0794
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 30, 2024
473befc
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 May 30, 2024
f414eaa
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Jun 3, 2024
31361df
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Jun 4, 2024
1391624
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Jun 6, 2024
586c6b1
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Jun 8, 2024
44ea5d1
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Jun 10, 2024
9aba90f
Merge branch 'release-139' of https://github.com/tokens-studio/figma-…
robinhoodie0823 Jun 10, 2024
755fbd7
feat: add console logs to figure out issue
robinhoodie0823 Jun 11, 2024
adfbd44
feat: add logic to create collection based on selected sets
robinhoodie0823 Jun 12, 2024
f743f4a
feat: update to create all tokens as variables
robinhoodie0823 Jun 12, 2024
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
@@ -0,0 +1,64 @@
import { mockCreateVariableCollection, mockGetLocalVariableCollections } from '../../tests/__mocks__/figmaMock';
import { TokenSetStatus } from '@/constants/TokenSetStatus';
import { TokenTypes } from '@/constants/TokenTypes';
import createLocalVariablesWithoutModesInPlugin from './createLocalVariablesWithoutModesInPlugin';
import { SingleToken } from '@/types/tokens';
import { SettingsState } from '@/app/store/models/settings';

describe('createLocalVariablesWithoutModesInPlugin', () => {
const mockRenameMode = jest.fn();

const tokens = {
global: [
{
name: 'button.primary.borderRadius',
value: '8',
type: TokenTypes.BORDER_RADIUS,
} as SingleToken,
{
name: 'button.primary.width',
value: '16',
type: TokenTypes.SIZING,
} as SingleToken,
],
};
const settings = {
baseFontSize: '16',
} as SettingsState;

it('when there is no collection which correspond to the theme, then we create a new collection', async () => {
const mockLocalVariableCollections = [
{
id: 'VariableCollectionId:334:16746',
modes: [
{
name: 'light',
modeId: '123',
},
],
name: 'core',
},
];
const mockNewCollection = {
id: 'VariableCollectionId:334:16723',
modes: [
{
name: 'new Mode',
modeId: '123',
},
],
name: 'color',
renameMode: mockRenameMode,
} as unknown as VariableCollection;
mockGetLocalVariableCollections.mockImplementationOnce(() => mockLocalVariableCollections);
mockCreateVariableCollection.mockImplementationOnce(() => mockNewCollection);
const selectedSets = [{
set: 'global',
status: TokenSetStatus.ENABLED,
}]
expect(await createLocalVariablesWithoutModesInPlugin(tokens, settings, selectedSets)).toEqual({
allVariableCollectionIds: {},
totalVariables: 0,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ export default async function createLocalVariablesWithoutModesInPlugin(tokens: R

const checkSetting = !settings.variablesBoolean && !settings.variablesColor && !settings.variablesNumber && !settings.variablesString;
if (!checkSetting) {
const themesToCreateCollections = selectedSets.reduce((acc: ThemeObject[], curr: ExportTokenSet) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you not be able to re-use the themeContainer const on line 45 for this? I think thats what it was intended for?

if (curr.status === TokenSetStatus.ENABLED) {
acc.push({
selectedTokenSets: {
[curr.set]: curr.status,
},
id: curr.set,
name: curr.set
})
}
return acc;
}, [] as ThemeObject[]);
const themeContainer = selectedSets.reduce((acc: ThemeObject, curr: ExportTokenSet) => {
acc.selectedTokenSets = {
...acc.selectedTokenSets,
Expand All @@ -39,12 +51,19 @@ export default async function createLocalVariablesWithoutModesInPlugin(tokens: R
}, {} as ThemeObject);
const selectedSetIds = selectedSets.map((set) => set.set);

const collections = await createNecessaryVariableCollections([themeContainer], selectedSetIds);
const collections = await createNecessaryVariableCollections(themesToCreateCollections, selectedSetIds);

const sourceSets = selectedSets.filter((t) => t.status === TokenSetStatus.SOURCE);
const sourceTokenSets = sourceSets.reduce((acc, curr) => {
acc[curr.set] = tokens[curr.set];
return acc;
}, {});

await Promise.all(selectedSets.map(async (set: ExportTokenSet, index) => {
if (set.status === TokenSetStatus.ENABLED) {
const setTokens: Record<string, AnyTokenList> = {
[set.set]: tokens[set.set],
...sourceTokenSets,
[set.set]: tokens[set.set]
};
const { collection, modeId } = findCollectionAndModeIdForTheme(set.set, set.set, collections);

Expand Down
Loading