Skip to content

Commit

Permalink
Merge pull request mito-ds#1286 from mito-ds/more-bug-fixes
Browse files Browse the repository at this point in the history
More bug fixes
  • Loading branch information
aarondr77 authored Mar 15, 2024
2 parents 65140c5 + 2155380 commit e7c2128
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
7 changes: 5 additions & 2 deletions mitosheet/mitosheet/pro/conditional_formatting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ def get_conditonal_formatting_result(

for index in applied_indexes:
# We need to make this index valid json, and do so in a way that is consistent with how indexes
# are sent to the frontend
json_index = json.dumps(index, cls=NpEncoder)
# are sent to the frontend. However, if the index is a string, we don't want to add quotes around it
if isinstance(index, str):
json_index = index
else:
json_index = json.dumps(index, cls=NpEncoder)
formatted_result[column_id][json_index] = {'backgroundColor': backgroundColor, 'color': color}

except Exception as e:
Expand Down
14 changes: 8 additions & 6 deletions mitosheet/mitosheet/public/v3/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pandas import DataFrame, ExcelWriter

from mitosheet.excel_utils import get_column_from_column_index
from mitosheet.is_type_utils import is_float_dtype
from mitosheet.is_type_utils import is_float_dtype, is_int_dtype
from mitosheet.types import (
FC_BOOLEAN_IS_FALSE, FC_BOOLEAN_IS_TRUE, FC_DATETIME_EXACTLY,
FC_DATETIME_GREATER, FC_DATETIME_GREATER_THAN_OR_EQUAL, FC_DATETIME_LESS,
Expand Down Expand Up @@ -152,13 +152,15 @@ def add_number_formatting(
for column_index in default_number_format_column_indexes:
column_header = column_headers[column_index]
dtype = str(df[column_header].dtype)
if not is_float_dtype(dtype):
continue

column = get_column_from_column_index(column_index)
cell_range = f'{column}2:{column}{sheet.max_row}'
for cell in sheet[cell_range]:
cell[0].number_format = '#,##0.00'

if is_float_dtype(dtype):
for cell in sheet[cell_range]:
cell[0].number_format = '#,##0.00'
if is_int_dtype(dtype):
for cell in sheet[cell_range]:
cell[0].number_format = '#,##0'

def add_header_formatting_to_excel_sheet(
writer: ExcelWriter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import pytest
from mitosheet.mito_backend import MitoBackend, get_mito_backend
import pandas as pd
Expand Down Expand Up @@ -233,7 +234,28 @@ def test_create_backend_with_column_definitions_does_not_error_with_mismatch_con
assert df_formats[0]['conditional_formats'][0]['invalidFilterColumnIDs'] == []


def test_column_definitions_with_string_indexes_conditional_format_works():
column_definitions= [
[
{
'columns': ['A'],
'conditional_formats': [{
'filters': [{'condition': 'number_exactly', 'value': 2}],
'font_color': '#c30010',
'background_color': '#ffcbd1'
}]
}
]
]


mito_backend = get_mito_backend(pd.DataFrame({'A': [1, 2, 3]}, index=['S1', 'S2', 'S3']), column_definitions=column_definitions)
sheet_json = mito_backend.get_shared_state_variables()['sheet_data_json']
sheet_data = json.loads(sheet_json)[0]
conditional_formatting_result = sheet_data['conditionalFormattingResult']
assert len(conditional_formatting_result['results']) == 1
assert len(conditional_formatting_result['results']['A']) == 1
assert 'S2' in conditional_formatting_result['results']['A']



Expand Down
2 changes: 1 addition & 1 deletion mitosheet/mitosheet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def write_to_excel(
sheet_name = get_df_name_as_valid_sheet_name(df_name)

# Write the dataframe to the sheet
df.to_excel(writer, sheet_name, index=False)
df.to_excel(writer, sheet_name=sheet_name, index=False)

# Add formatting to the sheet for pro users
format = state.df_formats[sheet_index]
Expand Down
2 changes: 1 addition & 1 deletion mitosheet/src/mito/components/endo/focusUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

export const focusGrid = (containerDiv: HTMLDivElement | null | undefined): void => {
if (containerDiv) {
containerDiv.focus()
containerDiv.focus({preventScroll: true})
}
}

0 comments on commit e7c2128

Please sign in to comment.