From 77cf8208fe792bfdd9aa88895af7a4f94bd8f36f Mon Sep 17 00:00:00 2001 From: Tosone Date: Wed, 12 Jul 2023 00:07:23 +0800 Subject: [PATCH] :sparkles: Fix toast close automatic --- pkg/handlers/apidocs/docs.go | 138 +++++++++++------- pkg/handlers/apidocs/swagger.json | 138 +++++++++++------- pkg/handlers/apidocs/swagger.yaml | 96 ++++++------ pkg/handlers/namespaces/namespaces_delete.go | 1 + pkg/handlers/namespaces/namespaces_get.go | 7 +- pkg/handlers/namespaces/namespaces_list.go | 24 +-- pkg/handlers/namespaces/namespaces_post.go | 1 + pkg/handlers/namespaces/namespaces_put.go | 2 +- pkg/handlers/repositories/repositories_get.go | 15 +- .../repositories/repositories_list.go | 29 ++-- pkg/types/namespace.go | 16 -- pkg/types/repository.go | 52 +++++-- web/package.json | 5 +- web/src/App.tsx | 3 +- web/src/components/Notification/index.tsx | 1 - web/src/interfaces/index.ts | 3 + web/src/pages/Home/index.tsx | 24 +-- web/src/pages/Namespace/DaemonTask.tsx | 2 +- web/src/pages/Namespace/Users.tsx | 2 +- web/src/pages/Namespace/Webhook.tsx | 2 +- web/src/pages/Namespace/index.tsx | 29 +--- web/src/pages/Repository/TableItem.tsx | 30 ++-- web/src/pages/Repository/index.tsx | 3 + web/yarn.lock | 25 +--- 24 files changed, 328 insertions(+), 320 deletions(-) diff --git a/pkg/handlers/apidocs/docs.go b/pkg/handlers/apidocs/docs.go index 7bb5eec0..8da52964 100644 --- a/pkg/handlers/apidocs/docs.go +++ b/pkg/handlers/apidocs/docs.go @@ -178,7 +178,19 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/types.GetNamespaceResponse" + "$ref": "#/definitions/types.NamespaceItem" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/xerrors.ErrCode" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/xerrors.ErrCode" } } } @@ -211,11 +223,8 @@ const docTemplate = `{ } ], "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/types.GetNamespaceResponse" - } + "204": { + "description": "No Content" } } }, @@ -597,55 +606,6 @@ const docTemplate = `{ } } }, - "types.GetNamespaceResponse": { - "type": "object", - "properties": { - "created_at": { - "type": "string", - "example": "2006-01-02 15:04:05" - }, - "description": { - "type": "string", - "example": "i am just description" - }, - "id": { - "type": "integer", - "example": 1 - }, - "name": { - "type": "string", - "example": "test" - }, - "repository_count": { - "type": "integer", - "example": 10 - }, - "repository_limit": { - "type": "integer", - "example": 10 - }, - "size": { - "type": "integer", - "example": 10000 - }, - "size_limit": { - "type": "integer", - "example": 10000 - }, - "tag_count": { - "type": "integer", - "example": 10 - }, - "tag_limit": { - "type": "integer", - "example": 10000 - }, - "updated_at": { - "type": "string", - "example": "2006-01-02 15:04:05" - } - } - }, "types.NamespaceItem": { "type": "object", "properties": { @@ -692,6 +652,14 @@ const docTemplate = `{ "updated_at": { "type": "string", "example": "2006-01-02 15:04:05" + }, + "visibility": { + "allOf": [ + { + "$ref": "#/definitions/enums.Visibility" + } + ], + "example": "private" } } }, @@ -745,9 +713,35 @@ const docTemplate = `{ "name" ], "properties": { + "description": { + "type": "string", + "maxLength": 30, + "example": "i am just description" + }, "name": { "type": "string", "example": "test" + }, + "overview": { + "type": "string", + "maxLength": 3000, + "example": "i am just overview" + }, + "size_limit": { + "type": "integer", + "example": 10000 + }, + "tag_limit": { + "type": "integer", + "example": 10000 + }, + "visibility": { + "allOf": [ + { + "$ref": "#/definitions/enums.Visibility" + } + ], + "example": "public" } } }, @@ -798,6 +792,22 @@ const docTemplate = `{ "type": "string", "maxLength": 3000, "example": "i am just overview" + }, + "size_limit": { + "type": "integer", + "example": 10000 + }, + "tag_limit": { + "type": "integer", + "example": 10000 + }, + "visibility": { + "allOf": [ + { + "$ref": "#/definitions/enums.Visibility" + } + ], + "example": "public" } } }, @@ -817,6 +827,11 @@ const docTemplate = `{ "type": "string", "example": "2006-01-02 15:04:05" }, + "description": { + "type": "string", + "maxLength": 30, + "example": "i am just description" + }, "id": { "type": "integer", "example": 1 @@ -825,6 +840,11 @@ const docTemplate = `{ "type": "string", "example": "busybox" }, + "overview": { + "type": "string", + "maxLength": 3000, + "example": "i am just overview" + }, "size": { "type": "integer", "example": 10000 @@ -844,6 +864,14 @@ const docTemplate = `{ "updated_at": { "type": "string", "example": "2006-01-02 15:04:05" + }, + "visibility": { + "allOf": [ + { + "$ref": "#/definitions/enums.Visibility" + } + ], + "example": "private" } } }, diff --git a/pkg/handlers/apidocs/swagger.json b/pkg/handlers/apidocs/swagger.json index 8f3e68f2..a3f2b017 100644 --- a/pkg/handlers/apidocs/swagger.json +++ b/pkg/handlers/apidocs/swagger.json @@ -169,7 +169,19 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/types.GetNamespaceResponse" + "$ref": "#/definitions/types.NamespaceItem" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/xerrors.ErrCode" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/xerrors.ErrCode" } } } @@ -202,11 +214,8 @@ } ], "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/types.GetNamespaceResponse" - } + "204": { + "description": "No Content" } } }, @@ -588,55 +597,6 @@ } } }, - "types.GetNamespaceResponse": { - "type": "object", - "properties": { - "created_at": { - "type": "string", - "example": "2006-01-02 15:04:05" - }, - "description": { - "type": "string", - "example": "i am just description" - }, - "id": { - "type": "integer", - "example": 1 - }, - "name": { - "type": "string", - "example": "test" - }, - "repository_count": { - "type": "integer", - "example": 10 - }, - "repository_limit": { - "type": "integer", - "example": 10 - }, - "size": { - "type": "integer", - "example": 10000 - }, - "size_limit": { - "type": "integer", - "example": 10000 - }, - "tag_count": { - "type": "integer", - "example": 10 - }, - "tag_limit": { - "type": "integer", - "example": 10000 - }, - "updated_at": { - "type": "string", - "example": "2006-01-02 15:04:05" - } - } - }, "types.NamespaceItem": { "type": "object", "properties": { @@ -683,6 +643,14 @@ "updated_at": { "type": "string", "example": "2006-01-02 15:04:05" + }, + "visibility": { + "allOf": [ + { + "$ref": "#/definitions/enums.Visibility" + } + ], + "example": "private" } } }, @@ -736,9 +704,35 @@ "name" ], "properties": { + "description": { + "type": "string", + "maxLength": 30, + "example": "i am just description" + }, "name": { "type": "string", "example": "test" + }, + "overview": { + "type": "string", + "maxLength": 3000, + "example": "i am just overview" + }, + "size_limit": { + "type": "integer", + "example": 10000 + }, + "tag_limit": { + "type": "integer", + "example": 10000 + }, + "visibility": { + "allOf": [ + { + "$ref": "#/definitions/enums.Visibility" + } + ], + "example": "public" } } }, @@ -789,6 +783,22 @@ "type": "string", "maxLength": 3000, "example": "i am just overview" + }, + "size_limit": { + "type": "integer", + "example": 10000 + }, + "tag_limit": { + "type": "integer", + "example": 10000 + }, + "visibility": { + "allOf": [ + { + "$ref": "#/definitions/enums.Visibility" + } + ], + "example": "public" } } }, @@ -808,6 +818,11 @@ "type": "string", "example": "2006-01-02 15:04:05" }, + "description": { + "type": "string", + "maxLength": 30, + "example": "i am just description" + }, "id": { "type": "integer", "example": 1 @@ -816,6 +831,11 @@ "type": "string", "example": "busybox" }, + "overview": { + "type": "string", + "maxLength": 3000, + "example": "i am just overview" + }, "size": { "type": "integer", "example": 10000 @@ -835,6 +855,14 @@ "updated_at": { "type": "string", "example": "2006-01-02 15:04:05" + }, + "visibility": { + "allOf": [ + { + "$ref": "#/definitions/enums.Visibility" + } + ], + "example": "private" } } }, diff --git a/pkg/handlers/apidocs/swagger.yaml b/pkg/handlers/apidocs/swagger.yaml index f35e14bf..525873cc 100644 --- a/pkg/handlers/apidocs/swagger.yaml +++ b/pkg/handlers/apidocs/swagger.yaml @@ -17,42 +17,6 @@ definitions: example: 1 type: integer type: object - types.GetNamespaceResponse: - properties: - created_at: - example: "2006-01-02 15:04:05" - type: string - description: - example: i am just description - type: string - id: - example: 1 - type: integer - name: - example: test - type: string - repository_count: - example: 10 - type: integer - repository_limit: - example: 10 - type: integer - size: - example: 10000 - type: integer - size_limit: - example: 10000 - type: integer - tag_count: - example: 10 - type: integer - tag_limit: - example: 10000 - type: integer - updated_at: - example: "2006-01-02 15:04:05" - type: string - type: object types.NamespaceItem: properties: created_at: @@ -88,6 +52,10 @@ definitions: updated_at: example: "2006-01-02 15:04:05" type: string + visibility: + allOf: + - $ref: '#/definitions/enums.Visibility' + example: private type: object types.PostNamespaceRequest: properties: @@ -121,9 +89,27 @@ definitions: type: object types.PostRepositoryRequestSwagger: properties: + description: + example: i am just description + maxLength: 30 + type: string name: example: test type: string + overview: + example: i am just overview + maxLength: 3000 + type: string + size_limit: + example: 10000 + type: integer + tag_limit: + example: 10000 + type: integer + visibility: + allOf: + - $ref: '#/definitions/enums.Visibility' + example: public required: - name type: object @@ -160,6 +146,16 @@ definitions: example: i am just overview maxLength: 3000 type: string + size_limit: + example: 10000 + type: integer + tag_limit: + example: 10000 + type: integer + visibility: + allOf: + - $ref: '#/definitions/enums.Visibility' + example: public type: object types.PutRepositoryResponse: properties: @@ -172,12 +168,20 @@ definitions: created_at: example: "2006-01-02 15:04:05" type: string + description: + example: i am just description + maxLength: 30 + type: string id: example: 1 type: integer name: example: busybox type: string + overview: + example: i am just overview + maxLength: 3000 + type: string size: example: 10000 type: integer @@ -193,6 +197,10 @@ definitions: updated_at: example: "2006-01-02 15:04:05" type: string + visibility: + allOf: + - $ref: '#/definitions/enums.Visibility' + example: private type: object xerrors.ErrCode: properties: @@ -341,7 +349,15 @@ paths: "200": description: OK schema: - $ref: '#/definitions/types.GetNamespaceResponse' + $ref: '#/definitions/types.NamespaceItem' + "404": + description: Not Found + schema: + $ref: '#/definitions/xerrors.ErrCode' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/xerrors.ErrCode' security: - BasicAuth: [] summary: Get namespace @@ -360,10 +376,8 @@ paths: produces: - application/json responses: - "200": - description: OK - schema: - $ref: '#/definitions/types.GetNamespaceResponse' + "204": + description: No Content security: - BasicAuth: [] summary: Update namespace diff --git a/pkg/handlers/namespaces/namespaces_delete.go b/pkg/handlers/namespaces/namespaces_delete.go index 80ac6b0a..c647ceff 100644 --- a/pkg/handlers/namespaces/namespaces_delete.go +++ b/pkg/handlers/namespaces/namespaces_delete.go @@ -35,6 +35,7 @@ import ( // @Produce json // @Router /namespaces/{id} [delete] // @Success 204 +// @Failure 500 {object} xerrors.ErrCode func (h *handlers) DeleteNamespace(c echo.Context) error { ctx := log.Logger.WithContext(c.Request().Context()) diff --git a/pkg/handlers/namespaces/namespaces_get.go b/pkg/handlers/namespaces/namespaces_get.go index 84173c64..69827a03 100644 --- a/pkg/handlers/namespaces/namespaces_get.go +++ b/pkg/handlers/namespaces/namespaces_get.go @@ -36,7 +36,9 @@ import ( // @Produce json // @Router /namespaces/{id} [get] // @Param id path string true "Namespace ID" -// @Success 200 {object} types.GetNamespaceResponse +// @Success 200 {object} types.NamespaceItem +// @Failure 404 {object} xerrors.ErrCode +// @Failure 500 {object} xerrors.ErrCode func (h *handlers) GetNamespace(c echo.Context) error { ctx := log.Logger.WithContext(c.Request().Context()) @@ -72,10 +74,11 @@ func (h *handlers) GetNamespace(c echo.Context) error { return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeInternalError, err.Error()) } - return c.JSON(http.StatusOK, types.GetNamespaceResponse{ + return c.JSON(http.StatusOK, types.NamespaceItem{ ID: namespace.ID, Name: namespace.Name, Description: namespace.Description, + Visibility: namespace.Visibility, Size: namespace.Size, SizeLimit: namespace.SizeLimit, RepositoryCount: repositoryMapCount[namespace.ID], diff --git a/pkg/handlers/namespaces/namespaces_list.go b/pkg/handlers/namespaces/namespaces_list.go index e138adc4..42abccc8 100644 --- a/pkg/handlers/namespaces/namespaces_list.go +++ b/pkg/handlers/namespaces/namespaces_list.go @@ -39,6 +39,7 @@ import ( // @Param method query string false "sort method" Enums(asc, desc) // @Param name query string false "search namespace with name" // @Success 200 {object} types.CommonList{items=[]types.NamespaceItem} +// @Failure 500 {object} xerrors.ErrCode func (h *handlers) ListNamespace(c echo.Context) error { ctx := log.Logger.WithContext(c.Request().Context()) @@ -57,25 +58,6 @@ func (h *handlers) ListNamespace(c echo.Context) error { return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeInternalError, err.Error()) } - var namespaceIDs = make([]int64, 0, len(namespaces)) - for _, ns := range namespaces { - namespaceIDs = append(namespaceIDs, ns.ID) - } - - repositoryService := h.repositoryServiceFactory.New() - repositoryMapCount, err := repositoryService.CountByNamespace(ctx, namespaceIDs) - if err != nil { - log.Error().Err(err).Msg("Count repository failed") - return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeInternalError, err.Error()) - } - - tagService := h.tagServiceFactory.New() - tagMapCount, err := tagService.CountByNamespace(ctx, namespaceIDs) - if err != nil { - log.Error().Err(err).Msg("Count tag failed") - return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeInternalError, err.Error()) - } - var resp = make([]any, 0, len(namespaces)) for _, ns := range namespaces { resp = append(resp, types.NamespaceItem{ @@ -86,9 +68,9 @@ func (h *handlers) ListNamespace(c echo.Context) error { Size: ns.Size, SizeLimit: ns.SizeLimit, RepositoryLimit: ns.RepositoryLimit, - RepositoryCount: repositoryMapCount[ns.ID], + RepositoryCount: ns.RepositoryCount, TagLimit: ns.TagLimit, - TagCount: tagMapCount[ns.ID], + TagCount: ns.TagCount, CreatedAt: ns.CreatedAt.Format(consts.DefaultTimePattern), UpdatedAt: ns.UpdatedAt.Format(consts.DefaultTimePattern), }) diff --git a/pkg/handlers/namespaces/namespaces_post.go b/pkg/handlers/namespaces/namespaces_post.go index d1af8ea3..e9072d5a 100644 --- a/pkg/handlers/namespaces/namespaces_post.go +++ b/pkg/handlers/namespaces/namespaces_post.go @@ -43,6 +43,7 @@ import ( // @security BasicAuth // @Success 201 {object} types.PostNamespaceResponse // @Failure 400 {object} xerrors.ErrCode +// @Failure 500 {object} xerrors.ErrCode func (h *handlers) PostNamespace(c echo.Context) error { ctx := log.Logger.WithContext(c.Request().Context()) diff --git a/pkg/handlers/namespaces/namespaces_put.go b/pkg/handlers/namespaces/namespaces_put.go index 8518bfaf..215a99f3 100644 --- a/pkg/handlers/namespaces/namespaces_put.go +++ b/pkg/handlers/namespaces/namespaces_put.go @@ -38,7 +38,7 @@ import ( // @Produce json // @Router /namespaces/{id} [put] // @Param message body types.PutNamespaceRequestSwagger true "Namespace object" -// @Success 200 {object} types.GetNamespaceResponse +// @Success 204 func (h *handlers) PutNamespace(c echo.Context) error { ctx := log.Logger.WithContext(c.Request().Context()) diff --git a/pkg/handlers/repositories/repositories_get.go b/pkg/handlers/repositories/repositories_get.go index 8818203e..da312e04 100644 --- a/pkg/handlers/repositories/repositories_get.go +++ b/pkg/handlers/repositories/repositories_get.go @@ -24,6 +24,7 @@ import ( "github.com/ximager/ximager/pkg/consts" "github.com/ximager/ximager/pkg/types" "github.com/ximager/ximager/pkg/utils" + "github.com/ximager/ximager/pkg/utils/ptr" "github.com/ximager/ximager/pkg/xerrors" ) @@ -60,9 +61,15 @@ func (h *handlers) GetRepository(c echo.Context) error { } return c.JSON(http.StatusOK, types.RepositoryItem{ - ID: repository.ID, - Name: repository.Name, - CreatedAt: repository.CreatedAt.Format(consts.DefaultTimePattern), - UpdatedAt: repository.UpdatedAt.Format(consts.DefaultTimePattern), + ID: repository.ID, + Name: repository.Name, + Description: repository.Description, + Overview: ptr.Of(string(repository.Overview)), + Visibility: repository.Visibility, + SizeLimit: ptr.Of(repository.Size), + Size: ptr.Of(repository.Size), + TagCount: repository.TagCount, + CreatedAt: repository.CreatedAt.Format(consts.DefaultTimePattern), + UpdatedAt: repository.UpdatedAt.Format(consts.DefaultTimePattern), }) } diff --git a/pkg/handlers/repositories/repositories_list.go b/pkg/handlers/repositories/repositories_list.go index 437ac3de..6692317c 100644 --- a/pkg/handlers/repositories/repositories_list.go +++ b/pkg/handlers/repositories/repositories_list.go @@ -75,28 +75,19 @@ func (h *handlers) ListRepository(c echo.Context) error { return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeInternalError, err.Error()) } - var repositoryIDs = make([]int64, 0, len(repositories)) - for _, repository := range repositories { - repositoryIDs = append(repositoryIDs, repository.ID) - } - - tagService := h.tagServiceFactory.New() - tagMapCount, err := tagService.CountByRepository(ctx, repositoryIDs) - if err != nil { - log.Error().Err(err).Msg("Count tag from db failed") - return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeInternalError, err.Error()) - } - var resp = make([]any, 0, len(repositories)) for _, repository := range repositories { resp = append(resp, types.RepositoryItem{ - ID: repository.ID, - Name: repository.Name, - SizeLimit: ptr.Of(repository.Size), - Size: ptr.Of(repository.Size), - TagCount: tagMapCount[repository.ID], - CreatedAt: repository.CreatedAt.Format(consts.DefaultTimePattern), - UpdatedAt: repository.UpdatedAt.Format(consts.DefaultTimePattern), + ID: repository.ID, + Name: repository.Name, + Description: repository.Description, + Overview: ptr.Of(string(repository.Overview)), + Visibility: repository.Visibility, + SizeLimit: ptr.Of(repository.Size), + Size: ptr.Of(repository.Size), + TagCount: repository.TagCount, + CreatedAt: repository.CreatedAt.Format(consts.DefaultTimePattern), + UpdatedAt: repository.UpdatedAt.Format(consts.DefaultTimePattern), }) } total, err := repositoryService.CountRepository(ctx, namespaceObj.ID, req.Name) diff --git a/pkg/types/namespace.go b/pkg/types/namespace.go index 203f8c4f..0444f908 100644 --- a/pkg/types/namespace.go +++ b/pkg/types/namespace.go @@ -61,22 +61,6 @@ type GetNamespaceRequest struct { ID int64 `json:"id" param:"id" validate:"required,number"` } -// GetNamespaceResponse represents the response to get a namespace. -type GetNamespaceResponse struct { - ID int64 `json:"id" example:"1"` - Name string `json:"name" example:"test"` - Description *string `json:"description,omitempty" example:"i am just description"` - RepositoryLimit int64 `json:"repository_limit" example:"10"` - RepositoryCount int64 `json:"repository_count" example:"10"` - TagCount int64 `json:"tag_count" example:"10"` - TagLimit int64 `json:"tag_limit" example:"10000"` - Size int64 `json:"size" example:"10000"` - SizeLimit int64 `json:"size_limit" example:"10000"` - - CreatedAt string `json:"created_at" example:"2006-01-02 15:04:05"` - UpdatedAt string `json:"updated_at" example:"2006-01-02 15:04:05"` -} - // DeleteNamespaceRequest represents the request to delete a namespace. type DeleteNamespaceRequest struct { ID int64 `json:"id" param:"id" validate:"required,number" example:"1"` diff --git a/pkg/types/repository.go b/pkg/types/repository.go index e9868d0f..9f5f4ded 100644 --- a/pkg/types/repository.go +++ b/pkg/types/repository.go @@ -14,15 +14,19 @@ package types +import "github.com/ximager/ximager/pkg/types/enums" + // RepositoryItem represents a repository. type RepositoryItem struct { - ID int64 `json:"id" example:"1"` - Name string `json:"name" example:"busybox"` - - TagCount int64 `json:"tag_count" example:"100"` - TagLimit *int64 `json:"tag_limit" example:"1000"` - SizeLimit *int64 `json:"size_limit" example:"10000"` - Size *int64 `json:"size" example:"10000"` + ID int64 `json:"id" example:"1"` + Name string `json:"name" example:"busybox"` + Description *string `json:"description,omitempty" validate:"omitempty,max=30" example:"i am just description"` + Overview *string `json:"overview,omitempty" validate:"omitempty,max=3000" example:"i am just overview"` + Visibility enums.Visibility `json:"visibility" example:"private"` + TagCount int64 `json:"tag_count" example:"100"` + TagLimit *int64 `json:"tag_limit" example:"1000"` + SizeLimit *int64 `json:"size_limit" example:"10000"` + Size *int64 `json:"size" example:"10000"` CreatedAt string `json:"created_at" example:"2006-01-02 15:04:05"` UpdatedAt string `json:"updated_at" example:"2006-01-02 15:04:05"` @@ -51,13 +55,23 @@ type DeleteRepositoryRequest struct { // PostRepositoryRequest represents the request to create a repository. type PostRepositoryRequest struct { - Namespace string `json:"namespace" param:"namespace" validate:"required,min=2,max=20,is_valid_namespace" example:"test"` - Name string `json:"name" validate:"required" example:"test"` + Namespace string `json:"namespace" param:"namespace" validate:"required,min=2,max=20,is_valid_namespace" example:"test"` + Name string `json:"name" validate:"required" example:"test"` + Description *string `json:"description,omitempty" validate:"omitempty,max=30" example:"i am just description"` + Overview *string `json:"overview,omitempty" validate:"omitempty,max=3000" example:"i am just overview"` + SizeLimit *int64 `json:"size_limit,omitempty" validate:"omitempty,numeric" example:"10000"` + TagLimit *int64 `json:"tag_limit,omitempty" validate:"omitempty,numeric" example:"10000"` + Visibility *enums.Visibility `json:"visibility,omitempty" validate:"omitempty,is_valid_visibility" example:"public"` } // PostRepositoryRequestSwagger represents the request to create a repository. type PostRepositoryRequestSwagger struct { - Name string `json:"name" validate:"required" example:"test"` + Name string `json:"name" validate:"required" example:"test"` + Description *string `json:"description,omitempty" validate:"omitempty,max=30" example:"i am just description"` + Overview *string `json:"overview,omitempty" validate:"omitempty,max=3000" example:"i am just overview"` + SizeLimit *int64 `json:"size_limit,omitempty" validate:"omitempty,numeric" example:"10000"` + TagLimit *int64 `json:"tag_limit,omitempty" validate:"omitempty,numeric" example:"10000"` + Visibility *enums.Visibility `json:"visibility,omitempty" validate:"omitempty,is_valid_visibility" example:"public"` } // PostRepositoryResponse represents the response to create a repository. @@ -67,16 +81,22 @@ type PostRepositoryResponse struct { // PutRepositoryRequest represents the request to update a repository. type PutRepositoryRequest struct { - Namespace string `json:"namespace" param:"namespace" validate:"required,min=2,max=20,is_valid_namespace" example:"test"` - ID int64 `json:"id" param:"id" validate:"required,number" example:"1"` - Description *string `json:"description,omitempty" validate:"omitempty,max=300" example:"i am just description"` - Overview *string `json:"overview,omitempty" validate:"omitempty,max=3000" example:"i am just overview"` + Namespace string `json:"namespace" param:"namespace" validate:"required,min=2,max=20,is_valid_namespace" example:"test"` + ID int64 `json:"id" param:"id" validate:"required,number" example:"1"` + Description *string `json:"description,omitempty" validate:"omitempty,max=300" example:"i am just description"` + Overview *string `json:"overview,omitempty" validate:"omitempty,max=3000" example:"i am just overview"` + SizeLimit *int64 `json:"size_limit,omitempty" validate:"omitempty,numeric" example:"10000"` + TagLimit *int64 `json:"tag_limit,omitempty" validate:"omitempty,numeric" example:"10000"` + Visibility *enums.Visibility `json:"visibility,omitempty" validate:"omitempty,is_valid_visibility" example:"public"` } // PutRepositoryRequestSwagger represents the request to update a repository. type PutRepositoryRequestSwagger struct { - Description *string `json:"description,omitempty" validate:"omitempty,max=300" example:"i am just description"` - Overview *string `json:"overview,omitempty" validate:"omitempty,max=3000" example:"i am just overview"` + Description *string `json:"description,omitempty" validate:"omitempty,max=300" example:"i am just description"` + Overview *string `json:"overview,omitempty" validate:"omitempty,max=3000" example:"i am just overview"` + SizeLimit *int64 `json:"size_limit,omitempty" validate:"omitempty,numeric" example:"10000"` + TagLimit *int64 `json:"tag_limit,omitempty" validate:"omitempty,numeric" example:"10000"` + Visibility *enums.Visibility `json:"visibility,omitempty" validate:"omitempty,is_valid_visibility" example:"public"` } // PutRepositoryResponse represents the response to update a repository. diff --git a/web/package.json b/web/package.json index 8743039e..2498090f 100644 --- a/web/package.json +++ b/web/package.json @@ -16,11 +16,9 @@ "@tailwindcss/forms": "^0.5.3", "@tailwindcss/line-clamp": "^0.4.4", "@tailwindcss/typography": "^0.5.9", - "@yaireo/tagify": "^4.17.8", "axios": "^1.4.0", "dayjs": "^1.11.9", "human-format": "^1.2.0", - "prop-types": "^15.8.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^4.10.1", @@ -32,7 +30,6 @@ "@types/node": "^20.4.1", "@types/react": "^18.2.14", "@types/react-dom": "^18.2.6", - "@types/yaireo__tagify": "^4.17.0", "@vitejs/plugin-react-swc": "^3.3.2", "autoprefixer": "^10.4.14", "cssnano": "^6.0.1", @@ -41,6 +38,6 @@ "react-helmet-async": "^1.3.0", "tailwindcss": "^3.3.2", "typescript": "^5.1.6", - "vite": "^4.4.2" + "vite": "^4.4.3" } } diff --git a/web/src/App.tsx b/web/src/App.tsx index c42916f2..de4593b9 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -42,7 +42,8 @@ export default function App() { return ( <> - { - console.log("CHANGED:" - , e.detail.tagify.value // Array where each tag includes tagify's (needed) extra properties - , e.detail.tagify.getCleanValue() // Same as above, without the extra properties - , e.detail.value // a string representing the tags - ) - }, []) return ( @@ -82,13 +67,6 @@ export default function Home({ localServer }: { localServer: string }) { ))} - diff --git a/web/src/pages/Namespace/DaemonTask.tsx b/web/src/pages/Namespace/DaemonTask.tsx index 2bc1b29d..5076b1b0 100644 --- a/web/src/pages/Namespace/DaemonTask.tsx +++ b/web/src/pages/Namespace/DaemonTask.tsx @@ -56,7 +56,7 @@ export default function Repository({ localServer }: { localServer: string }) { - XImager - Repository + XImager - Namespace Daemon Task
diff --git a/web/src/pages/Namespace/Users.tsx b/web/src/pages/Namespace/Users.tsx index abfdcf86..30430819 100644 --- a/web/src/pages/Namespace/Users.tsx +++ b/web/src/pages/Namespace/Users.tsx @@ -56,7 +56,7 @@ export default function Repository({ localServer }: { localServer: string }) { - XImager - Repository + XImager - Namespace Users
diff --git a/web/src/pages/Namespace/Webhook.tsx b/web/src/pages/Namespace/Webhook.tsx index 387389fe..79bc0481 100644 --- a/web/src/pages/Namespace/Webhook.tsx +++ b/web/src/pages/Namespace/Webhook.tsx @@ -56,7 +56,7 @@ export default function Repository({ localServer }: { localServer: string }) { - XImager - Repository + XImager - Namespace Webhook
diff --git a/web/src/pages/Namespace/index.tsx b/web/src/pages/Namespace/index.tsx index 872150aa..de75f610 100644 --- a/web/src/pages/Namespace/index.tsx +++ b/web/src/pages/Namespace/index.tsx @@ -32,8 +32,6 @@ import "./index.css"; import { INamespace, INamespaceList, IHTTPError, IOrder } from "../../interfaces"; export default function Namespace({ localServer }: { localServer: string }) { - const [updateNamespaceModal, setUpdateNamespaceModal] = useState(false); - const [namespaceList, setNamespaceList] = useState({} as INamespaceList); const [namespaceText, setNamespaceText] = useState(""); @@ -99,12 +97,18 @@ export default function Namespace({ localServer }: { localServer: string }) { if (sortName !== "") { url += `&sort=${sortName}&method=${sortOrder.toString()}` } - axios.get(url).then((response) => { + axios.get(url).then(response => { if (response?.status === 200) { const namespaceList = response.data as INamespaceList; setNamespaceList(namespaceList); setTotal(namespaceList.total); + } else { + const errorcode = response.data as IHTTPError; + Toast({ level: "warning", title: errorcode.title, message: errorcode.message }); } + }).catch(error => { + const errorcode = error.response.data as IHTTPError; + Toast({ level: "warning", title: errorcode.title, message: errorcode.message }); }); } @@ -179,25 +183,6 @@ export default function Namespace({ localServer }: { localServer: string }) {
-
- - -
- - enter - -
-
diff --git a/web/src/pages/Repository/TableItem.tsx b/web/src/pages/Repository/TableItem.tsx index ad7246f7..270388a1 100644 --- a/web/src/pages/Repository/TableItem.tsx +++ b/web/src/pages/Repository/TableItem.tsx @@ -15,10 +15,9 @@ */ import dayjs from 'dayjs'; +import { Fragment } from "react"; import humanFormat from 'human-format'; -import { useClickAway } from 'react-use'; import { useNavigate } from 'react-router-dom'; -import { useRef, useState, Fragment } from "react"; import relativeTime from 'dayjs/plugin/relativeTime'; import { Menu, Transition } from '@headlessui/react'; import { EllipsisVerticalIcon } from '@heroicons/react/20/solid'; @@ -29,22 +28,16 @@ dayjs.extend(relativeTime); export default function TableItem({ index, namespace, repository }: { index: number, namespace: string, repository: IRepository }) { const navigate = useNavigate(); - const [show, setShow] = useState(false); - - const ref = useRef() as React.MutableRefObject; - useClickAway(ref, () => { - if (show) { - setShow(!show); - } - }); return ( - { - navigate(`/namespace/${namespace}/artifact?repository=${repository.name}`); - }}> - + + { + navigate(`/namespace/${namespace}/artifact?repository=${repository.name}`); + }} + >
-
+
{repository.name}
@@ -55,6 +48,9 @@ export default function TableItem({ index, namespace, repository }: { index: num {repository.tag_count} + + {repository.visibility} + {dayjs().to(dayjs(repository.created_at))} @@ -84,7 +80,7 @@ export default function TableItem({ index, namespace, repository }: { index: num
Update @@ -95,7 +91,7 @@ export default function TableItem({ index, namespace, repository }: { index: num {({ active }) => (
Delete diff --git a/web/src/pages/Repository/index.tsx b/web/src/pages/Repository/index.tsx index a1772933..ec3b374a 100644 --- a/web/src/pages/Repository/index.tsx +++ b/web/src/pages/Repository/index.tsx @@ -145,6 +145,9 @@ export default function Repository({ localServer }: { localServer: string }) { Tag count + + Visibility + Created at diff --git a/web/yarn.lock b/web/yarn.lock index e6068bb5..85f8e948 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -394,14 +394,6 @@ resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.3.tgz#cef09e3ec9af1d63d2a6cc5b383a737e24e6dcf5" integrity sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ== -"@types/yaireo__tagify@*", "@types/yaireo__tagify@^4.17.0": - version "4.17.0" - resolved "https://registry.yarnpkg.com/@types/yaireo__tagify/-/yaireo__tagify-4.17.0.tgz#5ba14e6f01375a34caf0a38fbc9d197c8e7b6a88" - integrity sha512-UT/6MhrWAKiI825mUxpDM9HgKA6cWEcW7meOkdPEmFRIl83UXAZsyhpekEgPAWJkn8WP8nHKl5v0UsDi24Ajiw== - dependencies: - "@types/react" "*" - "@types/yaireo__tagify" "*" - "@vitejs/plugin-react-swc@^3.3.2": version "3.3.2" resolved "https://registry.yarnpkg.com/@vitejs/plugin-react-swc/-/plugin-react-swc-3.3.2.tgz#34a82c1728066f48a86dfecb2f15df60f89207fb" @@ -414,11 +406,6 @@ resolved "https://registry.yarnpkg.com/@xobotyi/scrollbar-width/-/scrollbar-width-1.9.5.tgz#80224a6919272f405b87913ca13b92929bdf3c4d" integrity sha512-N8tkAACJx2ww8vFMneJmaAgmjAG1tnVBZJRLRcx061tmsLRZHSEZSLuGWnwPtunsSLvSqXQ2wfp7Mgqg1I+2dQ== -"@yaireo/tagify@^4.17.8": - version "4.17.8" - resolved "https://registry.yarnpkg.com/@yaireo/tagify/-/tagify-4.17.8.tgz#2696570843e3cd14318f305e80699d457aad918a" - integrity sha512-MqU3JhE/35r8qZPgfLshXfOkTkgtFEXh2Ja8J3Nn1rPuut28yorJLtxH67jbrbanE1gFH2vCvxe6meqM6oZ8rA== - accepts@~1.3.5, accepts@~1.3.7, accepts@~1.3.8: version "1.3.8" resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e" @@ -2911,7 +2898,7 @@ postcss-value-parser@^4.0.0, postcss-value-parser@^4.2.0: resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514" integrity sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ== -postcss@^8.4.23, postcss@^8.4.24, postcss@^8.4.25: +postcss@^8.4.23, postcss@^8.4.25: version "8.4.25" resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.25.tgz#4a133f5e379eda7f61e906c3b1aaa9b81292726f" integrity sha512-7taJ/8t2av0Z+sQEvNzCkpDynl0tX3uJMCODi6nT3PfASC7dYCWV9aQ+uiCf+KBD4SEFcu+GvJdGdwzQ6OSjCw== @@ -3686,13 +3673,13 @@ version-guard@^1.1.1: resolved "https://registry.yarnpkg.com/version-guard/-/version-guard-1.1.1.tgz#7a6e87a1babff1b43d6a7b0fd239731e278262fa" integrity sha512-MGQLX89UxmYHgDvcXyjBI0cbmoW+t/dANDppNPrno64rYr8nH4SHSuElQuSYdXGEs0mUzdQe1BY+FhVPNsAmJQ== -vite@^4.4.2: - version "4.4.2" - resolved "https://registry.yarnpkg.com/vite/-/vite-4.4.2.tgz#acd47de771c498aec80e4900f30133d9529b278a" - integrity sha512-zUcsJN+UvdSyHhYa277UHhiJ3iq4hUBwHavOpsNUGsTgjBeoBlK8eDt+iT09pBq0h9/knhG/SPrZiM7cGmg7NA== +vite@^4.4.3: + version "4.4.3" + resolved "https://registry.yarnpkg.com/vite/-/vite-4.4.3.tgz#dfaf86f4cba3058bf2724e2e2c88254fb0f21a5a" + integrity sha512-IMnXQXXWgLi5brBQx/4WzDxdzW0X3pjO4nqFJAuNvwKtxzAmPzFE1wszW3VDpAGQJm3RZkm/brzRdyGsnwgJIA== dependencies: esbuild "^0.18.10" - postcss "^8.4.24" + postcss "^8.4.25" rollup "^3.25.2" optionalDependencies: fsevents "~2.3.2"