Skip to content

Commit

Permalink
feat: minor fixes to edit
Browse files Browse the repository at this point in the history
  • Loading branch information
kirangadhave committed Nov 8, 2023
1 parent 50f473d commit ed94f89
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 106 deletions.
98 changes: 8 additions & 90 deletions examples/test_ext_widget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 7,
"id": "9c930f8c-7612-4e28-bc80-439c3cfcd7b4",
"metadata": {
"trrack_graph": "໢尭䲠 "
Expand All @@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 8,
"id": "865de998-8e43-4643-aa6a-93bc1289f30b",
"metadata": {
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰҃Xڂ䂌ϐ€ୠೠ⌠ᘪ䑾䂃¼∤᧵Fจ睯છ壠テ⒴E䨲ࡔⳙժ⭵咂曳嚯ἡ⅂†桠ûᧂẰӁĠנ搬W౐㮨⃎濻倡㜴㔠ʑ㥀ǔÚ䍃Ꭼᳱh㏆ݐ沀倠祐ሹܡ䱏䏥叐Ź梦{భ妬∬挤䍴淤ၹ䐨憪᫠ඎ⺄ޕ䏢Þ䎞獩ᖦ悮沩ǡ᪁㕖o#䦝氃φ痌⇥⼖䞆ᱤ䩽恣ӣ劃㢁⑐暆ഹಯѮ䞁憱࠸琠䨥ڃ場ᐸ偃泋ۺ≩ỉ࠸㉦䙀⁺掐搸㘿ك䡴᜵▀㡼ᚿ䐳ӂ≠֢֔⏛䭆戴㲒佢ォൗ௣᎔児搠 "
Expand Down Expand Up @@ -140,7 +140,7 @@
"4 140.0 3449 10.5 1970-01-01 USA "
]
},
"execution_count": 2,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -152,26 +152,26 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 9,
"id": "82f9dab1-06be-481e-9147-845bf7bed257",
"metadata": {
"__GENERATED_DATAFRAMES__": "ᯡࠣ䅬Ԁ朤壠ᜣ琢〹夤゠⹰〮⁁䁻қ䚾ኊ㇠നСࠩ瀮晼Ƭ穅5愠៤⠠ ",
"__GENERATED_DATAFRAMES__": "ᯢ粠 ",
"__has_persist_output": true,
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰ৢ䇸ѐƠᘢᠢ〫⊳↻෪℣ᦨҋ₃ᑶࠬ性ઍե桫圲⠠䭈⑀棑焵ᝉ⵮冫᭼乜簥Ҩǁ#㓠挰橠ኤРᜰ͐üメ湁˛㾄ᦠָ憴)挄䀦歫ᨑ格璌ݑᦥඤ兠Ǒ奐岉ᑤ猬്ᳫ䖨ˑ匨†崣↳䳩ච㚁ڀ沀倠祐቞݅ண䷆惁笨ؠ嬸ෆᑤদҡ䳹䑀㶨ズ䠣᫠ඁ᳢܏䋊Þͣ䫧ጹ䎀䃺淣 獖o#䘝栃څ沜ၑᗭ牙ᢓᤢh劌آ拱夸ᢡ惡ᡅἭ଱ɔ弬⃁䰢↠掱呲嬭珜彉׊䟔⁳䆰㐃典幈䭅⤬墥䤄礢䣂⯁敪刽ߙ䲸乀䥄⥊ᵉ䮅㤢㾼⦴ᖏᣪぢ†ᡷ恸Ćຠl恡ؠᗢ㌣ഠ㤠৊䔥㜃㊳˚ၛⲮ棌協圦ঠ灊国珴₿峵㖠ᯆᰒ൏㍿搨䌋⛠愚๎ᮺ⃠瀤ब䃁⡔㴩䖃壼⼿䐳Ӿ്儋㫝㽰ㅢ栣ᄫ䒻⛓⑁㉹嫋ڋㇸℛ⇸炛伓ၪ燙湇Ʈ°怠⢧ʭ帎倴ġ⹠୸™ᴇ⟓㬔緞ၖ㎃祡炘⨠䁞⤨∖ᨒ潝簂䠠㴻劝ᛍ獕ᛕ厬㞢㟴怱埄穋瞝湇眝䦽玉翛䀣傡䌥⁴䝠烎۠屌ᙁ㐺◁栵ͩᠺ⒀ҭ३㐭旁㡚ߡㄷb䡴䓠偄䋭ᢀ༣冠ij㒸!⣾Яޢ୻犠䝰獾⩽掚榬√èᥴ漣䁠₠爆෰ਘ楇ⓜٴ熌徿爢恦恸ᠣ䅨ᤰ寨ዩ⎶唪墈᫻⏶ᄮ㧴朢ఀ䙤Ĥ欯᪙㤸婈㋥≶申⋶ᴡ孔୨Ꮖ磊ቪ㙦⪒շ䭊䊵⤪畴焠 "
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰໠ጡ䘦ダ㌴怶䊠าÒཛྷ䃌⴨҅坉҃⩕搦捪㤸栢㢲䀤奢℮䶯Ñᥪ檕ය寔爇恘␠ന;c̸䍲´၀Û璡䀦熦ྑѕ嶧ఠᚃٰG⮲;‫偔᭛䲰,̬࢑囦Ԡ޳ŀĹ屢→ड़⬾ᙼၐ˸憍䛂ႃᡄᛖ晁۬≤స㘠歪熰㟜ᄰؐᨮ宑䘸嬤❴␮˳ߍ堢㰠໋ཟద៓ㄦ᎐㥛్䡀ॉნⒷã乑昰犸䩐湂Ⴃ᠐䑆烐⠾⃧巨捙Ā淖⥒⌥╶凒ṑ¢᭛䵄悐簱੠僈婝ӡヸื௧焤ᄲ‥㤤ⅳ䏣ᄃ犜⥤⛉⒭ʽ卲ⁱ䠠 "
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5b5b3efccd86436da005033b2dd29355",
"model_id": "02495a30e1304f3fa638637931186f28",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"PersistWidget(data_values=[{'__id_column': '1', 'Name': 'chevrolet chevelle malibu', 'Miles_per_Gallon': 18.0,…"
]
},
"execution_count": 3,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -180,88 +180,6 @@
"a = PR.PersistTable(cars)\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6a435cfb-9c8f-4f7b-b775-f5ed8f762850",
"metadata": {
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰Ӣ䅸ɗ㴦ᠭ䁍cČíᨰֿ㗚ࠣ䱶䊀ৢ䩬ɓ往ƥ`㌲⠠䭈⑀棐瀱Ⴥ⭾䦫ᔮ⻝粦䒠ǁ#㙉䌸晠ኤРᝣၐüムṁǟ㤗%䉸攠ʓ㥀ǔÚ⎃஥䤠⒋䔮ᇸ惀Ēいཞᾶ侢䠄獱డ㙐㮂㢨᢬थ⯐䡣㌰兦䱻U䳘䰵梬䐢粬絭犂⸽䄭崲Τ㓠欌¾'ጇ忦஥歸䁫崽令䮄࠴䙠⌢ᗡ੓炁Ԅᢂㄭާ䩤慧愒৸尰ᦤ憨ᑕԧ․䝊懑䦲垺∢౱ᆨవ塜夦ඣ您㉅ͣ倸晋׆焘䅐䙂␠垀呄㪘牼ㅠⓉ䔕ಹ恳㪊㤴 "
},
"outputs": [],
"source": [
"cars.Year = a.data.Year"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fbf9df2a-6f61-48b9-97d3-71ca7bdf4448",
"metadata": {
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰ৠବ倻Č⠱䁍.†Ƭ˒ࣧ㔢ద㉓傠౐擌宋୾䨲⠠䭁䑁楒瀱Ⴭ⭡始ݎẜʤð䀡寰ɑ䗴䈠ॢȠநຸŽᢀ㙄⽽央•扗⨠Ꮃ䤠වױ欈ᶬ䢌ᶒ₝૳/ጢ␁ぱ桸Ⲝ੆ⶥπב䅻榤℔と㥵䑢ڸ䌩栺Ⱑ囥窟㭨㑀ః圏嚳槨嘨朐䠼ໆॵ〤砠Ḇዾᢒ㮒戤ⴁ矗傻ၠ拆๦㥃᢫̨╁䏳梉礘嚂3ᝐ䊮␘ᠹ琯䴥ɰ氯ঊ媹照䥂Д࣡䐯牸⹩̭䈀䑒ણ⃠瑢ঢ揑᲎ᒫ搑ȯᲠ˛粡㻢⊲㇒แ⟥ᓤ檬䣆㔐倠 "
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"id": "969052a8-acab-4a58-8177-2c9ef62ae521",
"metadata": {
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰ˠ⌴栣Ìǐ͐ୢ䔢㢰ჯČ∢ᠬ恘呚⿦䁬X㠩挃ҴE䨲࢔䳙ѩ䡱⛇ⓥ䢻ݺ帢䉠ð䀡婷冨㥀ॢȠ௞䠸Žᢀ眰䅽忐ಀƊᢅ\"㣙အ娠崣↳䳩֠㜑ٰ沀倠祐ሺ༿俢䏧怶ᦐؠ嬸ළѤ०Ң哺䑀妨䢣㵕䀺晹∪瞤∡㸦㻆䅅᯦悦檩Ǣᮥ䡀ᬠ➠ǩ㈧熦禗噁⋎筧╙妜⥅䆤㎚ᢘ硐∢౅ኤ䚦䏁熑烰䔜㞨࿃梴ᜥ΁ㄖ᫳㒱ዏ⩤Ȼᅃࠨᛑ屲ػߣࣄ㤪䗀ᣬ⬽䔃㒢ケဢ岢ბ漆䢑㥞ᣆ⦩㔦乫煉⑰ "
},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'E' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[5], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mE\u001b[49m\u001b[38;5;241m.\u001b[39mhead()\n",
"\u001b[0;31mNameError\u001b[0m: name 'E' is not defined"
]
}
],
"source": [
"E.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d096bc85-ec23-44ee-bd5c-2792731a2937",
"metadata": {
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰ಅŸހ֠ยฐ୮䂆㸠᢮怹䁦♤ɒ㩠㙃ᠩ旻ⴡᡱᡲ矤䨠ዪनᩌ㲤◩⫰㚊懻垠傱ㄠ㑀碸愹䠤傡%戰映ᮬᢛ䑁圌ỨÐ䩒䀡ᵼ䠠洠⻁䣹溄䃄ᣀ䐑㙐⠠㲸म䛥挆懓價Ⓒ屼ɨ6挫㌶₣烡ვ嬩жㄲᢄ懐ͺⰐ䇝炨䁏僰㫳⟡⋸ᅚ兀㠶䱘䐶怩瀠㫌㱱㹐ᑾ囤ɭ搄矠寵⒄ᑐ刴⥎ඦѣ↤⮁棵㤜㙚ࢥ惀₶Ἧ掀ᠪߩ夌㉄吊䢡⌴㲂Ĥ㚗ᙡ䄀҂಩⍱瑦֮抐㱞ڨጩ∿Ԡ˙Ɂ㧯㇤ᔘ犨䭲䦺Շ⇅䓃ဠ "
},
"outputs": [],
"source": [
"D.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc4392b5-b799-4e48-9823-4b3647f6dbe6",
"metadata": {
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰à㬠春ㅠᘣᡰୣԡ೦瀸暴∤ᧀᎣᇚ㊟⸸㋊ᐠᱩ•ⳁႧ⛧䡤峅൚䙌汙㤓琲&䈠۾䀱䘾䒠┨ࠠ⹚₀ǘ憡屢ƚ盵+ࣝ⠠乮␠㚠᝷⟀煒⃂瓉Ȕ⬸ᐠṬҦ‣ㅑᦑ᥸屆ᨹഠ⯀ב䅻榤℔と㕵䑢ຸ䌭樺Ⱑ圅窟㝨㑀ఋ堎㒃棈嘨眐䠼৆୵〤砠ᶷ⻾ᡊ㞚戤ⴋ㟗劻ၠ戲ᐸ㸵ἠ⦳ɀ惣樈沄ዂ ঳ᙢႸ⨨ᢄᨈ忎Ԣ恰嬺槐䨂㞲∦ೱ冨င塼䥆Πᆨ別ۤ⠸晋໠慘湏࿢ंK忨ଽ⹉Ἳᄲ੺ಲ剳咭຺䔠 "
},
"outputs": [],
"source": [
"TEst.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3cddbc4-a619-4f9b-a27b-ecbeec3bd7d4",
"metadata": {
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰怶ƹ桃¼吵䁍ܡء堣ᨰ₃f䈠炳૦ϐ‚晴ሢ㏁䇮撴E䨲ࡔ䳘֫䥵傌櫩䮯ὡ懂ˆ†汩棤ẰӁĠפìW౐㮨⃎濹ǀƎᢅ\"㣙အ娠崣↳䳩ৠ㇁Ұ沀倠祐ሯܯٯ䃣ᆁ㈐ؠ嬸ඩ౤ɦҢ哻䑀妨䢣ᵕ䀺晲∪瞤∡㸦㻆䔩ڦ悦檩Ǣ᪀㕖o#䦝栃ǂ痌⇥⻾䜲㧒вⵉ憧⃳儸摐䈪఩Һ䱾抇焷ࢉ羔ᴠ╡℘✻數㛲ት畨䁣Ʉㄡ˶ᮦ⃣゘ᄴ䓃⤘㴩䆁墺⼠∰䓾ഠ֒Ѣ⏛䭄戴Გ侭⢩ൗ੩桉↰ "
},
"outputs": [],
"source": [
"A.head()"
]
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "persist_ext",
"version": "1.5.5",
"version": "1.5.6",
"description": "PersIst is a JupyterLab extension to enable persistent interactive visualizations in JupyterLab notebooks.",
"keywords": [
"jupyter",
Expand Down
75 changes: 75 additions & 0 deletions src/widgets/interactive_table/ColumnHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React, { useRef, useState } from 'react';
import { MRT_Column } from 'mantine-react-table';
import { DataPoint } from './helpers';
import { Box, TextInput } from '@mantine/core';
import { getHotkeyHandler, useValidatedState } from '@mantine/hooks';
import { PERSIST_MANTINE_FONT_SIZE } from './constants';
import { TrrackableCell } from '../../cells';
import { PersistCommands } from '../../commands';

type Props = {
cell: TrrackableCell;
column: MRT_Column<DataPoint>;
allColumns: string[];
};

export function ColumnHeader({ column, allColumns, cell }: Props) {
const ref = useRef<HTMLInputElement>(null);

const [newColumnName, setNewColumnName] = useValidatedState(
column.id,
val => {
return val.length > 0 && !allColumns.includes(val);
},
true
);

const [isEditing, setIsEditing] = useState(false);

return isEditing ? (
<TextInput
ref={ref}
value={newColumnName.value}
onChange={e => {
setNewColumnName(e.target.value);
}}
error={!newColumnName.valid}
onBlur={() => {
if (
newColumnName.value &&
newColumnName.value.length > 0 &&
newColumnName.valid &&
newColumnName.value !== column.id
) {
window.Persist.Commands.execute(PersistCommands.renameColumns, {
cell,
renameColumnMap: {
[column.id]: newColumnName.value
}
});
} else {
setNewColumnName(column.id);
}
setIsEditing(false);
}}
autoFocus
onKeyDown={getHotkeyHandler([['Enter', () => ref.current?.blur()]])}
size="xs"
/>
) : (
<Box
fz={PERSIST_MANTINE_FONT_SIZE}
onClick={e => {
e.stopPropagation();
e.preventDefault();
}}
onDoubleClick={e => {
e.stopPropagation();
e.preventDefault();
setIsEditing(true);
}}
>
{column.id}
</Box>
);
}
26 changes: 25 additions & 1 deletion src/widgets/interactive_table/DatatableComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ export function DatatableComponent({ cell }: Props) {

const [dtypes] =
useModelState<Record<string, PandasDTypes>>('df_column_types');
const columns = useColumnDefs(dfVisibleColumns, ID_COLUMN, data, [], dtypes);
const columns = useColumnDefs(
cell,
dfVisibleColumns,
ID_COLUMN,
data,
[],
dtypes
);

// Add as required
const dfColumnsWithInternal = useMemo(() => {
Expand Down Expand Up @@ -133,6 +140,7 @@ export function DatatableComponent({ cell }: Props) {
return (
<>
<MRT_ToggleFiltersButton
title="Show/Hide column search"
table={table}
fz={PERSIST_MANTINE_FONT_SIZE}
/>
Expand All @@ -156,6 +164,9 @@ export function DatatableComponent({ cell }: Props) {
},
globalFilterFn: 'containsWithNullHandling',
positionGlobalFilter: 'left',
mantineFilterTextInputProps: ({ column }) => ({
placeholder: `Search ${column.id}`
}),
mantineSearchTextInputProps: {
size: 'xs'
},
Expand Down Expand Up @@ -235,6 +246,9 @@ export function DatatableComponent({ cell }: Props) {
});
},
// Column Delete
mantineColumnActionsButtonProps: {
size: 'xs'
},
renderColumnActionsMenuItems: ({ internalColumnMenuItems, column }) => {
return (
<>
Expand Down Expand Up @@ -278,8 +292,10 @@ export function DatatableComponent({ cell }: Props) {
// Edit Cell
enableEditing: true,
editDisplayMode: 'cell',

mantineEditTextInputProps: props => {
return {
size: 'xs',
onBlur: evt => {
const columnName = props.cell.column.id;

Expand Down Expand Up @@ -316,6 +332,14 @@ export function DatatableComponent({ cell }: Props) {
// Sorting
manualSorting: true,
enableMultiSort: true,
mantineTableHeadCellProps: {
sx: () => ({
'& .mantine-TableHeadCell-Content-Labels': {
justifyContent: 'space-between',
width: '100%'
}
})
},
maxMultiSortColCount: 3,
onSortingChange: updater => {
const sortStatus =
Expand Down
14 changes: 2 additions & 12 deletions src/widgets/interactive_table/RenameTableColumnPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React from 'react';
import { MRT_Column } from 'mantine-react-table';
import { DataPoint } from './helpers';
import {
Expand Down Expand Up @@ -28,7 +28,6 @@ export function RenameTableColumnPopover({
column,
allColumnNames
}: Props) {
const [open, setOpen] = useState(false);
const [name, setName] = useValidatedState(
column.id,
val => {
Expand All @@ -39,23 +38,14 @@ export function RenameTableColumnPopover({

return (
<Popover
opened={open}
position="right-start"
trapFocus
withArrow
withinPortal={false}
shadow="md"
onClose={() => setOpen(false)}
>
<Popover.Target>
<Menu.Item
onClick={e => {
setOpen(true);
e.stopPropagation();
e.preventDefault();
}}
icon={<IconEdit />}
>
<Menu.Item closeMenuOnClick={false} icon={<IconEdit />}>
Rename column '{column.id}'
</Menu.Item>
</Popover.Target>
Expand Down

0 comments on commit ed94f89

Please sign in to comment.