Repository navigation
feat: 스키마 갱신과 상품·주문 커스텀 표시 #86
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| const HEX = /^#[0-9A-Fa-f]{6}$/; | ||
|
|
||
| /** 판매자가 고른 글자색 견본과 값. 형식이 어긋난 값은 견본 없이 글자만 보인다 */ | ||
| export function ColorSwatch({ color }: { color: string }) { | ||
| return ( | ||
| <span className="inline-flex items-center gap-1.5 font-mono text-xs"> | ||
| <span | ||
| aria-hidden | ||
| data-slot="color-swatch" | ||
| className="size-3.5 shrink-0 rounded-sm border" | ||
| style={HEX.test(color) ? { backgroundColor: color } : undefined} | ||
| /> | ||
| {color} | ||
| </span> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { areaToPercent, splitCustomImages } from './custom-geometry'; | ||
|
|
||
| describe('areaToPercent', () => { | ||
| it.each([ | ||
| ['바탕 전체', [0, 0, 10000, 10000], ['0%', '0%', '100%', '100%']], | ||
| ['소수 둘째 자리', [1234, 5678, 100, 1], ['12.34%', '56.78%', '1%', '0.01%']], | ||
| ['오른쪽 아래 끝 1칸', [9999, 9999, 1, 1], ['99.99%', '99.99%', '0.01%', '0.01%']], | ||
| ['넘치는 크기는 바탕 끝까지', [5000, 2500, 6000, 9000], ['50%', '25%', '50%', '75%']], | ||
| ['범위 밖 시작점은 가장자리로', [-10, 12000, 100, 100], ['0%', '100%', '1%', '0%']], | ||
| ['음수 크기는 0', [100, 100, -5, -1], ['1%', '1%', '0%', '0%']], | ||
| ['숫자가 아니면 0', [Number.NaN, 0, Number.POSITIVE_INFINITY, 10], ['0%', '0%', '0%', '0.1%']], | ||
| ])('%s', (_, [posX, posY, width, height], [left, top, w, h]) => { | ||
| expect(areaToPercent({ posX: posX!, posY: posY!, width: width!, height: height! })).toEqual({ | ||
| left, | ||
| top, | ||
| width: w, | ||
| height: h, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| const img = (kind: string) => ({ kind, imageUrl: `https://img.test/${kind}.png` }); | ||
| const kinds = (list: readonly { kind: string }[]) => list.map((i) => i.kind); | ||
|
|
||
| describe('splitCustomImages', () => { | ||
| it('3D 5장은 받은 순서와 관계없이 윗면 → 앞·뒤·왼·오다', () => { | ||
| const r = splitCustomImages( | ||
| ['THREE_D_RIGHT', 'THREE_D_BACK', 'THREE_D_TOP', 'THREE_D_LEFT', 'THREE_D_FRONT'].map(img), | ||
| ); | ||
| expect(r.top?.kind).toBe('THREE_D_TOP'); | ||
| expect(kinds(r.sides)).toEqual([ | ||
| 'THREE_D_FRONT', | ||
| 'THREE_D_BACK', | ||
| 'THREE_D_LEFT', | ||
| 'THREE_D_RIGHT', | ||
| ]); | ||
| expect(r.composite).toBeNull(); | ||
| }); | ||
|
|
||
| it('슬롯형 합성은 렌더와 따로 나온다', () => { | ||
| const r = splitCustomImages([img('SLOT_COMPOSITE')]); | ||
| expect(r).toEqual({ top: null, sides: [], composite: img('SLOT_COMPOSITE') }); | ||
| }); | ||
|
|
||
| it('모르는 종류는 버리지 않고 옆면 뒤에 받은 순서대로 둔다', () => { | ||
| const r = splitCustomImages(['HOLOGRAM', 'THREE_D_LEFT', 'THREE_D_TOP', 'BOTTOM'].map(img)); | ||
| expect(r.top?.kind).toBe('THREE_D_TOP'); | ||
| expect(kinds(r.sides)).toEqual(['THREE_D_LEFT', 'HOLOGRAM', 'BOTTOM']); | ||
| }); | ||
|
|
||
| it('윗면이 없으면 렌더는 전부 옆면 자리에 둔다', () => { | ||
| const r = splitCustomImages(['THREE_D_BACK', 'THREE_D_FRONT'].map(img)); | ||
| expect(r.top).toBeNull(); | ||
| expect(kinds(r.sides)).toEqual(['THREE_D_FRONT', 'THREE_D_BACK']); | ||
| }); | ||
|
|
||
| it('이미지가 없으면 모두 비어 있고 입력 배열은 바꾸지 않는다', () => { | ||
| expect(splitCustomImages([])).toEqual({ top: null, sides: [], composite: null }); | ||
| const input = Object.freeze(['THREE_D_FRONT', 'THREE_D_TOP'].map(img)); | ||
| expect(() => splitCustomImages(input)).not.toThrow(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /** 커스텀 좌표는 바탕 이미지 한 변을 10000으로 본 정수 비율이고 원점은 왼쪽 위다 */ | ||
| const SCALE = 10000; | ||
|
|
||
| interface Area { | ||
| posX: number; | ||
| posY: number; | ||
| width: number; | ||
| height: number; | ||
| } | ||
|
|
||
| const clamp = (v: number, max: number) => Math.min(Math.max(Number.isFinite(v) ? v : 0, 0), max); | ||
| const percent = (v: number) => `${v / 100}%`; | ||
|
|
||
| /** 바탕 위 영역을 CSS 백분율 위치로 바꾼다. 범위 밖 값은 바탕 안으로 자른다 */ | ||
| export function areaToPercent(a: Area) { | ||
| const left = clamp(a.posX, SCALE); | ||
| const top = clamp(a.posY, SCALE); | ||
| return { | ||
| left: percent(left), | ||
| top: percent(top), | ||
| width: percent(clamp(a.width, SCALE - left)), | ||
| height: percent(clamp(a.height, SCALE - top)), | ||
| }; | ||
| } | ||
|
|
||
| const RENDER_ORDER: readonly string[] = [ | ||
| 'THREE_D_TOP', | ||
| 'THREE_D_FRONT', | ||
| 'THREE_D_BACK', | ||
| 'THREE_D_LEFT', | ||
| 'THREE_D_RIGHT', | ||
| ]; | ||
|
|
||
| /** | ||
| * 커스텀 이미지를 윗면 · 옆면(앞·뒤·왼·오) · 슬롯형 합성으로 나눈다. | ||
| * 모르는 종류는 버리지 않고 옆면 뒤에 받은 순서대로 둔다. | ||
| */ | ||
| export function splitCustomImages<T extends { kind: string }>(images: readonly T[]) { | ||
| const rank = (kind: string) => { | ||
| const i = RENDER_ORDER.indexOf(kind); | ||
| return i === -1 ? RENDER_ORDER.length : i; | ||
| }; | ||
| const renders = images | ||
| .filter((i) => i.kind !== 'SLOT_COMPOSITE') | ||
| .sort((a, b) => rank(a.kind) - rank(b.kind)); | ||
| const top = renders[0]?.kind === 'THREE_D_TOP' ? renders[0] : null; | ||
| return { | ||
| top, | ||
| sides: top ? renders.slice(1) : renders, | ||
| composite: images.find((i) => i.kind === 'SLOT_COMPOSITE') ?? null, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export { ColorSwatch } from './components/color-swatch'; | ||
| export { areaToPercent, splitCustomImages } from './custom-geometry'; | ||
| export { | ||
| customModeLabel, | ||
| imageKindLabel, | ||
| SLOT_TEXT_STATE_LABEL, | ||
| slotTextState, | ||
| textAlignLabel, | ||
| } from './meta'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { buildSchema, isEnumType } from 'graphql'; | ||
|
|
||
| // codegen이 읽는 SDL 스냅샷 원문. 손으로 적은 라벨 표와 대조하는 정답지다 | ||
| import sdl from '../../../schema/schema.graphql?raw'; | ||
|
|
||
| import { | ||
| customModeLabel, | ||
| imageKindLabel, | ||
| SLOT_TEXT_STATE_LABEL, | ||
| slotTextState, | ||
| textAlignLabel, | ||
| } from './meta'; | ||
|
|
||
| function enumValues(name: string): string[] { | ||
| const t = buildSchema(sdl).getType(name); | ||
| if (!isEnumType(t)) throw new Error(`${name} enum이 스키마에 없다`); | ||
| return t.getValues().map((v) => v.name); | ||
| } | ||
|
|
||
| const TABLES = [ | ||
| ['CustomModeType', customModeLabel], | ||
| ['CustomTextAlignType', textAlignLabel], | ||
| ['CustomImageKindType', imageKindLabel], | ||
| ] as const; | ||
|
|
||
| describe('커스텀 enum 라벨', () => { | ||
| it.each(TABLES)('%s 값이 스키마에 있다(정답지가 비어 통과하지 않게)', (name) => { | ||
| expect(enumValues(name).length).toBeGreaterThanOrEqual(3); | ||
| }); | ||
|
|
||
| it.each(TABLES.flatMap(([name, fn]) => enumValues(name).map((v) => [name, v, fn] as const)))( | ||
| '%s.%s는 원문이 아닌 한국어 라벨로 보인다', | ||
| (_, value, fn) => { | ||
| expect(fn(value)).not.toBe(value); | ||
| }, | ||
| ); | ||
|
|
||
| it.each([['HOLOGRAM'], ['constructor'], ['toString'], ['']])( | ||
| '모르는 값 %j는 원문으로 보인다', | ||
| (value) => { | ||
| for (const [, fn] of TABLES) expect(fn(value)).toBe(value); | ||
| }, | ||
| ); | ||
|
|
||
| it('대표 라벨', () => { | ||
| expect([customModeLabel('SLOT'), customModeLabel('THREE_D')]).toEqual(['슬롯형', '3D']); | ||
| expect(textAlignLabel('CENTER')).toBe('가운데'); | ||
| expect(imageKindLabel('THREE_D_TOP')).toBe('윗면'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('slotTextState', () => { | ||
| it.each([ | ||
| ['기본 문구 그대로', 'DEFAULT', '축하해', '축하해'], | ||
| [ | ||
| '기본 문구의 CRLF·앞뒤 공백은 저장 규칙대로 맞춰 본다', | ||
| 'DEFAULT', | ||
| ' 생일\r\n축하해 ', | ||
| '생일\n축하해', | ||
| ], | ||
| ['기본 문구의 홀로 있는 CR도 LF로 맞춰 본다', 'DEFAULT', '생일\r축하해', '생일\n축하해'], | ||
| ['바꾼 문구', 'CHANGED', '축하해', '서연아 생일 축하해 🎂'], | ||
| ['줄바꿈만 다름', 'CHANGED', '생일 축하해', '생일\n축하해'], | ||
| ['선택 자리를 지움(null)', 'EMPTY', '축하해', null], | ||
| ['빈 문자열', 'EMPTY', '축하해', ''], | ||
| ['기본 문구가 비어 있고 입력도 없음', 'EMPTY', '', null], | ||
| ] as const)('%s → %s', (_, state, defaultText, valueText) => { | ||
| expect(slotTextState({ defaultText, valueText })).toBe(state); | ||
| }); | ||
|
|
||
| it('상태마다 라벨이 있다', () => { | ||
| expect(SLOT_TEXT_STATE_LABEL).toEqual({ | ||
| DEFAULT: '기본 그대로', | ||
| CHANGED: '바꿈', | ||
| EMPTY: '문구 없음', | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { | ||
| type CustomImageKindType, | ||
| type CustomModeType, | ||
| type CustomTextAlignType, | ||
| } from '@/graphql/generated/graphql'; | ||
|
|
||
| // Record라 codegen enum에 값이 늘면 tsc가 잡는다. 화면은 BE가 먼저 배포돼 모르는 값이 와도 원문으로 보인다 | ||
| const MODE: Record<CustomModeType, string> = { NONE: '없음', SLOT: '슬롯형', THREE_D: '3D' }; | ||
| const ALIGN: Record<CustomTextAlignType, string> = { | ||
| LEFT: '왼쪽', | ||
| CENTER: '가운데', | ||
| RIGHT: '오른쪽', | ||
| }; | ||
| const IMAGE_KIND: Record<CustomImageKindType, string> = { | ||
| THREE_D_TOP: '윗면', | ||
| THREE_D_FRONT: '앞', | ||
| THREE_D_BACK: '뒤', | ||
| THREE_D_LEFT: '왼쪽', | ||
| THREE_D_RIGHT: '오른쪽', | ||
| SLOT_COMPOSITE: '합성 이미지', | ||
| }; | ||
|
|
||
| /** 표에 있는 값만 라벨로 바꾼다. `constructor` 같은 프로토타입 키도 모르는 값이다 */ | ||
| const label = (table: Record<string, string>, value: string) => | ||
| Object.hasOwn(table, value) ? table[value]! : value; | ||
|
|
||
| export const customModeLabel = (v: string) => label(MODE, v); | ||
| export const textAlignLabel = (v: string) => label(ALIGN, v); | ||
| export const imageKindLabel = (v: string) => label(IMAGE_KIND, v); | ||
|
|
||
| export type SlotTextState = 'DEFAULT' | 'CHANGED' | 'EMPTY'; | ||
| export const SLOT_TEXT_STATE_LABEL: Record<SlotTextState, string> = { | ||
| DEFAULT: '기본 그대로', | ||
| CHANGED: '바꿈', | ||
| EMPTY: '문구 없음', | ||
| }; | ||
|
|
||
| /** BE는 문구의 CRLF·CR을 LF로 바꾸고 trim해 저장하므로 기본 문구도 같은 규칙으로 맞춰 비교한다 */ | ||
| export function slotTextState(t: { defaultText: string; valueText: string | null }): SlotTextState { | ||
| if (t.valueText === null || t.valueText === '') return 'EMPTY'; | ||
| return t.valueText === t.defaultText.replace(/\r\n?/g, '\n').trim() ? 'DEFAULT' : 'CHANGED'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For an unpaid
PENDING_PAYMENTorder, the newly enabled cancellation dialog always submitsOTHER, although the updatedadminCancelOrdercontract specifiesPAYMENT_NOT_RECEIVEDfor cancellation due to nonpayment (schema/schema.graphql:2611–2615). The input must also use a reason fromcancelOptions.reasons, otherwise the server returnsCANCEL_REASON_NOT_ALLOWED. Consequently, the new pending-payment cancellation action cannot submit the prescribed nonpayment cancellation. Fetch and use the order's cancellation options, or pass the appropriate pending-payment reason instead of unconditionally sendingOTHER.Useful? React with 👍 / 👎.
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.
미반영(기록): 단계 분할. BE 정책상 관리자는 입금 대기 주문에 OTHER도 허용(CANCEL_REASON_NOT_ALLOWED 아님)이라 지금도 취소는 성공함. 미입금 사유(PAYMENT_NOT_RECEIVED) 선택을 포함한 cancelOptions 기반 취소 다이얼로그는 다음 PR(주문 결제·취소)에서 넣고, 관리자 릴리즈는 그 뒤라 운영 노출 없음.