diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a1cddf7d..9a5227cb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,6 +43,21 @@ jobs: run: yarn lint working-directory: web + frontend-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: "16" + cache: yarn + cache-dependency-path: "web/yarn.lock" + - run: yarn + working-directory: web + - name: Run frontend build + run: yarn build + working-directory: web + go-tests: runs-on: ubuntu-latest steps: diff --git a/web/src/components/CreateShortcutDialog.tsx b/web/src/components/CreateShortcutDialog.tsx index b7ba34eb..16fd8914 100644 --- a/web/src/components/CreateShortcutDialog.tsx +++ b/web/src/components/CreateShortcutDialog.tsx @@ -1,4 +1,4 @@ -import { memo, useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import { memoService, shortcutService } from "../services"; import { checkShouldShowMemoWithFilters, filterConsts, getDefaultFilter, relationConsts } from "../helpers/filter"; import useLoading from "../hooks/useLoading"; @@ -152,129 +152,66 @@ interface MemoFilterInputerProps { handleFilterRemove: (index: number) => void; } -const FilterInputer: React.FC = (props: MemoFilterInputerProps) => { +const MemoFilterInputer: React.FC = (props: MemoFilterInputerProps) => { const { index, filter, handleFilterChange, handleFilterRemove } = props; + const [value, setValue] = useState(filter.value.value); + const tags = Array.from(memoService.getState().tags); const { type } = filter; - const [inputElements, setInputElements] = useState(<>); + const dataSource = + type === "TYPE" + ? filterConsts["TYPE"].values + : tags.sort().map((t) => { + return { text: t, value: t }; + }); useEffect(() => { - let operatorElement = <>; - if (Object.keys(filterConsts).includes(type)) { - operatorElement = ( - - ); - } + setValue(filter.value.value); + }, [type]); - let valueElement = <>; - switch (type) { - case "TYPE": { - valueElement = ( - - ); - break; - } - case "TAG": { - valueElement = ( - { - return { text: t, value: t }; - })} - value={filter.value.value} - handleValueChanged={handleValueChange} - /> - ); - break; - } - case "TEXT": { - valueElement = ( - { - handleValueChange(event.target.value); - event.target.focus(); - }} - /> - ); - break; - } - } - - setInputElements( - <> - {operatorElement} - {valueElement} - - ); - }, [type, filter]); - - const handleRelationChange = useCallback( - (value: string) => { - if (["AND", "OR"].includes(value)) { - handleFilterChange(index, { - ...filter, - relation: value as MemoFilterRalation, - }); - } - }, - [filter] - ); - - const handleTypeChange = useCallback( - (value: string) => { - if (filter.type !== value) { - const ops = Object.values(filterConsts[value as FilterType].operators); - handleFilterChange(index, { - ...filter, - type: value as FilterType, - value: { - operator: ops[0].value, - value: "", - }, - }); - } - }, - [filter] - ); - - const handleOperatorChange = useCallback( - (value: string) => { + const handleRelationChange = (value: string) => { + if (["AND", "OR"].includes(value)) { handleFilterChange(index, { ...filter, - value: { - ...filter.value, - operator: value, - }, + relation: value as MemoFilterRalation, }); - }, - [filter] - ); + } + }; - const handleValueChange = useCallback( - (value: string) => { + const handleTypeChange = (value: string) => { + if (filter.type !== value) { + const ops = Object.values(filterConsts[value as FilterType].operators); handleFilterChange(index, { ...filter, + type: value as FilterType, value: { - ...filter.value, - value, + operator: ops[0].value, + value: "", }, }); - }, - [filter] - ); + } + }; + + const handleOperatorChange = (value: string) => { + handleFilterChange(index, { + ...filter, + value: { + ...filter.value, + operator: value, + }, + }); + }; + + const handleValueChange = (value: string) => { + setValue(value); + handleFilterChange(index, { + ...filter, + value: { + ...filter.value, + value, + }, + }); + }; const handleRemoveBtnClick = () => { handleFilterRemove(index); @@ -296,15 +233,29 @@ const FilterInputer: React.FC = (props: MemoFilterInpute value={filter.type} handleValueChanged={handleTypeChange} /> - - {inputElements} + + {type === "TEXT" ? ( + { + handleValueChange(event.target.value); + }} + /> + ) : ( + + )} ); }; -const MemoFilterInputer: React.FC = memo(FilterInputer); - export default function showCreateShortcutDialog(shortcutId?: ShortcutId): void { generateDialog( { diff --git a/web/src/less/create-shortcut-dialog.less b/web/src/less/create-shortcut-dialog.less index 280f2467..1e3737a2 100644 --- a/web/src/less/create-shortcut-dialog.less +++ b/web/src/less/create-shortcut-dialog.less @@ -1,8 +1,10 @@ @import "./mixin.less"; .create-shortcut-dialog { + @apply px-4; + > .dialog-container { - @apply w-128; + @apply w-128 max-w-full; > .dialog-content-container { .flex(column, flex-start, flex-start);