Files
kubevela/references/cli/top/component/pages.go
T
Siege Lion d38b20de64 Feat: add feature of refreshing resource view and fix the bug of stucking (#4743)
* Fix: add test cases

Signed-off-by: HanMengnan <1448189829@qq.com>

* Fix: fix bugs in resource view switch

Signed-off-by: HanMengnan <1448189829@qq.com>

* Fix: optimize the method of resource view render

1. Separate view loading and data rendering to optimize the view rendering speed

Signed-off-by: HanMengnan <1448189829@qq.com>

* Fix: fix the bug of ctx value transmit in resource view switch

Signed-off-by: HanMengnan <1448189829@qq.com>

* Feat: Add the feature of auto refresh
Signed-off-by: HanMengnan <1448189829@qq.com>

* Fix: small fix

Signed-off-by: HanMengnan <1448189829@qq.com>

* Fix: small fix

Signed-off-by: HanMengnan <1448189829@qq.com>

* Fix: small fix

Signed-off-by: HanMengnan <1448189829@qq.com>

* Fix: small fix

Signed-off-by: HanMengnan <1448189829@qq.com>

Signed-off-by: HanMengnan <1448189829@qq.com>
2022-09-20 11:28:51 +08:00

96 lines
2.0 KiB
Go

/*
Copyright 2022 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package component
import (
"fmt"
"github.com/rivo/tview"
"github.com/oam-dev/kubevela/references/cli/top/model"
)
// Pages is the app's main content view component
type Pages struct {
*tview.Pages
*model.Stack
}
// NewPages return a page component
func NewPages() *Pages {
p := &Pages{
Pages: tview.NewPages(),
Stack: model.NewStack(),
}
p.Stack.AddListener(p)
return p
}
// Init table component
func (p *Pages) Init() {}
// Name return pages' name
func (p *Pages) Name() string {
return "Pages"
}
// Start table component
func (p *Pages) Start() {}
// Stop table component
func (p *Pages) Stop() {}
// Hint return key action menu hints of the component
func (p *Pages) Hint() []model.MenuHint {
return []model.MenuHint{}
}
// StackPop change itself when accept "pop" notify from app's main view
func (p *Pages) StackPop(old, _ model.View) {
p.delete(old)
}
// StackPush change itself when accept "push" notify from app's main view
func (p *Pages) StackPush(_, new model.View) {
p.addAndShow(new)
}
// AddAndShow adds a new page and bring it to front.
func (p *Pages) addAndShow(c model.View) {
p.add(c)
p.show(c)
}
func (p *Pages) add(c model.View) {
p.AddPage(componentID(c), c, true, true)
}
func (p *Pages) delete(c model.View) {
p.RemovePage(componentID(c))
}
func (p *Pages) show(c model.View) {
p.SwitchToPage(componentID(c))
}
func componentID(c model.View) string {
if c.Name() == "" {
panic("View has no name")
}
return fmt.Sprintf("%s-%p", c.Name(), c)
}