Skip to content

Commit

Permalink
set the searchbar default from the environment
Browse files Browse the repository at this point in the history
allows deployer to set an environment variable for the label of the
repo/org they'd like the searchbar to default to on startup.

If the variable not set, default is the first option available in the
options list.

Signed-off-by: James Kunstle <[email protected]>
  • Loading branch information
JamesKunstle committed Oct 4, 2023
1 parent e6f009a commit d34cfb8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
21 changes: 18 additions & 3 deletions 8Knot/db_manager/augur_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class AugurManager:
def __init__(self, handles_oauth=False):
# sqlalchemy engine object
self.engine = None
self.initial_search_option = None

# db connection credentials
# if any are unavailable, raise error.
Expand Down Expand Up @@ -208,8 +209,6 @@ def multiselect_startup(self):
# self.repo_id_to_repo_git = {value: key for (key, value) in self.repo_git_to_repo_id.items()}
self.repo_id_to_repo_git = pd.Series(df_repo_git_id.repo_git.values, index=df_repo_git_id["repo_id"]).to_dict()

# making first selection for the search bar
self.initial_search_option = self.multiselect_options[0]
logging.warning(f"MULTISELECT_FINISHED")

def repo_git_to_id(self, git):
Expand Down Expand Up @@ -259,11 +258,27 @@ def is_org(self, org):
return org in self.org_names

def initial_multiselect_option(self):
"""Getter method on first multiselect option
"""Getter method for the initial multiselect option.
May be overwritten by the environment.
Returns:
dict(value, label): first thing the multiselect will represent on startup
"""
if self.initial_search_option is None:
# default the initial multiselect option to the
# first item in the list of options.
self.initial_search_option = self.multiselect_options[0]

if os.getenv("DEFAULT_SEARCHBAR_LABEL"):
logging.warning("INITIAL SEARCHBAR OPTION: DEFAULT OVERWRITTEN")

# search through available options for the specified overwriting default.
for opt in self.multiselect_options:
if os.getenv("DEFAULT_SEARCHBAR_LABEL") == opt["label"]:
logging.warning(f"INITIAL SEARCHBAR OPTION: NEW DEFAULT: {opt}")
self.initial_search_option = opt
break

return self.initial_search_option

def get_multiselect_options(self):
Expand Down
21 changes: 11 additions & 10 deletions 8Knot/pages/chaoss/visualizations/contrib_importance_pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
max_date_allowed=dt.date.today(),
initial_visible_month=dt.date(dt.date.today().year, 1, 1),
clearable=True,
),
),
],
),
dbc.Col(
Expand All @@ -166,8 +166,8 @@
),
],
align="center",
justify="between",
)
justify="between",
),
]
),
]
Expand Down Expand Up @@ -246,12 +246,12 @@ def process_data(df: pd.DataFrame, action_type, top_k, patterns, start_date, end
df["created_at"] = pd.to_datetime(df["created_at"], utc=True)

# order values chronologically by created_at date
df = df.sort_values(by='created_at', ascending=True)
df = df.sort_values(by="created_at", ascending=True)

# filter values based on date picker
if start_date is not None:
df = df[df.created_at >= start_date]
if end_date is not None:
# filter values based on date picker
if start_date is not None:
df = df[df.created_at >= start_date]
if end_date is not None:
df = df[df.created_at <= end_date]

# subset the df such that it only contains rows where the Action column value is the action type
Expand All @@ -268,7 +268,7 @@ def process_data(df: pd.DataFrame, action_type, top_k, patterns, start_date, end

# sort rows according to amount of contributions from greatest to least
df.sort_values(by="cntrb_id", ascending=False, inplace=True)
df= df.reset_index()
df = df.reset_index()

# rename Action column to action_type
df = df.rename(columns={"Action": action_type})
Expand All @@ -290,6 +290,7 @@ def process_data(df: pd.DataFrame, action_type, top_k, patterns, start_date, end

return df


def create_figure(df: pd.DataFrame, action_type):
# create plotly express pie chart
fig = px.pie(
Expand All @@ -310,4 +311,4 @@ def create_figure(df: pd.DataFrame, action_type):
# add legend title
fig.update_layout(legend_title_text="Contributor ID")

return fig
return fig
21 changes: 11 additions & 10 deletions 8Knot/pages/contributors/visualizations/contrib_importance_pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
max_date_allowed=dt.date.today(),
initial_visible_month=dt.date(dt.date.today().year, 1, 1),
clearable=True,
),
),
],
),
dbc.Col(
Expand All @@ -166,8 +166,8 @@
),
],
align="center",
justify="between",
)
justify="between",
),
]
),
]
Expand Down Expand Up @@ -246,12 +246,12 @@ def process_data(df: pd.DataFrame, action_type, top_k, patterns, start_date, end
df["created_at"] = pd.to_datetime(df["created_at"], utc=True)

# order values chronologically by created_at date
df = df.sort_values(by='created_at', ascending=True)
df = df.sort_values(by="created_at", ascending=True)

# filter values based on date picker
if start_date is not None:
df = df[df.created_at >= start_date]
if end_date is not None:
# filter values based on date picker
if start_date is not None:
df = df[df.created_at >= start_date]
if end_date is not None:
df = df[df.created_at <= end_date]

# subset the df such that it only contains rows where the Action column value is the action type
Expand All @@ -268,7 +268,7 @@ def process_data(df: pd.DataFrame, action_type, top_k, patterns, start_date, end

# sort rows according to amount of contributions from greatest to least
df.sort_values(by="cntrb_id", ascending=False, inplace=True)
df= df.reset_index()
df = df.reset_index()

# rename Action column to action_type
df = df.rename(columns={"Action": action_type})
Expand All @@ -290,6 +290,7 @@ def process_data(df: pd.DataFrame, action_type, top_k, patterns, start_date, end

return df


def create_figure(df: pd.DataFrame, action_type):
# create plotly express pie chart
fig = px.pie(
Expand All @@ -310,4 +311,4 @@ def create_figure(df: pd.DataFrame, action_type):
# add legend title
fig.update_layout(legend_title_text="Contributor ID")

return fig
return fig

0 comments on commit d34cfb8

Please sign in to comment.