Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added grouping in default_config page #9

Merged
merged 1 commit into from
Apr 26, 2024

Conversation

mahatoankitkumar
Copy link
Collaborator

@mahatoankitkumar mahatoankitkumar commented Apr 23, 2024

Problem

Add grouping in default_config page

Solution

Added grouping in default_config page to show keys in folder structure.
Screenshot 2024-04-23 at 5 35 57 PM
Screenshot 2024-04-23 at 5 36 04 PM
Screenshot 2024-04-23 at 5 36 14 PM

Environment variable changes

N.A.

Pre-deployment activity

N.A.

Post-deployment activity

N.A.

API changes

N.A.

Possible Issues in the future

N.A.

@mahatoankitkumar mahatoankitkumar self-assigned this Apr 23, 2024
@mahatoankitkumar mahatoankitkumar requested a review from a team as a code owner April 23, 2024 06:49
@mahatoankitkumar mahatoankitkumar force-pushed the feat/grouping/default_config branch from 701d931 to a45be66 Compare April 23, 2024 06:50
@Datron Datron force-pushed the main branch 5 times, most recently from 7dcb3c0 to 3b7e262 Compare April 23, 2024 10:03
@Datron
Copy link
Collaborator

Datron commented Apr 23, 2024

@mahatoankitkumar can you add screenshots?

@mahatoankitkumar mahatoankitkumar force-pushed the feat/grouping/default_config branch from a45be66 to 875e51c Compare April 23, 2024 12:10
let f_name = config_key.get();
let f_name = prefix
.clone()
.map_or_else(|| config_key.get(), |p| p + &config_key.get());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does |p| p + &config_key.get()
Supposed to do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds prefix to the key. Will change p to prefix more readibility.


create_effect(move |_| {
let query_params_map = query_params.try_get();
if let Some(query_map) = query_params_map {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we simplify this block of code and reduce the ifs?

@mahatoankitkumar mahatoankitkumar force-pushed the feat/grouping/default_config branch from 875e51c to c558e53 Compare April 23, 2024 12:25
@@ -23,6 +23,7 @@ pub fn default_config_form<NF>(
#[prop(default = String::new())] config_pattern: String,
#[prop(default = String::new())] config_value: String,
#[prop(default = None)] function_name: Option<Value>,
#[prop(default = None)] prefix: Option<String>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[prop(default = None)] prefix: Option<String>,
#[prop(default = String::new())] prefix: String,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional parameter makes more sense here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mahatoankitkumar , can you make the folder and the file name default_config also the component function name default_config?

create_effect(move |_| {
let query_params_map = query_params.try_get();
if let Some(query_map) = query_params_map {
let opt_prefix = query_map.get("prefix");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let opt_prefix = query_map.get("prefix");
filters.set(query_map.get("prefix").cloned());

we can directly go with this, right?


let expand = move |_: &str, row: &Map<String, Value>| {
let key_name = row["key"].clone().to_string().replace("\"", "");
let key_name_copy = key_name.clone();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let key_name_copy = key_name.clone();
let label = key_name.clone();

Since this is used as the cell value on the page.


let table_columns = create_memo(move |_| {
let edit_col_formatter = move |_: &str, row: &Map<String, Value>| {
logging::log!("{:?}", row);
let row_key = row["key"].clone().to_string().replace("\"", "");
let key = row_key.clone();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let key = row_key.clone();
let is_folder = row_key.contains(".");

@@ -116,10 +144,36 @@ pub fn DefaultConfig() -> impl IntoView {
let edit_icon: HtmlElement<html::I> =
view! { <i class="ri-pencil-line ri-xl text-blue-500"></i> };

view! { <span class="cursor-pointer" on:click=edit_click_handler>{edit_icon}</span> }.into_view()
if key.to_owned().contains(".") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if key.to_owned().contains(".") {
if is_folder {

}
folder_click_handler(Some(key.clone()))
}>
{key_name_copy.clone()}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{key_name_copy.clone()}
{label}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.clone() is not needed

vec!["".to_string(), key.to_string()]
};

if let Some(filtered_key) = key_arr.get(1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mahatoankitkumar , can you explain the approach here to generate a key name?

@@ -30,11 +32,37 @@ pub fn DefaultConfig() -> impl IntoView {
);

let selected_config = create_rw_signal::<Option<RowData>>(None);
let filters = create_rw_signal::<Option<String>>(None);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let filters = create_rw_signal::<Option<String>>(None);
let key_prefix = create_rw_signal::<Option<String>>(None);

</DrawerBtn>
<div class="flex justify-between pb-2">
<div class="flex justify-between pt-3">{
{move || {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{move || {
```suggestion
{
move || {
let data = bread_crums.get();
let last_index = data.len() - 1;
data.iter()
.enumerate()
.map(|(index, item)| {
let value = item.value.clone();
let is_link = item.is_link.clone();
let is_last_item = index < last_index;
let item_classname = if item.is_link {
"cursor-pointer text-blue-500 underline underline-offset-2"
} else {
""
};
view! {
<div class="flex">
<h2
on:click=move |_| {
if is_link {
folder_click_handler(value.clone())
}
}
class={item_classname}
>
{item.key.clone()}
</h2>
<h2 class="pl-4 pr-4">
{if is_last_item { ">" } else { "" }}
</h2>
</div>
}
})
.collect_view()
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use derive signal like this, to solution this out

    let bread_crums = Signal::derive(move || {
        let filters = filters.get();
        let mut default_bread_crums = vec![BreadCrums {
            key: "Default Config".to_string(),
            value: None,
            is_link: true,
        }];

        let mut bread_crums = match filters {
            Some(prefix) => {
                let partials = prefix
                    .trim_matches('.')
                    .split(".")
                    .map(str::to_string)
                    .collect::<Vec<String>>();
                partials
                    .into_iter()
                    .fold(String::new(), |mut prefix, partial| {
                        default_bread_crums.push(BreadCrums {
                            key: partial.clone(),
                            value: Some(prefix.clone()),
                            is_link: true,
                        });
                        prefix.push_str(&partial);
                        prefix.push('.');
                        prefix
                    });
                default_bread_crums
            }
            None => default_bread_crums,
        };

        if let Some(last_crum) = bread_crums.last_mut() {
            last_crum.is_link = false;
        }

        bread_crums
    });

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure will try this.

@mahatoankitkumar mahatoankitkumar force-pushed the feat/grouping/default_config branch 2 times, most recently from a20f321 to 5d1d379 Compare April 23, 2024 18:46
@@ -0,0 +1 @@
pub mod default_config;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we stop doing these one line mod.rs files? We can just put all the code here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave it as is for now

Deserialize,
Serialize,
diesel_derive_enum::DbEnum,
QueryId,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mahatoankitkumar you can get rid of QueryId here, I was trying to solve something and added it by mistake.

@mahatoankitkumar mahatoankitkumar force-pushed the feat/grouping/default_config branch 2 times, most recently from d4f392a to 1264fbf Compare April 24, 2024 06:16
@Datron Datron force-pushed the feat/grouping/default_config branch from 1264fbf to 86cc900 Compare April 24, 2024 06:29
is_link: true,
}];

let mut bread_crums = match key_prefix {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have different variable name bread_crums ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bread_crums name serves the purpose.

@mahatoankitkumar mahatoankitkumar force-pushed the feat/grouping/default_config branch 2 times, most recently from ac68951 to fed78c9 Compare April 26, 2024 06:36
<div class="flex">
<label on:click=move |_| {
folder_click_handler(None);
enable_grouping.set(!enable_grouping.get());}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enable_grouping.set(!enable_grouping.get());}
enable_grouping.update(|prev| *prev = !(*prev));

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't re-rendering the component.

@mahatoankitkumar mahatoankitkumar force-pushed the feat/grouping/default_config branch from fed78c9 to 691556a Compare April 26, 2024 08:00
@ShubhranshuSanjeev ShubhranshuSanjeev merged commit 5ac099d into main Apr 26, 2024
2 checks passed
Datron pushed a commit that referenced this pull request May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants