-
Notifications
You must be signed in to change notification settings - Fork 48
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
Feat (data): support checklist data format #103
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 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 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,20 +1,35 @@ | ||||||
import type { OldListData, ListData, ListItem } from '../types/ListParams'; | ||||||
import type { OldListData, ListData, ListItem, OldChecklistData } from '../types/ListParams'; | ||||||
|
||||||
/** | ||||||
* Method that checks if data is related to the List or NestedListTool | ||||||
* @param data - data of the List or NestedListTool | ||||||
* @returns true if data related to the List tool, false if to Nested List tool | ||||||
* Method that checks if data is related to the List Tool | ||||||
* @param data - data of the List or NestedList tool | ||||||
* @returns true if data related to the List tool, false otherwise | ||||||
*/ | ||||||
function instanceOfListData(data: ListData | OldListData): data is OldListData { | ||||||
function instanceOfListData(data: ListData | OldListData | OldChecklistData): data is OldListData { | ||||||
return (typeof data.items[0] === 'string'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. function name means checking passed value to be |
||||||
} | ||||||
|
||||||
/** | ||||||
* Method that checks if data is related to the Checklist tool | ||||||
* @param data - data of the Checklist of NestedList tool | ||||||
* @returns true if data is related to the Checklist tool, false otherwise | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
function instanceOfChecklistData(data: ListData | OldListData | OldChecklistData): data is OldChecklistData { | ||||||
return ( | ||||||
typeof data.items[0] !== 'string' | ||||||
&& 'text' in data.items[0] | ||||||
&& 'checked' in data.items[0] | ||||||
&& typeof data.items[0].text === 'string' | ||||||
&& typeof data.items[0].checked === 'boolean' | ||||||
); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Method that checks if passed data is related to the legacy format and normalizes it | ||||||
* @param data - data to be checked | ||||||
* @returns - normalized data, ready to be used by Nested List tool | ||||||
*/ | ||||||
export default function normalizeData(data: ListData | OldListData): ListData { | ||||||
export default function normalizeData(data: ListData | OldListData | OldChecklistData): ListData { | ||||||
const normalizedDataItems: ListItem[] = []; | ||||||
|
||||||
if (instanceOfListData(data)) { | ||||||
|
@@ -30,6 +45,21 @@ export default function normalizeData(data: ListData | OldListData): ListData { | |||||
style: data.style, | ||||||
items: normalizedDataItems, | ||||||
}; | ||||||
} else if (instanceOfChecklistData(data)) { | ||||||
data.items.forEach((item) => { | ||||||
normalizedDataItems.push({ | ||||||
content: item.text, | ||||||
meta: { | ||||||
checked: item.checked, | ||||||
}, | ||||||
items: [], | ||||||
}); | ||||||
}); | ||||||
|
||||||
return { | ||||||
style: 'checklist', | ||||||
items: normalizedDataItems, | ||||||
}; | ||||||
} else { | ||||||
return data; | ||||||
} | ||||||
|
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.
description is unclear