-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): support use tags to filter data source
- Loading branch information
1 parent
59d5e6a
commit ed0a1fd
Showing
10 changed files
with
139 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import { Text, VStack, Checkbox } from '@chakra-ui/react'; | ||
import { EditorServices } from '../../types'; | ||
|
||
type Props = { | ||
services: EditorServices; | ||
}; | ||
|
||
export const TagForm: React.FC<Props> = ({ services }) => { | ||
const { editorStore } = services; | ||
const tagMap = editorStore.app.metadata.annotations?.componentsTagMap; | ||
const componentId = editorStore.selectedComponentId; | ||
|
||
if (!tagMap) return null; | ||
|
||
const tagItems = Object.keys(tagMap).map(tag => { | ||
const checked = tagMap[tag].includes(editorStore.selectedComponentId); | ||
|
||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const newTagMap = tagMap; | ||
const nextValue = e.target.checked; | ||
if (nextValue) { | ||
newTagMap[tag].push(componentId); | ||
} else { | ||
newTagMap[tag] = tagMap[tag].filter(id => id !== componentId); | ||
} | ||
services.editorStore.appStorage.saveAppAnnotations({ | ||
componentsTagMap: newTagMap, | ||
}); | ||
}; | ||
|
||
return ( | ||
<Checkbox key={tag} defaultChecked={checked} onChange={onChange}> | ||
<Text>{tag}</Text> | ||
</Checkbox> | ||
); | ||
}); | ||
|
||
return <VStack align="flex-start">{tagItems}</VStack>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters