Skip to content

Commit

Permalink
internal/frontend: add NestedModules field to Directory struct
Browse files Browse the repository at this point in the history
This change adds NestedModules to the directory struct in order to later
render the data in the subdirectories page of a package. We also modify
the createDirectory function to take in a nestedModules parameter.

Updates golang/go#38596

Change-Id: I9bcfc1f2aa37ac0b03b5def4b237473310690af6
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/254018
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
  • Loading branch information
Miguel Acero committed Sep 11, 2020
1 parent 640a34b commit a470123
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions internal/frontend/directory.go
Expand Up @@ -34,7 +34,8 @@ type DirectoryHeader struct {
// Directory contains information for an individual directory.
type Directory struct {
DirectoryHeader
Packages []*Package
Packages []*Package
NestedModules []*internal.ModuleInfo
}

// serveDirectoryPage serves a directory view for a directory in a module
Expand Down Expand Up @@ -110,7 +111,11 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, um *inte
header := createDirectoryHeader(um.Path, mi, um.Licenses)
return &Directory{DirectoryHeader: *header}, nil
}
return createDirectory(um.Path, mi, u.Subdirectories, um.Licenses, includeDirPath)
nestedModules, err := ds.GetNestedModules(ctx, um.Path)
if err != nil {
return nil, err
}
return createDirectory(um.Path, mi, u.Subdirectories, nestedModules, um.Licenses, includeDirPath)
}

// createDirectory constructs a *Directory for the given dirPath.
Expand All @@ -122,7 +127,7 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, um *inte
// the module path. However, on the package and directory view's
// "Subdirectories" tab, we do not want to include packages whose import paths
// are the same as the dirPath.
func createDirectory(dirPath string, mi *internal.ModuleInfo, pkgMetas []*internal.PackageMeta,
func createDirectory(dirPath string, mi *internal.ModuleInfo, pkgMetas []*internal.PackageMeta, nestedModules []*internal.ModuleInfo,
licmetas []*licenses.Metadata, includeDirPath bool) (_ *Directory, err error) {
var packages []*Package
for _, pm := range pkgMetas {
Expand All @@ -146,6 +151,7 @@ func createDirectory(dirPath string, mi *internal.ModuleInfo, pkgMetas []*intern
return &Directory{
DirectoryHeader: *header,
Packages: packages,
NestedModules: nestedModules,
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion internal/frontend/directory_test.go
Expand Up @@ -57,7 +57,8 @@ func TestFetchDirectoryDetails(t *testing.T) {
Path: dirPath,
URL: constructDirectoryURL(dirPath, mi.ModulePath, linkVersion(mi.Version, mi.ModulePath)),
},
Packages: wantPkgs,
Packages: wantPkgs,
NestedModules: nil,
}
if diff := cmp.Diff(want, got, cmp.AllowUnexported(safehtml.Identifier{})); diff != "" {
t.Errorf("fetchDirectoryDetails(ctx, %q, %q, %q) mismatch (-want +got):\n%s", dirPath, modulePath, version, diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/frontend/legacy_directory.go
Expand Up @@ -66,5 +66,5 @@ func legacyCreateDirectory(dbDir *internal.LegacyDirectory, licmetas []*licenses
newPkg := packageMetaFromLegacyPackage(pkg)
packages = append(packages, newPkg)
}
return createDirectory(dbDir.Path, &dbDir.ModuleInfo, packages, licmetas, includeDirPath)
return createDirectory(dbDir.Path, &dbDir.ModuleInfo, packages, nil, licmetas, includeDirPath)
}

0 comments on commit a470123

Please sign in to comment.