Skip to content

Commit a470123

Browse files
author
Miguel Acero
committed
internal/frontend: add NestedModules field to Directory struct
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 <[email protected]> Reviewed-by: Julie Qiu <[email protected]>
1 parent 640a34b commit a470123

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

internal/frontend/directory.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ type DirectoryHeader struct {
3434
// Directory contains information for an individual directory.
3535
type Directory struct {
3636
DirectoryHeader
37-
Packages []*Package
37+
Packages []*Package
38+
NestedModules []*internal.ModuleInfo
3839
}
3940

4041
// serveDirectoryPage serves a directory view for a directory in a module
@@ -110,7 +111,11 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, um *inte
110111
header := createDirectoryHeader(um.Path, mi, um.Licenses)
111112
return &Directory{DirectoryHeader: *header}, nil
112113
}
113-
return createDirectory(um.Path, mi, u.Subdirectories, um.Licenses, includeDirPath)
114+
nestedModules, err := ds.GetNestedModules(ctx, um.Path)
115+
if err != nil {
116+
return nil, err
117+
}
118+
return createDirectory(um.Path, mi, u.Subdirectories, nestedModules, um.Licenses, includeDirPath)
114119
}
115120

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

internal/frontend/directory_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func TestFetchDirectoryDetails(t *testing.T) {
5757
Path: dirPath,
5858
URL: constructDirectoryURL(dirPath, mi.ModulePath, linkVersion(mi.Version, mi.ModulePath)),
5959
},
60-
Packages: wantPkgs,
60+
Packages: wantPkgs,
61+
NestedModules: nil,
6162
}
6263
if diff := cmp.Diff(want, got, cmp.AllowUnexported(safehtml.Identifier{})); diff != "" {
6364
t.Errorf("fetchDirectoryDetails(ctx, %q, %q, %q) mismatch (-want +got):\n%s", dirPath, modulePath, version, diff)

internal/frontend/legacy_directory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ func legacyCreateDirectory(dbDir *internal.LegacyDirectory, licmetas []*licenses
6666
newPkg := packageMetaFromLegacyPackage(pkg)
6767
packages = append(packages, newPkg)
6868
}
69-
return createDirectory(dbDir.Path, &dbDir.ModuleInfo, packages, licmetas, includeDirPath)
69+
return createDirectory(dbDir.Path, &dbDir.ModuleInfo, packages, nil, licmetas, includeDirPath)
7070
}

0 commit comments

Comments
 (0)