From c4b94d618d183a6ab01406f73ac81c8d300dc0f8 Mon Sep 17 00:00:00 2001 From: Alessio Occhipinti Date: Sun, 23 Dec 2018 18:14:33 +0100 Subject: [PATCH] Fixed order and empty list (#299) --- extensions/webviews/interfaces.ts | 8 +++++++- extensions/webviews/ui/release-notes/index.ts | 15 +++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/extensions/webviews/interfaces.ts b/extensions/webviews/interfaces.ts index 5ba4c81..eb2cfb8 100644 --- a/extensions/webviews/interfaces.ts +++ b/extensions/webviews/interfaces.ts @@ -13,7 +13,13 @@ export interface IPost { new: IChangeType[]; breaking: IChangeType[]; } - +export interface IPostNormalized { + title: String; + version: String; + fixed: String[]; + new: String[]; + breaking: String[]; +} export interface SettingsChangedMessage { type: 'settingsChanged'; config: IThemeCustomSettings; diff --git a/extensions/webviews/ui/release-notes/index.ts b/extensions/webviews/ui/release-notes/index.ts index 68ab198..25dba37 100644 --- a/extensions/webviews/ui/release-notes/index.ts +++ b/extensions/webviews/ui/release-notes/index.ts @@ -1,6 +1,6 @@ import * as sanityClient from '@sanity/client'; -import {IPost} from '../../interfaces'; +import {IPost, IPostNormalized} from '../../interfaces'; const getClient = () => sanityClient({ projectId: 'v475t82f', @@ -8,21 +8,24 @@ const getClient = () => sanityClient({ }); const getReleaseNotes = (): Promise => { - const query = '*[_type == "release"] | order(_createdAt desc)'; + const query = '*[_type == "release"] | order(version desc)'; const client = getClient(); return client.fetch(query); }; -const renderTemplate = (posts: IPost[]) => { +const renderTemplate = (posts: IPostNormalized[]) => { return `${posts.reduce((acc, {version, title, fixed, new: newItems, breaking}) => acc.concat(`
${version}

${title}

    - ${fixed.reduce((accc: string, src) => accc.concat(`
  • ${src}
  • `), '')} - ${newItems.reduce((accc: string, src) => accc.concat(`
  • ${src}
  • `), '')} - ${breaking.reduce((accc: string, src) => accc.concat(`
  • ${src}
  • `), '')} + ${fixed.reduce((accc: string, src) => + src.length > 0 ? accc.concat(`
  • ${src}
  • `) : '', '')} + ${newItems.reduce((accc: string, src) => + src.length > 0 ? accc.concat(`
  • ${src}
  • `) : '', '')} + ${breaking.reduce((accc: string, src) => + src.length > 0 ? accc.concat(`
  • ${src}
  • `) : '', '')}
`), '')}`; };