#include "SecretsPanel.hpp" #include "BoxLayout.hpp" #include "Ui.hpp" namespace tp::taskboard { using namespace ui; namespace { constexpr halnf kPadding = 12; constexpr halnf kGap = 6; constexpr halnf kKeyWidth = 200; constexpr halnf kValueWidth = 180; constexpr halnf kDescWidth = 240; bool isKey(const std::string& k) { if (k.empty()) return false; for (char ch : k) if (!std::isalnum(static_cast(ch)) && ch != '.' && ch != '_' && ch != '-') return false; return true; } } SecretsPanel::SecretsPanel() { setDebugName("secrets panel"); setSizing(AxisSizing::fill(), AxisSizing::fill()); emplaceLayout(kGap).setPadding(Insets::uniform(kPadding)); mHint.setTone(Label::Tone::Muted); mHint.setSizing(AxisSizing::fill(), AxisSizing::fit()); mHint.setText("Agents read a value at run time with get_secret; the board never shows a stored value."); key.setPlaceholder("key"); key.setSizing(AxisSizing::preferred(kKeyWidth), AxisSizing::fit()); value.setPlaceholder("value"); value.setSizing(AxisSizing::preferred(kValueWidth), AxisSizing::fit()); description.setPlaceholder("description"); description.setSizing(AxisSizing::fill(), AxisSizing::fit()); save.setStyle(Button::Style::Accent); save.setSizing(AxisSizing::fit(), AxisSizing::fit()); save.setOnClicked([this](const Event&) { commitForm(); }); cancel.setStyle(Button::Style::Flat); cancel.setSizing(AxisSizing::fit(), AxisSizing::fit()); cancel.setVisible(false); cancel.setOnClicked([this](const Event&) { clearForm(); }); mForm.setSizing(AxisSizing::fill(), AxisSizing::fit()); mForm.emplaceLayout(kGap); mForm.addChild(key); mForm.addChild(value); mForm.addChild(description); mForm.addChild(save); mForm.addChild(cancel); mStatus.setVisible(false); mStatus.setSizing(AxisSizing::fill(), AxisSizing::fit()); mList.setSizing(AxisSizing::fill(), AxisSizing::fit()); mList.emplaceLayout(kGap); mListScroll.setContent(&mList); mListScroll.setSizing(AxisSizing::fill(), AxisSizing::fill()); addChild(mHint); addChild(mForm); addChild(mStatus); addChild(mListScroll); } void SecretsPanel::setStore(SecretsStore* store) { mStore = store; refresh(); } void SecretsPanel::refresh() { if (!mStore) { rebuildList({}); return; } mStore->listSecrets([this](std::vector entries) { rebuildList(entries); }); } void SecretsPanel::rebuildList(const std::vector& entries) { mList.clearOwnedChildren(); for (const SecretEntry& entry : entries) { Widget& row = mList.emplaceChild(); row.setSizing(AxisSizing::fill(), AxisSizing::fit()); row.emplaceLayout(kGap); Label& keyLabel = row.emplaceChild