Skip to content

Commit ea0e1b5

Browse files
authored
refactor(web): make Switch controlled-only and migrate call sites (#32399)
1 parent 368db04 commit ea0e1b5

File tree

58 files changed

+181
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+181
-222
lines changed

web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/config-popup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const ConfigPopup: FC<PopupProps> = ({
9494
const switchContent = (
9595
<Switch
9696
className="ml-3"
97-
defaultValue={enabled}
97+
value={enabled}
9898
onChange={onStatusChange}
9999
disabled={providerAllNotConfigured}
100100
/>

web/app/components/app/annotation/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,18 @@ const Annotation: FC<Props> = (props) => {
144144

145145
return (
146146
<div className="flex h-full flex-col">
147-
<p className="system-sm-regular text-text-tertiary">{t('description', { ns: 'appLog' })}</p>
147+
<p className="text-text-tertiary system-sm-regular">{t('description', { ns: 'appLog' })}</p>
148148
<div className="relative flex h-full flex-1 flex-col py-4">
149149
<Filter appId={appDetail.id} queryParams={queryParams} setQueryParams={setQueryParams}>
150150
<div className="flex items-center space-x-2">
151151
{isChatApp && (
152152
<>
153153
<div className={cn(!annotationConfig?.enabled && 'pr-2', 'flex h-7 items-center space-x-1 rounded-lg border border-components-panel-border bg-components-panel-bg-blur pl-2')}>
154154
<MessageFast className="h-4 w-4 text-util-colors-indigo-indigo-600" />
155-
<div className="system-sm-medium text-text-primary">{t('name', { ns: 'appAnnotation' })}</div>
155+
<div className="text-text-primary system-sm-medium">{t('name', { ns: 'appAnnotation' })}</div>
156156
<Switch
157157
key={controlRefreshSwitch}
158-
defaultValue={annotationConfig?.enabled}
158+
value={annotationConfig?.enabled ?? false}
159159
size="md"
160160
onChange={async (value) => {
161161
if (value) {

web/app/components/app/configuration/config-vision/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const ConfigVision: FC = () => {
121121
<ParamConfig />
122122
<div className="ml-1 mr-3 h-3.5 w-[1px] bg-divider-regular"></div>
123123
<Switch
124-
defaultValue={isImageEnabled}
124+
value={isImageEnabled}
125125
onChange={handleChange}
126126
size="md"
127127
/>

web/app/components/app/configuration/config/agent/agent-tools/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ const AgentTools: FC = () => {
298298
<div className={cn(item.isDeleted && 'opacity-50')}>
299299
{!item.notAuthor && (
300300
<Switch
301-
defaultValue={item.isDeleted ? false : item.enabled}
301+
value={item.isDeleted ? false : item.enabled}
302302
disabled={item.isDeleted || readonly}
303303
size="md"
304304
onChange={(enabled) => {

web/app/components/app/configuration/config/config-audio.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const ConfigAudio: FC = () => {
6969
<div className="flex shrink-0 items-center">
7070
<div className="ml-1 mr-3 h-3.5 w-[1px] bg-divider-subtle"></div>
7171
<Switch
72-
defaultValue={isAudioEnabled}
72+
value={isAudioEnabled}
7373
onChange={handleChange}
7474
size="md"
7575
/>

web/app/components/app/configuration/config/config-document.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const ConfigDocument: FC = () => {
6969
<div className="flex shrink-0 items-center">
7070
<div className="ml-1 mr-3 h-3.5 w-[1px] bg-divider-subtle"></div>
7171
<Switch
72-
defaultValue={isDocumentEnabled}
72+
value={isDocumentEnabled}
7373
onChange={handleChange}
7474
size="md"
7575
/>

web/app/components/app/configuration/dataset-config/params-config/config-content.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,44 +188,44 @@ const ConfigContent: FC<Props> = ({
188188

189189
return (
190190
<div>
191-
<div className="system-xl-semibold text-text-primary">{t('retrievalSettings', { ns: 'dataset' })}</div>
192-
<div className="system-xs-regular text-text-tertiary">
191+
<div className="text-text-primary system-xl-semibold">{t('retrievalSettings', { ns: 'dataset' })}</div>
192+
<div className="text-text-tertiary system-xs-regular">
193193
{t('defaultRetrievalTip', { ns: 'dataset' })}
194194
</div>
195195
{type === RETRIEVE_TYPE.multiWay && (
196196
<>
197197
<div className="my-2 flex flex-col items-center py-1">
198-
<div className="system-xs-semibold-uppercase mb-2 mr-2 shrink-0 text-text-secondary">
198+
<div className="mb-2 mr-2 shrink-0 text-text-secondary system-xs-semibold-uppercase">
199199
{t('rerankSettings', { ns: 'dataset' })}
200200
</div>
201201
<Divider bgStyle="gradient" className="m-0 !h-px" />
202202
</div>
203203
{
204204
selectedDatasetsMode.inconsistentEmbeddingModel
205205
&& (
206-
<div className="system-xs-medium mt-4 text-text-warning">
206+
<div className="mt-4 text-text-warning system-xs-medium">
207207
{t('inconsistentEmbeddingModelTip', { ns: 'dataset' })}
208208
</div>
209209
)
210210
}
211211
{
212212
selectedDatasetsMode.mixtureInternalAndExternal && (
213-
<div className="system-xs-medium mt-4 text-text-warning">
213+
<div className="mt-4 text-text-warning system-xs-medium">
214214
{t('mixtureInternalAndExternalTip', { ns: 'dataset' })}
215215
</div>
216216
)
217217
}
218218
{
219219
selectedDatasetsMode.allExternal && (
220-
<div className="system-xs-medium mt-4 text-text-warning">
220+
<div className="mt-4 text-text-warning system-xs-medium">
221221
{t('allExternalTip', { ns: 'dataset' })}
222222
</div>
223223
)
224224
}
225225
{
226226
selectedDatasetsMode.mixtureHighQualityAndEconomic
227227
&& (
228-
<div className="system-xs-medium mt-4 text-text-warning">
228+
<div className="mt-4 text-text-warning system-xs-medium">
229229
{t('mixtureHighQualityAndEconomicTip', { ns: 'dataset' })}
230230
</div>
231231
)
@@ -238,7 +238,7 @@ const ConfigContent: FC<Props> = ({
238238
<div
239239
key={option.value}
240240
className={cn(
241-
'system-sm-medium flex h-8 w-[calc((100%-8px)/2)] cursor-pointer items-center justify-center rounded-lg border border-components-option-card-option-border bg-components-option-card-option-bg text-text-secondary',
241+
'flex h-8 w-[calc((100%-8px)/2)] cursor-pointer items-center justify-center rounded-lg border border-components-option-card-option-border bg-components-option-card-option-bg text-text-secondary system-sm-medium',
242242
selectedRerankMode === option.value && 'border-[1.5px] border-components-option-card-option-selected-border bg-components-option-card-option-selected-bg text-text-primary',
243243
)}
244244
onClick={() => handleRerankModeChange(option.value)}
@@ -267,12 +267,12 @@ const ConfigContent: FC<Props> = ({
267267
canManuallyToggleRerank && (
268268
<Switch
269269
size="md"
270-
defaultValue={showRerankModel}
270+
value={showRerankModel ?? false}
271271
onChange={handleManuallyToggleRerank}
272272
/>
273273
)
274274
}
275-
<div className="system-sm-semibold ml-1 leading-[32px] text-text-secondary">{t('modelProvider.rerankModel.key', { ns: 'common' })}</div>
275+
<div className="ml-1 leading-[32px] text-text-secondary system-sm-semibold">{t('modelProvider.rerankModel.key', { ns: 'common' })}</div>
276276
<Tooltip
277277
popupContent={(
278278
<div className="w-[200px]">

web/app/components/app/configuration/tools/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const Tools = () => {
130130
className="flex h-7 cursor-pointer items-center px-3 text-xs font-medium text-gray-700"
131131
onClick={() => handleOpenExternalDataToolModal({}, -1)}
132132
>
133-
<RiAddLine className="mr-[5px] h-3.5 w-3.5 " />
133+
<RiAddLine className="mr-[5px] h-3.5 w-3.5" />
134134
{t('operation.add', { ns: 'common' })}
135135
</div>
136136
</div>
@@ -180,7 +180,7 @@ const Tools = () => {
180180
<div className="ml-2 mr-3 hidden h-3.5 w-[1px] bg-gray-200 group-hover:block" />
181181
<Switch
182182
size="l"
183-
defaultValue={item.enabled}
183+
value={item.enabled ?? false}
184184
onChange={(enabled: boolean) => handleSaveExternalDataToolModal({ ...item, enabled }, index)}
185185
/>
186186
</div>

web/app/components/app/overview/app-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function AppCard({
260260
offset={24}
261261
>
262262
<div>
263-
<Switch defaultValue={runningStatus} onChange={onChangeStatus} disabled={toggleDisabled} />
263+
<Switch value={runningStatus} onChange={onChangeStatus} disabled={toggleDisabled} />
264264
</div>
265265
</Tooltip>
266266
</div>

web/app/components/app/overview/settings/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ const SettingsModal: FC<ISettingsModalProps> = ({
281281
<div className="flex items-center justify-between">
282282
<div className={cn('system-sm-semibold py-1 text-text-secondary')}>{t('answerIcon.title', { ns: 'app' })}</div>
283283
<Switch
284-
defaultValue={inputInfo.use_icon_as_answer_icon}
284+
value={inputInfo.use_icon_as_answer_icon}
285285
onChange={v => setInputInfo({ ...inputInfo, use_icon_as_answer_icon: v })}
286286
/>
287287
</div>
@@ -315,7 +315,7 @@ const SettingsModal: FC<ISettingsModalProps> = ({
315315
/>
316316
<div className="flex items-center justify-between">
317317
<p className={cn('body-xs-regular text-text-tertiary')}>{t(`${prefixSettings}.chatColorThemeInverted`, { ns: 'appOverview' })}</p>
318-
<Switch defaultValue={inputInfo.chatColorThemeInverted} onChange={v => setInputInfo({ ...inputInfo, chatColorThemeInverted: v })}></Switch>
318+
<Switch value={inputInfo.chatColorThemeInverted} onChange={v => setInputInfo({ ...inputInfo, chatColorThemeInverted: v })}></Switch>
319319
</div>
320320
</div>
321321
</div>
@@ -326,7 +326,7 @@ const SettingsModal: FC<ISettingsModalProps> = ({
326326
<div className={cn('system-sm-semibold py-1 text-text-secondary')}>{t(`${prefixSettings}.workflow.subTitle`, { ns: 'appOverview' })}</div>
327327
<Switch
328328
disabled={!(appInfo.mode === AppModeEnum.WORKFLOW || appInfo.mode === AppModeEnum.ADVANCED_CHAT)}
329-
defaultValue={inputInfo.show_workflow_steps}
329+
value={inputInfo.show_workflow_steps}
330330
onChange={v => setInputInfo({ ...inputInfo, show_workflow_steps: v })}
331331
/>
332332
</div>
@@ -380,7 +380,7 @@ const SettingsModal: FC<ISettingsModalProps> = ({
380380
>
381381
<Switch
382382
disabled={!webappCopyrightEnabled}
383-
defaultValue={inputInfo.copyrightSwitchValue}
383+
value={inputInfo.copyrightSwitchValue}
384384
onChange={v => setInputInfo({ ...inputInfo, copyrightSwitchValue: v })}
385385
/>
386386
</Tooltip>

0 commit comments

Comments
 (0)