forked from github-starred/komodo
default new tag colors to grey
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2503,7 +2503,6 @@ dependencies = [
|
||||
"futures",
|
||||
"mongo_indexed",
|
||||
"partial_derive2",
|
||||
"rand 0.9.0",
|
||||
"reqwest",
|
||||
"resolver_api",
|
||||
"serde",
|
||||
|
||||
@@ -50,7 +50,7 @@ impl Resolve<WriteArgs> for CreateTag {
|
||||
let mut tag = Tag {
|
||||
id: Default::default(),
|
||||
name: self.name,
|
||||
color: TagColor::random(),
|
||||
color: TagColor::Slate,
|
||||
owner: user.id.clone(),
|
||||
};
|
||||
|
||||
|
||||
@@ -17,12 +17,10 @@ use komodo_client::{
|
||||
};
|
||||
use mongo_indexed::Document;
|
||||
use mungos::{
|
||||
bulk_update::{BulkUpdate, bulk_update},
|
||||
find::find_collect,
|
||||
mongodb::bson::{Bson, doc, oid::ObjectId, to_document},
|
||||
};
|
||||
use periphery_client::PeripheryClient;
|
||||
use query::get_all_tags;
|
||||
use rand::Rng;
|
||||
use resolver_api::Resolve;
|
||||
|
||||
@@ -354,32 +352,4 @@ pub async fn ensure_first_server_and_builder() {
|
||||
e.error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// In 1.17, Tag colors are introduced.
|
||||
/// This will generate and save tag colors for all existing tags.
|
||||
/// Tags which already have color set will not be changed, making this a no-op.
|
||||
/// All new tags going forward will have a color assigned on creation,
|
||||
/// so this method will no longer be needed and should be removed in 1.18+.
|
||||
pub async fn generate_tag_colors() {
|
||||
let inner = async {
|
||||
let updates = get_all_tags(None)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|tag| {
|
||||
BulkUpdate::new(
|
||||
doc! { "name": tag.name },
|
||||
// If the tag doesn't have a color saved in the database,
|
||||
// a random one will be generated to populate the field,
|
||||
// and this just saves that back to the database.
|
||||
doc! { "$set": { "color": tag.color.as_ref() } },
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
bulk_update(&db_client().db, "Tag", &updates, false).await?;
|
||||
anyhow::Ok(())
|
||||
};
|
||||
if let Err(e) = inner.await {
|
||||
error!("Failed to generate tag colors | {e:#}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,8 +48,6 @@ async fn app() -> anyhow::Result<()> {
|
||||
helpers::ensure_first_server_and_builder(),
|
||||
// Cleanup open updates / invalid alerts
|
||||
helpers::startup_cleanup(),
|
||||
// Randomly populate tag colors on 1.16 -> 1.17 upgrade
|
||||
helpers::generate_tag_colors(),
|
||||
);
|
||||
// init jwt client to crash on failure
|
||||
state::jwt_client();
|
||||
|
||||
@@ -39,7 +39,6 @@ anyhow.workspace = true
|
||||
serde.workspace = true
|
||||
tokio.workspace = true
|
||||
strum.workspace = true
|
||||
rand.workspace = true
|
||||
envy.workspace = true
|
||||
uuid.workspace = true
|
||||
clap.workspace = true
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use derive_builder::Builder;
|
||||
use partial_derive2::Partial;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{AsRefStr, EnumCount, FromRepr};
|
||||
use strum::AsRefStr;
|
||||
use typeshare::typeshare;
|
||||
|
||||
use crate::entities::MongoId;
|
||||
@@ -43,11 +43,10 @@ pub struct Tag {
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
#[derive(
|
||||
Serialize, Deserialize, Debug, Clone, EnumCount, FromRepr, AsRefStr,
|
||||
)]
|
||||
#[derive(Serialize, Deserialize, Default, Debug, Clone, AsRefStr)]
|
||||
pub enum TagColor {
|
||||
LightSlate,
|
||||
#[default]
|
||||
Slate,
|
||||
DarkSlate,
|
||||
|
||||
@@ -119,17 +118,3 @@ pub enum TagColor {
|
||||
Rose,
|
||||
DarkRose,
|
||||
}
|
||||
|
||||
impl TagColor {
|
||||
pub fn random() -> Self {
|
||||
let index = rand::random_range(0..TagColor::COUNT);
|
||||
// Unwrap OK, index will always be in range
|
||||
Self::from_repr(index).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TagColor {
|
||||
fn default() -> Self {
|
||||
Self::random()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user