Add a sortIndex to items.
This commit is contained in:
parent
ab6ef97d91
commit
c72959841f
|
@ -14,6 +14,23 @@ export const dataMigrations: Array<Migration<string>> = [
|
|||
migrated[key] = item;
|
||||
}
|
||||
|
||||
return migrated;
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '0.3.0',
|
||||
async migrate(data: Record<string, any>) {
|
||||
const migrated: Record<string, any> = {
|
||||
version: '0.3.0',
|
||||
};
|
||||
|
||||
for (const [key, value] of Object.entries<Queue.Item>(data)) {
|
||||
if (key.startsWith('qi')) {
|
||||
migrated[key] = value;
|
||||
migrated[key].sortIndex = value.id;
|
||||
}
|
||||
}
|
||||
|
||||
return migrated;
|
||||
},
|
||||
},
|
||||
|
|
|
@ -42,6 +42,7 @@ export class Settings {
|
|||
const item: Queue.Item = {
|
||||
added: new Date(),
|
||||
id,
|
||||
sortIndex: id,
|
||||
text,
|
||||
url,
|
||||
};
|
||||
|
@ -51,6 +52,7 @@ export class Settings {
|
|||
[`qi${id}`]: {
|
||||
added: item.added.toISOString(),
|
||||
id,
|
||||
sortIndex: id,
|
||||
text,
|
||||
url,
|
||||
},
|
||||
|
|
|
@ -22,6 +22,7 @@ declare global {
|
|||
type Item = {
|
||||
added: Date;
|
||||
id: number;
|
||||
sortIndex: number;
|
||||
text: string;
|
||||
url: string;
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ const queueItemSample: Queue.Item = {
|
|||
id: 1,
|
||||
text: 'Sample',
|
||||
url: 'https://example.org',
|
||||
};
|
||||
} as unknown as Queue.Item;
|
||||
|
||||
test('dataMigrations happy path', async (t) => {
|
||||
let data: Record<string, any> = {
|
||||
|
|
|
@ -18,6 +18,19 @@ Generated by [AVA](https://avajs.dev).
|
|||
version: '0.1.7',
|
||||
}
|
||||
|
||||
> Migration 0.3.0
|
||||
|
||||
{
|
||||
qi1: {
|
||||
added: Date 2022-03-02 16:00:00 UTC {},
|
||||
id: 1,
|
||||
sortIndex: 1,
|
||||
text: 'Sample',
|
||||
url: 'https://example.org',
|
||||
},
|
||||
version: '0.3.0',
|
||||
}
|
||||
|
||||
## dataMigrations unhappy path
|
||||
|
||||
> Migration 0.1.7
|
||||
|
@ -26,6 +39,12 @@ Generated by [AVA](https://avajs.dev).
|
|||
version: '0.1.7',
|
||||
}
|
||||
|
||||
> Migration 0.3.0
|
||||
|
||||
{
|
||||
version: '0.3.0',
|
||||
}
|
||||
|
||||
## Serializing & Deserializing Queue
|
||||
|
||||
> Serialized
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue