-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: categories for Icons added #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
import React, { ChangeEvent, FC } from 'react'; | ||
import { Select, TextField } from '@salutejs/plasma-web'; | ||
import { TextField } from '@salutejs/plasma-web'; | ||
|
||
import { Input } from '../input/Input'; | ||
import type { IconPayload, SelectItem } from '../../../types'; | ||
import type { IconPayload } from '../../../types'; | ||
import { IconPreview } from '../iconPreview/IconPreview'; | ||
|
||
import { StyledFirstBlock, StyledIconItem, StyledSecondBlock } from './IconItem.style'; | ||
|
||
interface IconItemProps { | ||
name: string; | ||
item: IconPayload; | ||
category: string; | ||
categories: SelectItem[]; | ||
onChangeInput: (event: ChangeEvent<HTMLInputElement>) => void; | ||
} | ||
|
||
export const IconItem: FC<IconItemProps> = ({ name, item, category, categories, onChangeInput }) => ( | ||
<StyledIconItem> | ||
<StyledFirstBlock> | ||
<Input label="Svg" content={<IconPreview svg={item.svg} />} /> | ||
<Input label="Size" content={<TextField readOnly value={item.size} />} /> | ||
</StyledFirstBlock> | ||
<StyledSecondBlock> | ||
<Input label="Name" content={<TextField name={name} value={item.name} onChange={onChangeInput} />} /> | ||
<Input label="Category" content={<Select value={category} items={categories} />} /> | ||
</StyledSecondBlock> | ||
</StyledIconItem> | ||
); | ||
export const IconItem: FC<IconItemProps> = ({ name, item, onChangeInput }) => { | ||
return ( | ||
<StyledIconItem> | ||
<StyledFirstBlock> | ||
<Input label="Svg" content={<IconPreview svg={item.svg} />} /> | ||
<Input label="Size" content={<TextField readOnly value={item.size} />} /> | ||
</StyledFirstBlock> | ||
<StyledSecondBlock> | ||
<Input label="Name" content={<TextField name={name} value={item.name} onChange={onChangeInput} />} /> | ||
<Input label="Category" content={<TextField readOnly value={item.category} />} /> | ||
</StyledSecondBlock> | ||
</StyledIconItem> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,11 @@ interface CreatPR { | |
token?: string; | ||
} | ||
|
||
const saveMetaData = (octokit: Octokit, owner: string, repo: string) => <T>(fn: (...args: any[]) => Promise<T>) => ( | ||
...args: any[] | ||
) => fn(octokit, owner, repo, ...args); | ||
const saveMetaData = | ||
(octokit: Octokit, owner: string, repo: string) => | ||
<T>(fn: (...args: any[]) => Promise<T>) => | ||
(...args: any[]) => | ||
fn(octokit, owner, repo, ...args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а здесь что-то поменялось? Не могу найти разницу кроме переноса строк There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. видимо просто eslint |
||
|
||
/** | ||
* Хук для запуска процесса создания пул реквеста в GitHub. Возвращает: | ||
|
@@ -44,7 +46,7 @@ export const useRunGithubPRProcess = ({ owner, repo, branchName }: RunProcessGit | |
|
||
const withMetaData = saveMetaData(octokit, owner, repo); | ||
|
||
if (branchName !== 'master') { | ||
if (branchName !== 'master' && branchName !== 'dev') { | ||
setStep(0); | ||
await withMetaData(createBranch)(branchName); | ||
} | ||
|
@@ -66,7 +68,7 @@ export const useRunGithubPRProcess = ({ owner, repo, branchName }: RunProcessGit | |
await withMetaData(updateCommit)(branchName, newCommitSha); | ||
|
||
let pullRequest; | ||
if (branchName !== 'master') { | ||
if (branchName !== 'master' && branchName !== 'dev') { | ||
setStep(6); | ||
pullRequest = await withMetaData(createPullRequest)(branchName, prTitle); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,34 +10,69 @@ const defaultSetting = { | |
width: 700, | ||
}; | ||
|
||
/** | ||
* Получить имя, размер и категорию из полного имени | ||
* Example: | ||
* 24 / Operation / 24_ShareScreenOutline - новый формат | ||
* Player / ic_36_pause_outline - старый формат | ||
*/ | ||
const getNormalizedName = (name: string) => { | ||
const secondPart = camelize(name).split('/')[1] || camelize(name); | ||
const withoutPrefix = secondPart | ||
.trim() | ||
.replace(/^(\s*)[a-zA-Z_]+(\d\d)/g, '') | ||
.replace(/\s/g, ''); | ||
return upperFirstLetter(withoutPrefix); | ||
const trimmedName = name.replace(/\s/g, ''); | ||
// в новом формате | ||
const [size, category, nameWithSize] = trimmedName.split('/'); | ||
|
||
if (!size || !category || !nameWithSize) { | ||
const last = camelize(trimmedName).split('/').slice(-1)[0]; | ||
const withoutPrefix = last | ||
.trim() | ||
.replace(/^(\s*)[a-zA-Z_]+(\d\d)/g, '') // убирает все символы и размер перед названием: ic36pauseOutline -> pauseOutline | ||
.replace(/\s/g, ''); | ||
return upperFirstLetter(withoutPrefix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. можешь пожалуйста добавить в коментах пример строки, которая в итоге разбирается, и что получается из неё? А то я этого в своё время не сделал и сейчас этот код трудно читается There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. добавил комменты |
||
} | ||
|
||
return { | ||
size, | ||
category, | ||
name: upperFirstLetter(nameWithSize.split('_').slice(-1)[0]), // убирает размер перед названием | ||
}; | ||
}; | ||
|
||
const getNames = async (node: ComponentNode | InstanceNode) => { | ||
const { width, name: nodeName } = node; | ||
|
||
const normalizedName = getNormalizedName(nodeName); | ||
const svg = await getExportSvg(node); | ||
|
||
const isString = typeof normalizedName === 'string'; | ||
|
||
return { | ||
size: isString ? Math.round(width) : Number(normalizedName.size), | ||
category: isString ? 'Other' : normalizedName.category, | ||
name: isString ? normalizedName : normalizedName.name, | ||
svg, | ||
}; | ||
}; | ||
|
||
const sendMetaDataInfo = async (selections: readonly SceneNode[]) => { | ||
const iconsMetaData = await Promise.all( | ||
selections.map(async (selection) => { | ||
const { width, name } = selection; | ||
const { type } = selection; | ||
|
||
if (type !== 'FRAME') { | ||
return []; | ||
} | ||
|
||
const normalizedName = getNormalizedName(name); | ||
const svg = await getExportSvg(selection); | ||
const nodes = (selection as FrameNode).findAllWithCriteria({ | ||
types: ['COMPONENT', 'INSTANCE'], | ||
}); | ||
|
||
return { | ||
size: Math.round(width), | ||
name: normalizedName, | ||
svg, | ||
}; | ||
return await Promise.all(nodes.map(getNames)); | ||
}), | ||
); | ||
|
||
const payload: UIMessage<IconPayload[]> = { | ||
type: 'update-icon-data', | ||
payload: iconsMetaData, | ||
payload: iconsMetaData.flat(), | ||
}; | ||
figma.ui.postMessage(payload); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а для чего этот файл тоже коммитить надо при экспорте иконок? 🤔 Он же вроде всегда статичный должен оставаться
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а, кажется понял, из-за появившейся возможности динамически добавлять категории
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
да, из-за категорий