Skip to content

Commit

Permalink
feat(csv): Add overriden name support to the csv.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruler501 committed Nov 4, 2023
1 parent 3b2bf51 commit 7669be7
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
10 changes: 10 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,13 @@ This release is composed of porting over bug fixes for bugs we carried over from
#### Infrastructure

- Better track and export data on decks for analytics and machine learning.

### v1.4.6.8

#### Features

- Support overriden name in CSV export and import.

#### Bug Fixes

- Fix for specifying color category in csv import.
2 changes: 1 addition & 1 deletion client/components/modals/CardModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const CardModal = ({
<fieldset disabled={disabled}>
<InputGroup className="mb-3">
<InputGroupAddon addonType="prepend">
<InputGroupText>Overriden Name</InputGroupText>
<InputGroupText>Overridden Name</InputGroupText>
</InputGroupAddon>
<Input type="text" name="name" value={values.name} onChange={onChange} />
</InputGroup>
Expand Down
1 change: 1 addition & 0 deletions server/__tests__/routes/cube/export.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ test('csv download', () => {
'Tags',
'Notes',
'MTGO ID',
'Overridden Name',
];

const faerieGuidemotherData = {
Expand Down
23 changes: 16 additions & 7 deletions server/__tests__/serverjs/cubefn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,33 +145,41 @@ describe('CSVtoCards', () => {
finish: 'Is Foil',
imgUrl: 'http://example.com/',
tags: ['tag1', 'tag2'],
colorCategory: null,
overriddenName: null,
};
const expectedMaybe = {
name: 'Embercleave',
cmc: '2',
type_line: 'Creature - Type',
type_line: null,
colors: ['R', 'W'],
set: 'ELD',
collector_number: '120',
status: 'Not Owned',
finish: 'Is Not Foil',
imgUrl: null,
tags: ['tag3', 'tag4'],
overriddenName: 'Testingcleave',
colorCategory: 'R',
};
const cards = [
'Name,CMC,Type,Color,Set,Collector Number,Status,Finish,Maybeboard,Image URL,Tags',
`"${expectedCard.name}",${expectedCard.cmc},${expectedCard.type_line.replace(
'Name,CMC,Type,Color,Set,Collector Number,Status,Finish,Maybeboard,Image URL,Tags,Overridden Name,Color Category',
`"${expectedCard.name}",${expectedCard.cmc},${(expectedCard.type_line || '').replace(
'—',
'-',
)},${expectedCard.colors.join('')},${expectedCard.set},${expectedCard.collector_number},${expectedCard.status},${
expectedCard.finish
},false,${expectedCard.imgUrl},"${expectedCard.tags.join(';')}"`,
`"${expectedMaybe.name}",${expectedMaybe.cmc},${expectedMaybe.type_line.replace(
},false,${expectedCard.imgUrl},"${expectedCard.tags.join(';')}","${expectedCard.overriddenName || ''}",${
expectedCard.colorCategory || ''
}`,
`"${expectedMaybe.name}",${expectedMaybe.cmc},${(expectedMaybe.type_line || '').replace(
'—',
'-',
)},${expectedMaybe.colors.join('')},${expectedMaybe.set},${expectedMaybe.collector_number},${
expectedMaybe.status
},${expectedMaybe.finish},true,undefined,"${expectedMaybe.tags.join(';')}"`,
},${expectedMaybe.finish},true,undefined,"${expectedMaybe.tags.join(';')}","${
expectedMaybe.overriddenName || ''
}",${expectedMaybe.colorCategory || ''}`,
];
await carddb.initializeCardDb(fixturesPath, true);
const { newCards, newMaybe, missing } = CSVtoCards(cards.join('\n'), carddb);
Expand All @@ -183,14 +191,15 @@ describe('CSVtoCards', () => {
});
const expectSame = (card, expected) => {
expect(card.cardID).toBe(expectedId);
expect(card.name).toBe(expected.name);
expect(card.name).toBe(expected.overriddenName);
expect(card.cmc).toBe(expected.cmc);
expect(card.colors).equalsArray(expected.colors);
expect(card.collector_number).toBe(expected.collector_number);
expect(card.status).toBe(expected.status);
expect(card.finish).toBe(expected.finish);
expect(card.imgUrl).toBe(expected.imgUrl);
expect(card.tags).equalsArray(expected.tags);
expect(card.colorCategory).toBe(expected.colorCategory);
};
expect(newCards.length).toBe(1);
expectSame(newCards[0], expectedCard);
Expand Down
5 changes: 3 additions & 2 deletions server/routes/cube/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const DEFAULT_BASICS = [
export const CARD_HEIGHT = 680;
export const CARD_WIDTH = 488;
export const CSV_HEADER =
'Name,CMC,Type,Color,Set,Collector Number,Rarity,Color Category,Status,Finish,Maybeboard,Image URL,Image Back URL,Tags,Notes,MTGO ID';
'Name,CMC,Type,Color,Set,Collector Number,Rarity,Color Category,Status,Finish,Maybeboard,Image URL,Image Back URL,Tags,Notes,MTGO ID,Overridden Name';

export const updateCubeAndBlog = async (req, res, cube, changelog, added, missing) => {
try {
Expand Down Expand Up @@ -173,7 +173,8 @@ export const writeCard = (res, card, maybe) => {
res.write(tag);
});
res.write(`","${card.notes || ''}",`);
res.write(`${carddb.cardFromId(card.cardID).mtgo_id || ''}`);
res.write(`${carddb.cardFromId(card.cardID).mtgo_id || ''},`);
res.write(`${card.name || ''}`);
res.write('\n');
};

Expand Down
4 changes: 3 additions & 1 deletion server/serverjs/cubefn.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ export const CSVtoCards = (csvString, carddb) => {
'image back url': imageBackUrl,
tags,
notes,
'Color Category': colorCategory,
'color category': colorCategory,
rarity,
'overridden name': overriddenName,
} of data) {
if (name) {
const upperSet = (set || '').toUpperCase();
Expand Down Expand Up @@ -277,6 +278,7 @@ export const CSVtoCards = (csvString, carddb) => {
const nonPromo = potentialIds.find(carddb.reasonableId);
const first = potentialIds[0];
card.cardID = matchingSetAndNumber || matchingSet || nonPromo || first;
card.name = overriddenName || null;
if (maybeboard.toLowerCase() === 'true') {
newMaybe.push(card);
} else {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3743,9 +3743,9 @@ can-use-dom@^0.1.0:
integrity sha1-IsxKNKCrxDlQ9CxkEQJKP2NmtFo=

caniuse-lite@^1.0.30001280:
version "1.0.30001474"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001474.tgz"
integrity sha512-iaIZ8gVrWfemh5DG3T9/YqarVZoYf0r188IjaGwx68j4Pf0SGY6CQkmJUIE+NZHkkecQGohzXmBGEwWDr9aM3Q==
version "1.0.30001561"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001561.tgz"
integrity sha512-NTt0DNoKe958Q0BE0j0c1V9jbUzhBxHIEJy7asmGrpE0yG63KTV7PLHPnK2E1O9RsQrQ081I3NLuXGS6zht3cw==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down

0 comments on commit 7669be7

Please sign in to comment.