diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index d8fb26a26..059af615b 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -15,7 +15,6 @@ import qualified Data.List as List import qualified Data.Map as Map hiding (null) import Renderer import Source hiding (null) -import SourceSpan import Syntax as S import Term import Patch @@ -65,9 +64,7 @@ toc blobs diff = TOCOutput $ Map.fromList [ summaries = diffTOC blobs diff diffTOC :: (StringConv leaf Text, DefaultFields fields) => Both SourceBlob -> SyntaxDiff leaf fields -> [JSONSummary] -diffTOC blobs diff = do - noDupes <- removeDupes (diffToTOCSummaries (source <$> blobs) diff) - toJSONSummaries noDupes +diffTOC blobs diff = removeDupes (diffToTOCSummaries (source <$> blobs) diff) >>= toJSONSummaries where removeDupes :: [TOCSummary DiffInfo] -> [TOCSummary DiffInfo] removeDupes = foldl' (\xs x -> case (x `elem` xs, x `findSimilarSummaryIndex` xs) of @@ -75,16 +72,15 @@ diffTOC blobs diff = do (False, Nothing) -> xs <> [x] (_, Just n) -> let - (a, _ : b) = List.splitAt n xs - name = case parentInfo x of - (Summarizable _ name _ _) -> name - _ -> "xx" - item = x { parentInfo = Summarizable C.Function name SourceSpan.emptySourceSpan "modified" } + (a, existingItem : b) = List.splitAt n xs + (Summarizable category name sourceSpan _) = parentInfo existingItem + replacement = x { parentInfo = Summarizable category name sourceSpan "modified" } in - a <> (item : b) + a <> (replacement : b) ) [] findSimilarSummaryIndex summary = List.findIndex (isSimilarSummary summary) isSimilarSummary a b = case (parentInfo a, parentInfo b) of + -- TODO: Only do this for methods in the same source file? (Summarizable _ nameA _ _, Summarizable _ nameB _ _) -> toLower nameA == toLower nameB (_, _) -> False diff --git a/test.A.js b/test.A.js new file mode 100644 index 000000000..6c4442952 --- /dev/null +++ b/test.A.js @@ -0,0 +1,43 @@ +/* @flow */ + +import $ from '../jquery' +import cast from '../typecast' +import {on} from 'delegated-events' +import {submit} from '../form' + +let allowSubmit = false + +function performHealthcheck() { + const repoName = cast(document.getElementById('showcase_item_name_with_owner'), HTMLInputElement).value + const submitButton = cast(document.getElementById('submit'), HTMLButtonElement) + const hiddenForm = cast(document.getElementsByClassName('js-submit-health-check')[0], HTMLFormElement) + const targetRepoName = cast(document.getElementById('repo_name'), HTMLInputElement) + document.getElementById("js-health").innerHTML = "Performing health check..." + targetRepoName.value = repoName + submitButton.disabled = false + allowSubmit = true + submit(hiddenForm) +} + +function test() { + console.log("hi"); + return 0; +} + +on('submit', '#new_showcase_item', function(e) { + if (!allowSubmit) { e.preventDefault() } +}) + +$(document).on('ajaxSuccess', '.js-health', function(event, xhr, settings, data) { + this.innerHTML = data +}) + +on('focusout', '#showcase_item_name_with_owner', function() { + performHealthcheck() +}) + +on('focusin', '#showcase_item_body', function() { + if (cast(document.getElementById('showcase_item_name_with_owner'), HTMLInputElement).type === 'hidden') { + performHealthcheck() + } +}) diff --git a/test.B.js b/test.B.js new file mode 100644 index 000000000..8c2d76650 --- /dev/null +++ b/test.B.js @@ -0,0 +1,49 @@ +/* @flow */ + +import cast from '../typecast' +import {changeValue} from '../form' +import {fetchSafeDocumentFragment} from '../fetch' +import {observe} from '../observe' + +function performHealthCheck(container, repoName) { + const formCheck = cast(document.querySelector('.js-repo-health-check'), HTMLFormElement) + const nameToCheck = cast(formCheck.querySelector('.js-repo-health-name'), HTMLInputElement) + nameToCheck.value = repoName + + const completedIndicator = cast(container.querySelector('.js-repo-health-check-completed'), HTMLInputElement) + changeValue(completedIndicator, '') + container.classList.remove('d-none') + container.classList.add('is-loading') + + return fetchSafeDocumentFragment(document, formCheck.action, { + method: 'POST', + body: new FormData(formCheck), + }).then(html => { + const results = cast(container.querySelector('.js-repo-health-results'), HTMLElement) + results.innerHTML = '' + results.appendChild(html) + + container.classList.remove('is-loading') + changeValue(completedIndicator, '1') + }) +} + +function test() { + return 0; +} + +observe('.js-repo-health', function(container: HTMLElement) { + const form = cast(container.closest('form'), HTMLFormElement) + const repoInput = cast(form.querySelector('.js-repo-name'), HTMLInputElement) + + if (repoInput.type === 'hidden') { + const description = cast(form.querySelector('.js-comment-field'), HTMLTextAreaElement) + description.addEventListener('focus', () => { + performHealthCheck(container, repoInput.value) + }) + } else { + repoInput.addEventListener('change', () => { + performHealthCheck(container, repoInput.value) + }) + } +})