Skip to content

Commit

Permalink
fix: added check for unique options
Browse files Browse the repository at this point in the history
  • Loading branch information
kirangadhave committed Nov 9, 2023
1 parent bd4c4db commit 02b53b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/test_ext_widget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@
"execution_count": 4,
"id": "3e1630c0-2ed8-4eb1-8045-c57d1fcdeb56",
"metadata": {
"__GENERATED_DATAFRAMES__": "ᯢ粠 ",
"__GENERATED_DATAFRAMES__": "ᯡࠣ䅬Ԁ朤壠ᜣ琢〹夤゠⹰〮⁁䁻қ䚾ኊ㇠നСࠩ瀮晼Ƭ穅5愠៤⠠ ",
"__has_persist_output": true,
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰໠ᬠⰥ〸斡ణᠫ‣䆠☽䞃唂ʑ⊠͑ᡈࢁ䌹硿䟦ैkᑄᄉ㐨䮲凋佩嗛᜾㸢䉠ð䀡媔࿹ဩ™+坨ఠ㜸ヷࡣ䵹姠ƊῊ3凩-倥樋瘌う䐶ẮS䦃ʠϩ䂰¬㐦̶Ԡೡ䫠恐⠸稠嬸◇Ѥ০ҡ噺䑁榨僝㸥䀺慹搑眤䈡㺚ƶ慇ܲ悡欩ǣᮥ䡀䬠➠ǥ㈥熡愖㙁≮᭛❔Ɫ⌅䆁擒ࡑ磤ȴᬯʣ٥жႄ硸㮦⡡䄨ئ⎀淖䥜⌤▤ᇂᙑĜ୓䕄憐夹०冈敓۠燘幟ࡄ࡜K俠઼⺉଴ℂજㆨ◈⓭Ჰ䔠 "
"trrack_graph": "ᯡ࠽䈌ʀ匦㢠⹰໠ᬠⰥ〸斡ణᠫ‣䆠☽䞃唂ʑ⊠͑ᡈࢁ䌹硿䟦ैkᑄᄉ㐨䮲凋佩嗛᜾㸢䉠ð䀡媔࿹ဩ™+坨ఠ㜸ヷࡣ䵹姠ƊῊ3凩-儡㊰灰¬䢶͑പΠڄ⪳ᑱ㣤੨本⺣ʠ悁₠Ɣ笚笸ূ֯⎠ഄ壡‡犀⑨娱⬥ҹૠ恐⠸稠嬸◇Ѥ০Ң乺䑀ᶨℒ䡞ˠආᴃ箏ͪÞ㶝匁Ꭷঀ䍸淢ឥ䡀䬠➠ǩ爥熡掏幀儳䎃奘᪸䅁㣐墣ˤၐ籑a⃸ḥƣჀ䅑ऱ灸壄⡡䄨ل⎃㵞䤣⌢㖤揝ៃт棌⼴⑲氺⣠旈泎⋧攪抬湄䢹⢬✰▲哚⦳猒爰剰咬櫄䀤୐\"ᠦ#巕࡛擑ⷕY*倣ᑕ玖妀䇕ᱍဧᡠ繷䋺標≷⠾㓸喀◢睕滯⏭猘ŵ嶇叝筧᧥ኁ㡹಩⍱㒅ᦦ悑屾ᾨረṦ姆櫌崾俄䫢堪ମᩭ厇亀奕䭘掅塡㮝儇㪽㍟̅㣼䝝ฮრqℨ仚滀ᐢҼ䀠⮸૚ᶧߍፐ勞䔅䘁ˡ惈ಌ䠢矁䎦࠳⛇䥀Ȉ䠓罡嶜憸ɚ碠厪篜᯦Ǿ⮱碠Ꮵ磘埴⨈偫禜港ǀ㺦ϐ剤䂀䈪Ǩ籥̰䈲რ氿ʰ⠫ͤ簰Ԉ恒⊐昦捡㟼㦖俻磬毥扑प㤀捫猺卣叴㝣校ᜧ樚⁦挩癅惺൰ܼට爜h੸匸䩨椽ᤰ䳡℆䘯ᧈ䋳₶㩢兴᪲ၒု恸ᓿ☀䍞⎆┴曈ˣ⌶派傎㼶ᣆ煥䥪癶⮒祧ቊʨ傴推 "
},
"outputs": [
{
Expand Down
16 changes: 11 additions & 5 deletions src/widgets/header/EditCategoryPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ export function EditCategoryPopover({ cell }: Props) {
const { classes, cx } = useStyles();
const [opened, openHandlers] = useDisclosure(false);
const [isAddingOption, setIsAddingOption] = useState(false);
const [newOption, setNewOptionValue] = useValidatedState<string>(
'',
value => value.trim().length > 0
);

const [categoriesColumnRecord] = useModelState<Categories>(
'df_category_columns'
Expand All @@ -103,6 +99,11 @@ export function EditCategoryPopover({ cell }: Props) {
skipOptionsSyncRef
} = useCategoryOptions(categoriesColumnRecord);

const [newOption, setNewOptionValue] = useValidatedState<string>(
'',
value => !options.includes(value)
);

const addOptionCb = useCallback((category: string, option: string) => {
window.Persist.Commands.execute(PersistCommands.categorize, {
cell,
Expand Down Expand Up @@ -369,6 +370,9 @@ export function EditCategoryPopover({ cell }: Props) {
value={newOption.value}
autoFocus
onChange={e => setNewOptionValue(e.currentTarget.value)}
error={
!newOption.valid && 'Category options must be unique'
}
onKeyDown={getHotkeyHandler([
[
'Enter',
Expand All @@ -385,7 +389,9 @@ export function EditCategoryPopover({ cell }: Props) {
<Button
size="xs"
variant="light"
disabled={!newOption.valid}
disabled={
!newOption.valid || newOption.value.length === 0
}
leftIcon={<IconPlus size={PERSIST_ICON_SIZE} />}
onClick={() =>
addOptionCb(
Expand Down

0 comments on commit 02b53b9

Please sign in to comment.