같은 명령의 field 계약과 유효한 select option이 유지되는 동안 사용자가 편집한 값을 보존한다. 장수 동향과 명령표 realtime 갱신을 함께 발생시키는 desktop/mobile Chromium 회귀 테스트를 추가한다.
23 lines
949 B
TypeScript
23 lines
949 B
TypeScript
import type { CommandInputField, CommandOption } from './types';
|
|
|
|
export type CommandArgumentFieldContract = Pick<CommandInputField, 'kind' | 'optionSource'>;
|
|
|
|
export const commandArgumentFieldContract = (field: CommandInputField): CommandArgumentFieldContract => ({
|
|
kind: field.kind,
|
|
optionSource: field.optionSource,
|
|
});
|
|
|
|
export const shouldPreserveCommandArgumentValue = (
|
|
field: CommandInputField,
|
|
previousField: CommandArgumentFieldContract | undefined,
|
|
values: Readonly<Record<string, unknown>>,
|
|
options: readonly CommandOption[]
|
|
): boolean => {
|
|
if (field.kind === 'hidden' || !Object.prototype.hasOwnProperty.call(values, field.key)) return false;
|
|
if (!previousField || previousField.kind !== field.kind || previousField.optionSource !== field.optionSource) {
|
|
return false;
|
|
}
|
|
if (field.kind !== 'select') return true;
|
|
return options.some((option) => option.value === values[field.key]);
|
|
};
|