Skip to content

Commit

Permalink
Merge pull request #14 from d3i-infra/13-make-delete-feature-in-table…
Browse files Browse the repository at this point in the history
…s-optional

made delete feature in tables optional
  • Loading branch information
trbKnl authored Sep 6, 2024
2 parents 27c0d42 + 0c95943 commit f413d81
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/framework/processing/py/port/api/props.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class PropsUIPromptConsentFormTable:
description: Optional[Translatable] = None
visualizations: Optional[list] = None
folded: Optional[bool] = False
delete_option: Optional[bool] = True

def toDict(self):
dict = {}
Expand All @@ -110,6 +111,7 @@ def toDict(self):
dict["description"] = self.description.toDict() if self.description else None
dict["visualizations"] = self.visualizations if self.visualizations else None
dict["folded"] = self.folded
dict["delete_option"] = self.delete_option
return dict


Expand Down
2 changes: 1 addition & 1 deletion src/framework/processing/py/port/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def generate_consent_prompt(*args: pd.DataFrame) -> props.PropsUIPromptConsentFo
"textColumn": "File name",
"tokenize": True,
}
tables.append(props.PropsUIPromptConsentFormTable(f"zip_contents_{index}", table_title, df, visualizations=[wordcloud]))
tables.append(props.PropsUIPromptConsentFormTable(f"zip_contents_{index}", table_title, df, visualizations=[wordcloud], delete_option=True))

return props.PropsUIPromptConsentForm(
tables,
Expand Down
1 change: 1 addition & 0 deletions src/framework/types/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ export interface TableContext {
deletedRows: string[][]
visualizations?: any[]
folded: boolean
deleteOption: boolean
}

export type TableWithContext = TableContext & PropsUITable
Expand Down
1 change: 1 addition & 0 deletions src/framework/types/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface PropsUIPromptConsentFormTable {
data_frame: any
visualizations: any
folded: boolean
delete_option: boolean
}
export function isPropsUIPromptConsentFormTable(arg: any): arg is PropsUIPromptConsentFormTable {
return isInstanceOf<PropsUIPromptConsentFormTable>(arg, "PropsUIPromptConsentFormTable", [
Expand Down
41 changes: 25 additions & 16 deletions src/framework/visualisation/react/ui/elements/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,18 @@ export const Table = ({
}
return (
<tr key={item.id} className='border-b-2 border-grey4 border-solid'>
<td key='select'>
<CheckBox
id={item.id}
size='w-6 h-6'
selected={selected.has(item.id)}
onSelect={() => toggleSelected(item.id)}
/>
</td>
{table.deleteOption &&
(
<td key='select'>
<CheckBox
id={item.id}
size='w-6 h-6'
selected={selected.has(item.id)}
onSelect={() => toggleSelected(item.id)}
/>
</td>
)
}

{item.cells.map((cell, j) => (
<td key={j}>
Expand Down Expand Up @@ -165,14 +169,18 @@ export const Table = ({
<table className='table-fixed min-w-full '>
<thead className=''>
<tr className='border-b-2 border-grey4 border-solid'>
<td className='w-8'>
<CheckBox
id='selectAll'
size='w-6 h-6'
selected={table.body.rows.length > 0 && selected.size === table.body.rows.length}
onSelect={toggleSelectAll}
/>
</td>
{table.deleteOption &&
(
<td className='w-8'>
<CheckBox
id='selectAll'
size='w-6 h-6'
selected={table.body.rows.length > 0 && selected.size === table.body.rows.length}
onSelect={toggleSelectAll}
/>
</td>
)
}
{columnNames.map(renderHeaderCell)}
</tr>
</thead>
Expand All @@ -188,6 +196,7 @@ export const Table = ({
label={`${text.delete} ${selected.size > 0 ? selectedLabel : ''}`}
color='text-delete'
disabled={selected.size === 0}
hidden={!table.deleteOption}
onClick={() => handleDelete?.(Array.from(selected))}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const ConsentForm = (props: Props): JSX.Element => {
deletedRows: [],
visualizations: tableData.visualizations,
folded: tableData.folded || false,
deleteOption: tableData.delete_option,
}
}

Expand Down

0 comments on commit f413d81

Please sign in to comment.