1. 11 May, 2021 11 commits
    • Robert Knight's avatar
      Replace `document.title` as a fallback for title in PDFs · 40eaf5c9
      Robert Knight authored
      Replace the usage of `document.title` as a way to get the document title
      if the PDF has no embedded title in either its _document info
      dictionary_ or _metadata stream_.
      
      In top-level frames using `document.title` (where `document` is the
      global HTML document, not the PDF) works because PDF.js sets the title
      based on the first non-empty value from:
      
       1. The embedded title
       2. The filename from the `Content-Disposition` header
       3. The last segment of the URL's path (eg. "test.pdf" in
          "https://example.com/test.pdf")
      
      When PDF.js is embedded in an iframe however, it does not set
      `document.title` by default. As a result, documents were ending up in
      Hypothesis with a generic "PDF.js viewer" title.
      
      This commit implements (roughly) the same logic that PDF.js uses to
      determine the value used to set `document.title`, in the case where the
      PDF has no embedded title. This means implementing steps (2) and (3)
      from the above list. The `Content-Disposition` filename is not exposed
      as a public property on `PDFViewerApplication`, so
      `PDFMetadata#getMetadata` was refactored to call the
      `pdfDocument.getMetadata` instead.
      
      Fixes https://github.com/hypothesis/client/issues/3372
      40eaf5c9
    • Robert Knight's avatar
      Add missing tests for various error paths · 96723e83
      Robert Knight authored
      I ignored one path that is only used in local development.
      96723e83
    • Robert Knight's avatar
      Convert `streamer` service to an ES class · ca5b5393
      Robert Knight authored
      Part of https://github.com/hypothesis/client/issues/3298
      
      Convert the `streamer` service to an ES class, modernize the code
      (functions => arrow functions, Promise chains => async/await) and
      improve the class documentation. There are no significant changes to the internal
      logic or API.
      ca5b5393
    • Robert Knight's avatar
      Simplify code using `filter`/`map` · 5ffeba96
      Robert Knight authored
      This makes it more obvious what is going on at a glance. Refactoring the
      code in this way revealed to TS a hazard where `newGroupId` could, at
      least based only on local reasoning, be null. In practice this shouldn't
      happen due to the contexts when the method is called, but I've added a
      check to be safe and keep TS happy.
      5ffeba96
    • Robert Knight's avatar
      Re-order `Group` constructor arguments · 97eae5d4
      Robert Knight authored
      Re-order the arguments based on an alphabetic sorting of the `@param`
      lines, which results in sorting by import path. This will make it more obvious
      where to slot in any new dependencies in future. Also sort the field
      initialization to match.
      97eae5d4
    • Robert Knight's avatar
      Type a reference to the groups service · ffa74228
      Robert Knight authored
      ffa74228
    • Robert Knight's avatar
      Convert `groups` service to an ES class · 82d434df
      Robert Knight authored
       - Convert the `groups` service to an ES class and the many closures in
         the constructor to private or public methods.
      
       - Remove the unused `all` and `get` methods of the groups service.
         These were trivial wrappers around store methods. UI components
         should use the store methods directly.
      82d434df
    • Robert Knight's avatar
      Improve some test descriptions and add a comment · 87956ee3
      Robert Knight authored
       - Clarify what a "non-file URL" means and add an additional test case
         for HTTPS URLs
       - Add a comment to clarify the precedence order of titles. The tests
         could more directly check that the expected precedence order is
         respected, but the logic here is expected to change very soon, so
         just add a comment for now.
      87956ee3
    • Robert Knight's avatar
      Convert remaining promise chains to async/await · c4612eda
      Robert Knight authored
      Convert remaining promise chains in `PDFMetadata` tests to async/await.
      c4612eda
    • Robert Knight's avatar
      Refactor `getMetadata` tests · bfe5d42b
      Robert Knight authored
       - Convert promise chains to async/await
      
       - Add missing tests to check that the PDF URL and fingerprint URL
         appear in the object returned by `getMetadata`. These were previously
         tested indirectly in other tests.
      
       - Change tests to only check the specific properties of the returned
         object that are of interest. This reduces the changes needed when
         tests change unrelated parts of the output.
      bfe5d42b
    • Robert Knight's avatar
      Refactor test setup in `PDFMetadata` tests · 1b539b87
      Robert Knight authored
      Refactor the setup steps in PDFMetadata tests to make it easier
      to customize the PDF metadata exposed by the fake PDF.js environment.
      Instead of creating a fake `PDFViewerApplication` and `PDFMetadata`
      instance before each test, provide a helper function that creates both
      using the provided metadata.
      1b539b87
  2. 10 May, 2021 19 commits
  3. 07 May, 2021 5 commits
    • Robert Knight's avatar
      Change callback prop return type from `any` to `void` · 47e346e0
      Robert Knight authored
      This ensures that the component doesn't attempt to call the prop and use
      the result.
      47e346e0
    • Robert Knight's avatar
      Adjust condition ordering · 79be98b0
      Robert Knight authored
      As noted in PR review, checking for a valid annotation first seems more
      sensible.
      79be98b0
    • Robert Knight's avatar
      Correct a typo · 93700b5e
      Robert Knight authored
      93700b5e
    • Robert Knight's avatar
      Make service-using components typecheck correctly · 4be722ea
      Robert Knight authored
      Previously all components that used injected services did not have their
      usage type-checked because `withServices` returned `any`.
      
      This commit refactors the API of `withServices` to make it easier to
      typecheck and adds types. The major API change is that the list of injected
      services is now passed as a second argument to `withServices` rather
      than by setting an `injectedProps` property on the component. This makes
      it easy to infer that the component returned by `withServices(Widget,
      ['serviceA', 'serviceB'])` has the same props as `Widget` but without
      `serviceA` or `serviceB`.
      
      Making these changes also turned up a handful of mistakes in existing
      types which are fixed here:
      
       - Correct `auth` type used by `HelpPanel`
       - Correct type of `thread` prop used by `ThreadCard`
       - Correct optionality of boolean arguments in callbacks to `Excerpt`
       - Change `showActions` logic in `Annotation` to make it more obvious
         to TS that the actions are only shown when there is an annotation
       - Remove unused props passed to `GroupList`
      
      Additionally there was a type error with TopBar's `auth` prop which is
      less trivial to fix, so I have punted it to a future commit.
      4be722ea
    • Robert Knight's avatar
      Fix prop typechecking for `TopBar` component · 1a447624
      Robert Knight authored
      The type of the `props` argument to `TopBar` was not specified, so its
      props were not type-checked. Specifying a type for `props` turned up
      several mistakes in other types.
      
       - Specify the type of the `props` object so that the props are actually
         type-checked
       - Add missing `status` field to `AuthState` type
       - Correctly set the optionality of various props
      1a447624
  4. 06 May, 2021 5 commits