From 772d67fd6509e94cfdcc75575e13b7eab342edfd Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 15 Jun 2023 17:07:17 +0800 Subject: [PATCH] feat: suport var select options sortable (#376) --- .../config-var/config-select/index.tsx | 82 ++++++++++++------- .../config-var/config-select/style.module.css | 3 + web/package.json | 3 + 3 files changed, 58 insertions(+), 30 deletions(-) diff --git a/web/app/components/app/configuration/config-var/config-select/index.tsx b/web/app/components/app/configuration/config-var/config-select/index.tsx index 37d3812e11..0174e7044f 100644 --- a/web/app/components/app/configuration/config-var/config-select/index.tsx +++ b/web/app/components/app/configuration/config-var/config-select/index.tsx @@ -1,53 +1,75 @@ 'use client' -import React, { FC, useState } from 'react' +import type { FC } from 'react' +import React from 'react' import { useTranslation } from 'react-i18next' import { PlusIcon } from '@heroicons/react/24/outline' +import { ReactSortable } from 'react-sortablejs' import RemoveIcon from '../../base/icons/remove-icon' import s from './style.module.css' export type Options = string[] -export interface IConfigSelectProps { +export type IConfigSelectProps = { options: Options onChange: (options: Options) => void } - const ConfigSelect: FC = ({ options, - onChange + onChange, }) => { const { t } = useTranslation() + const optionList = options.map((content, index) => { + return ({ + id: index, + name: content, + }) + }) + return (
{options.length > 0 && ( -
- {options.map((o, index) => ( -
- { - let value = e.target.value - onChange(options.map((item, i) => { - if (index === i) { - return value - } - return item - })) - }} - className={`${s.input} w-full px-3 text-sm leading-9 text-gray-900 border-0 grow h-9 bg-transparent focus:outline-none cursor-pointer`} - /> - { - onChange(options.filter((_, i) => index !== i)) - }} - /> -
- ))} +
+ onChange(list.map(item => item.name))} + handle='.handle' + ghostClass="opacity-50" + animation={150} + > + {options.map((o, index) => ( +
+
+ + + +
+ { + const value = e.target.value + onChange(options.map((item, i) => { + if (index === i) + return value + + return item + })) + }} + className={`${s.input} w-full px-1.5 text-sm leading-9 text-gray-900 border-0 grow h-9 bg-transparent focus:outline-none cursor-pointer`} + /> + { + onChange(options.filter((_, i) => index !== i)) + }} + /> +
+ ))} +
)} diff --git a/web/app/components/app/configuration/config-var/config-select/style.module.css b/web/app/components/app/configuration/config-var/config-select/style.module.css index 5d558d89f2..fb6bca969e 100644 --- a/web/app/components/app/configuration/config-var/config-select/style.module.css +++ b/web/app/components/app/configuration/config-var/config-select/style.module.css @@ -1,6 +1,9 @@ .inputWrap { + display: flex; + align-items: center; border-radius: 8px; border: 1px solid #EAECF0; + padding-left: 10px; cursor: pointer; } diff --git a/web/package.json b/web/package.json index 346c6361cc..ae846508c7 100644 --- a/web/package.json +++ b/web/package.json @@ -62,6 +62,7 @@ "react-infinite-scroll-component": "^6.1.0", "react-markdown": "^8.0.6", "react-slider": "^2.0.4", + "react-sortablejs": "^6.1.4", "react-syntax-highlighter": "^15.5.0", "react-tooltip": "5.8.3", "react-window": "^1.8.9", @@ -73,6 +74,7 @@ "sass": "^1.61.0", "scheduler": "^0.23.0", "server-only": "^0.0.1", + "sortablejs": "^1.15.0", "swr": "^2.1.0", "tailwindcss": "^3.2.7", "typescript": "4.9.5", @@ -84,6 +86,7 @@ "@types/js-cookie": "^3.0.3", "@types/negotiator": "^0.6.1", "@types/qs": "^6.9.7", + "@types/sortablejs": "^1.15.1", "eslint-plugin-react-hooks": "^4.6.0", "lint-staged": "^13.2.2", "miragejs": "^0.1.47",