-
Notifications
You must be signed in to change notification settings - Fork 1
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
Tag Insertion Dialog #267
Merged
Merged
Tag Insertion Dialog #267
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5bd87d1
Create the tag insertion dialog outline
braxtonhall 3b6d692
Merge branch 'main' into insert-tags
braxtonhall 9a487ae
#212 Hook up the tag insertion dialog to tag validation
braxtonhall 40d78cb
#212 Avoid naming collision with author page tag insertion
braxtonhall ce88e0f
#212 Move some files around for cohesion
braxtonhall e8be0b6
#212 Make insert tags the first option when there are bad tags found
braxtonhall ce52e70
#212 Make the tag parser return all the sheet metadata it can
braxtonhall 4cb4522
#212 Implement nesting with the dialog
braxtonhall a657320
#212 Make the modal scrollable
braxtonhall 2adcc24
#212 Complete the insert tag dialog
braxtonhall 6dc2a19
Delete unused Dialog ui element
braxtonhall 1612057
DP-750: Inline some code that's only called once
braxtonhall 7cd39e9
Trim tags that you read from sheets
braxtonhall 6c02912
Comment out tag insertion for now
braxtonhall 097991e
#212 Rename the confirmation method becuase it doesn't just do confir…
braxtonhall 32a2ba4
#267 Remove unused code
braxtonhall 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
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,33 +1,41 @@ | ||
import {TagTree, TagTrees, WarnedTag} from "./types"; | ||
import {TagTree, TagNodes, WarnedTag, RawTagSheet, TagRoot} from "./types"; | ||
|
||
interface ParserOptions { | ||
rows: WarnedTag[][]; | ||
fromRow: number; | ||
depth: number; | ||
trees: TagTrees; | ||
parent?: TagTree; | ||
nodes: TagNodes; | ||
parent: TagTree | TagRoot; | ||
} | ||
|
||
const parseRows = ({rows, fromRow, depth, trees, parent}: ParserOptions): number => { | ||
const parseRows = ({rows, fromRow, depth, nodes, parent}: ParserOptions): number => { | ||
let row = fromRow; | ||
while (row < rows.length) { | ||
const {tag, warning} = rows[row][depth] ?? {}; | ||
if (tag) { | ||
const node = {tag, parent, warning}; | ||
// Keys in the tag trees map are lowercase for ez lookup later | ||
trees.set(tag.toLowerCase(), node); | ||
row = parseRows({rows, fromRow: row + 1, depth: depth + 1, trees, parent: node}); | ||
const trimmedTag = tag.trim(); | ||
const node = {name: trimmedTag, parent, warning, children: [], height: parent.height - 1}; | ||
parent.children.push(node); | ||
// TODO if nodes already contains this tag, we need to emit a warning somehow!!! see #214 | ||
// Keys in the tag nodes map are lowercase for ez lookup later | ||
nodes.set(trimmedTag.toLowerCase(), node); | ||
row = parseRows({rows, fromRow: row + 1, depth: depth + 1, nodes, parent: node}); | ||
} else { | ||
break; | ||
} | ||
} | ||
return row; | ||
}; | ||
|
||
const parseTree = (rows: WarnedTag[][]) => { | ||
const trees: TagTrees = new Map(); | ||
for (let fromRow = 0; fromRow < rows.length; fromRow = parseRows({rows, fromRow, depth: 0, trees}) + 1); | ||
return trees; | ||
const parseTags = (sheets: RawTagSheet[]) => { | ||
const nodes: TagNodes = new Map(); | ||
const roots = sheets.map((sheet) => { | ||
const {values: rows, ...rest} = sheet; | ||
const parent: TagRoot = {...rest, children: []}; | ||
for (let fromRow = 0; fromRow < rows.length; fromRow = parseRows({rows, fromRow, depth: 0, nodes, parent}) + 1); | ||
return parent; | ||
}); | ||
return {nodes, roots}; | ||
}; | ||
|
||
export {parseTree}; | ||
export {parseTags}; |
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,19 +1,30 @@ | ||
import {Range} from "../sheets"; | ||
|
||
type TagMapper = `${string}$TAG${string}`; | ||
type TagSheetDescriptor = {range: Range; mapper: TagMapper; name: string; cwRange?: Range; height: number}; | ||
|
||
type RawTagSheet = TagSheetDescriptor & {values: WarnedTag[][]}; | ||
|
||
type TagRoot = TagSheetDescriptor & {children: TagTree[]}; | ||
|
||
/** | ||
* A tag tree contains the properly cased tag at the root, | ||
* and a pointer to its parent in the tree | ||
*/ | ||
type TagTree = {tag: string; parent?: TagTree; warning: boolean}; | ||
type TagTree = {name: string; parent: TagTree | TagRoot; warning: boolean; children: TagTree[]; height: number}; | ||
|
||
/** | ||
* TagTrees is a map of lowercase tag to the tag subtree at that tag | ||
* TagNodes is a map of lowercase tag to the tag subtree at that tag | ||
* It contains every subtree of the complete tag tree | ||
*/ | ||
type TagTrees = Map<string, TagTree>; | ||
type TagNodes = Map<string, TagTree>; | ||
|
||
type Tags = {nodes: TagNodes; roots: TagRoot[]}; | ||
|
||
interface TagSearchOptions { | ||
noCache: boolean; | ||
} | ||
|
||
type WarnedTag = {tag: string; warning: boolean}; | ||
|
||
export {WarnedTag, TagTree, TagTrees, TagSearchOptions}; | ||
export {WarnedTag, TagTree, TagRoot, TagNodes, TagSearchOptions, RawTagSheet, TagSheetDescriptor, TagMapper, Tags}; |
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
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
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.
how often does this code get run? and what would the user do with this information if we show them the modal?
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.
I think maybe the modal should happen at a later step.
For example, when adding ancestor tags.
Or maybe? Instead of a tree its a network, and we just go for it and add all ancestors on multiple paths?