-
Notifications
You must be signed in to change notification settings - Fork 2
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
model display hint, centralise special format definitions #491
Merged
+170
−130
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
39d2dc7
add display hint to stub modelling
dblatcher e228919
add display hint to filter modelling, populate on the data before pos…
dblatcher aad9db6
add a list of formats andsome ts helpers
dblatcher f1eb849
ts files need to be named as such when importing
dblatcher d085e09
use helper to control whether to show the format dropdown
dblatcher 625032c
add helpers to get lists of formats accounting for feature switches
dblatcher bf37085
refactor the helper files
dblatcher 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 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 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 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 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 |
---|---|---|
@@ -1,27 +1,14 @@ | ||
define(['angular'], function (angular) { | ||
'use strict'; | ||
import angular from 'angular'; | ||
import { provideArticleFormatsForDropDown } from './model/format-helpers.ts'; | ||
|
||
var articleFormatService = angular.module('articleFormatService', []); | ||
|
||
articleFormatService.factory('articleFormatService',['wfPreferencesService', function (wfPreferencesService) { | ||
function getArticleFormats() { | ||
const featureSwitches = wfPreferencesService.preferences.featureSwitches; | ||
|
||
const articleFormats = [ | ||
{name: 'Standard Article', value: 'Standard Article'}, | ||
{name: 'Key Takeaways', value: 'Key Takeaways'}, | ||
{name: 'Q&A Explainer', value: 'Q&A Explainer'}, | ||
{name: 'Timeline', value: 'Timeline'}, | ||
{name: 'Mini profiles', value: 'Mini profiles'}, | ||
] | ||
if (featureSwitches && featureSwitches.multiByline){ | ||
articleFormats.push({name: 'Multi-byline', value: 'Multi-byline'}) | ||
} | ||
return articleFormats | ||
}; | ||
angular.module('articleFormatService', []) | ||
.factory('articleFormatService', ['wfPreferencesService', function (wfPreferencesService) { | ||
function getArticleFormats() { | ||
const featureSwitches = wfPreferencesService.preferences?.featureSwitches; | ||
return provideArticleFormatsForDropDown(featureSwitches) | ||
}; | ||
return { | ||
getArticleFormats: getArticleFormats | ||
}; | ||
}]); | ||
return articleFormatService; | ||
}); | ||
getArticleFormats: getArticleFormats | ||
}; | ||
}]); |
This file contains 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 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 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 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,84 @@ | ||
import { specialFormats } from './special-formats' | ||
import { ContentType } from './stub' | ||
|
||
const STANDARD_ARTICLE_FORMAT_LABEL = "Standard Article"; | ||
const STANDARD_ARTICLE_FORMAT_SHORT_LABEL = "Article"; | ||
|
||
const nonArticleFormats = { | ||
"liveblog": "Live blog", | ||
"gallery": "Gallery", | ||
"interactive": "Interactive", | ||
"picture": "Picture", | ||
"audio": "Audio", | ||
"atom": "Video/Atom" | ||
} | ||
|
||
/** | ||
* Returns an object mapping ContentType to user facings labels, excluding any | ||
* special formats that that behind a feature switch in the 'off' state. | ||
*/ | ||
const provideFormats = (featureSwitches?: Record<string, boolean>): Partial<Record<ContentType, string>> => { | ||
const articleFormats: Record<string, string> = { | ||
"article": STANDARD_ARTICLE_FORMAT_SHORT_LABEL, | ||
} | ||
|
||
specialFormats.forEach(format => { | ||
if (format.behindFeatureSwitch) { | ||
if (featureSwitches?.[format.behindFeatureSwitch]) { | ||
articleFormats[format.value] = format.label | ||
} | ||
} else { | ||
articleFormats[format.value] = format.label | ||
} | ||
}) | ||
|
||
|
||
// Assembling the object this way preserves the existing order in the UI | ||
return { ...articleFormats, ...nonArticleFormats }; | ||
} | ||
|
||
/** | ||
* Returns a list of objects describing the available article formats | ||
* that can be used to as a model for a select input in an angular template | ||
*/ | ||
const provideArticleFormatsForDropDown = (featureSwitches?: Record<string, boolean>): { name: string; value: string }[] => { | ||
|
||
const list = [STANDARD_ARTICLE_FORMAT_LABEL] | ||
|
||
specialFormats.forEach(format => { | ||
if (format.behindFeatureSwitch) { | ||
if (featureSwitches && featureSwitches[format.behindFeatureSwitch]) { | ||
list.push(format.label) | ||
} | ||
} else { | ||
list.push(format.label) | ||
} | ||
}) | ||
|
||
return list.map(label => ({ name: label, value: label })) | ||
} | ||
|
||
/** | ||
* returns "Standard Article" for normal articles, the label for special article formats | ||
* or empty string for non-article content types | ||
*/ | ||
const getArticleFormatLabel = (contentType: ContentType): string => { | ||
const maybeMatchingFormat = specialFormats.find(format => format.value === contentType) | ||
if (maybeMatchingFormat) { | ||
return maybeMatchingFormat.label | ||
} | ||
if (contentType === 'article') { | ||
return STANDARD_ARTICLE_FORMAT_LABEL | ||
} | ||
return '' | ||
} | ||
|
||
/** | ||
* true if the value is the label of a special format or the "Standard Article" label | ||
*/ | ||
const isFormatLabel = (value: string): boolean => { | ||
return value === STANDARD_ARTICLE_FORMAT_LABEL || specialFormats.some(format => format.label === value) | ||
} | ||
|
||
|
||
export { provideFormats, provideArticleFormatsForDropDown, getArticleFormatLabel, isFormatLabel } |
This file contains 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,37 @@ | ||
import { ComposerContentType, ContentType, SpecialArticleFormat, Stub } from "./stub"; | ||
|
||
const specialFormats: SpecialArticleFormat[] = [ | ||
{ label: 'Key Takeaways', value: 'keyTakeaways' }, | ||
{ label: 'Q&A Explainer', value: 'qAndA' }, | ||
{ label: 'Timeline', value: 'timeline' }, | ||
{ label: 'Mini profiles', value: 'miniProfiles' }, | ||
{ label: 'Multi-byline', value: 'multiByline', behindFeatureSwitch: 'multiByline' }, | ||
] | ||
|
||
const setDisplayHintForFormat = (stub: Stub): Stub => { | ||
const maybeMatchingFormat = specialFormats.find(format => format.value === stub.contentType) | ||
if (maybeMatchingFormat) { | ||
stub.displayHint = maybeMatchingFormat.value | ||
} | ||
return stub | ||
} | ||
|
||
const getSpecialFormatFromLabel = (label: string): SpecialArticleFormat | undefined => | ||
specialFormats.find(format => format.label === label) | ||
|
||
const contentTypeToComposerContentType = (type: ContentType): ComposerContentType => { | ||
switch (type) { | ||
case "article": | ||
case "liveblog": | ||
case "gallery": | ||
case "interactive": | ||
case "picture": | ||
case "video": | ||
case "audio": | ||
return type; | ||
default: | ||
return 'article' | ||
} | ||
} | ||
|
||
export { specialFormats, setDisplayHintForFormat, getSpecialFormatFromLabel, contentTypeToComposerContentType } |
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.
It's a great idea, centralising the list of special formats in this constant.