Skip to content

Commit

Permalink
fix: dependecnies sorting avoif recoil read only
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 25, 2020
1 parent 9a9c85a commit 5f454dc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
5 changes: 5 additions & 0 deletions core/core/src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,8 @@ export interface ImportName {
export interface Imports {
[key: string]: ImportName[];
}

/**
* default export keyword
*/
export const defaultExport = 'default';
16 changes: 14 additions & 2 deletions ui/blocks/src/ComponentDeps/BaseComponentDeps.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useMemo } from 'react';
import { StoryComponent } from '@component-controls/core';
import { StoryComponent, defaultExport } from '@component-controls/core';
import { usePackage } from '@component-controls/store';
import { Dependencies } from './Dependencies';

Expand Down Expand Up @@ -37,7 +37,19 @@ export const BaseComponentDeps: FC<BaseComponentDepsProps> = ({
));
return {
name,
imports: importObj[name],
imports: [...importObj[name]].sort((a, b) => {
if (a.importedName === defaultExport) {
return -1;
} else if (b.importedName === defaultExport) {
return 1;
}
if (a.importedName > b.importedName) {
return -1;
} else if (a.importedName < b.importedName) {
return 1;
}
return 0;
}),
packageName,
peer: packageName
? peerDependenciesKeys.includes(packageName)
Expand Down
39 changes: 11 additions & 28 deletions ui/blocks/src/ComponentDeps/Dependencies.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable react/display-name */
import React, { FC, useMemo } from 'react';
import { Flex, Box } from 'theme-ui';
import { ImportName } from '@component-controls/core';
import { ImportName, defaultExport } from '@component-controls/core';
import { Table, Tag, ExternalLink } from '@component-controls/components';

const defaultExport = 'default';
export interface Dependency {
/**
* import name (can include /dist/ folders)
Expand Down Expand Up @@ -72,32 +71,16 @@ export const Dependencies: FC<DependenciesProps> = ({ dependencies }) => {
flexWrap: 'wrap',
}}
>
{value
.sort((a, b) => {
if (a.importedName === defaultExport) {
return -1;
} else if (b.importedName === defaultExport) {
return 1;
}
if (a.importedName > b.importedName) {
return -1;
} else if (a.importedName < b.importedName) {
return 1;
}
return 0;
})
.map(v => (
<Tag
variant="tag.rightmargin"
key={`${v.name}`}
borderSize={1}
color={
v.importedName === defaultExport ? 'green' : 'lightgrey'
}
>
{v.importedName === defaultExport ? v.name : v.importedName}
</Tag>
))}
{value.map(v => (
<Tag
variant="tag.rightmargin"
key={`${v.name}`}
borderSize={1}
color={v.importedName === defaultExport ? 'green' : 'lightgrey'}
>
{v.importedName === defaultExport ? v.name : v.importedName}
</Tag>
))}
</Flex>
),
},
Expand Down

0 comments on commit 5f454dc

Please sign in to comment.