removed js sdk dto helpers

This commit is contained in:
Gani Georgiev
2023-08-14 21:20:49 +03:00
parent cbf1215bb1
commit 5960dc5f2d
94 changed files with 1226 additions and 1213 deletions

View File

@@ -1,7 +1,6 @@
<script>
import { createEventDispatcher, tick } from "svelte";
import { slide } from "svelte/transition";
import { Record } from "pocketbase";
import CommonHelper from "@/utils/CommonHelper";
import ApiClient from "@/utils/ApiClient";
import tooltip from "@/actions/tooltip";
@@ -46,6 +45,8 @@
let isNew = true;
let isLoaded = false;
$: isAuthCollection = collection?.type === "auth";
$: hasEditorField = !!collection?.schema?.find((f) => f.type === "editor");
$: hasFileChanges =
@@ -55,7 +56,7 @@
$: hasChanges = hasFileChanges || originalSerializedData != serializedData;
$: isNew = !original || original.$isNew;
$: isNew = !original || !original.id;
$: canSave = isNew || hasChanges;
@@ -80,8 +81,8 @@
async function load(model) {
isLoaded = false;
setErrors({}); // reset errors
original = model || new Record();
record = original.$clone();
original = model || {};
record = structuredClone(original);
uploadedFilesMap = {};
deletedFileNamesMap = {};
@@ -102,13 +103,13 @@
async function replaceOriginal(newOriginal) {
setErrors({}); // reset errors
original = newOriginal || new Record();
original = newOriginal || {};
uploadedFilesMap = {};
deletedFileNamesMap = {};
// to avoid layout shifts we replace only the file and non-schema fields
const skipFields = collection?.schema?.filter((f) => f.type != "file")?.map((f) => f.name) || [];
for (let k in newOriginal.$export()) {
for (let k in newOriginal) {
if (skipFields.includes(k)) {
continue;
}
@@ -150,20 +151,20 @@
}
function areRecordsEqual(recordA, recordB) {
const cloneA = recordA?.$clone();
const cloneB = recordB?.$clone();
const cloneA = structuredClone(recordA || {});
const cloneB = structuredClone(recordB || {});
const fileFields = collection?.schema?.filter((f) => f.type === "file");
for (let field of fileFields) {
delete cloneA?.[field.name];
delete cloneB?.[field.name];
delete cloneA[field.name];
delete cloneB[field.name];
}
// delete password props
delete cloneA?.password;
delete cloneA?.passwordConfirm;
delete cloneB?.password;
delete cloneB?.passwordConfirm;
delete cloneA.password;
delete cloneA.passwordConfirm;
delete cloneB.password;
delete cloneB.passwordConfirm;
return JSON.stringify(cloneA) == JSON.stringify(cloneB);
}
@@ -232,7 +233,7 @@
}
function exportFormData() {
const data = record?.$export() || {};
const data = structuredClone(record || {});
const formData = new FormData();
const exportableFields = {
@@ -243,7 +244,7 @@
exportableFields[field.name] = true;
}
if (collection?.isAuth) {
if (isAuthCollection) {
exportableFields["username"] = true;
exportableFields["email"] = true;
exportableFields["emailVisibility"] = true;
@@ -331,7 +332,7 @@
}
async function duplicate() {
const clone = original?.$clone();
let clone = original ? structuredClone(original) : null;
if (clone) {
clone.id = "";
@@ -369,7 +370,7 @@
class="
record-panel
{hasEditorField ? 'overlay-panel-xl' : 'overlay-panel-lg'}
{collection?.$isAuth && !isNew ? 'colored-header' : ''}
{isAuthCollection && !isNew ? 'colored-header' : ''}
"
beforeHide={() => {
if (hasChanges && confirmClose) {
@@ -400,7 +401,7 @@
<button type="button" aria-label="More" class="btn btn-sm btn-circle btn-transparent flex-gap-0">
<i class="ri-more-line" />
<Toggler class="dropdown dropdown-right dropdown-nowrap">
{#if collection.$isAuth && !original.verified && original.email}
{#if isAuthCollection && !original.verified && original.email}
<button
type="button"
class="dropdown-item closable"
@@ -410,7 +411,7 @@
<span class="txt">Send verification email</span>
</button>
{/if}
{#if collection.$isAuth && original.email}
{#if isAuthCollection && original.email}
<button
type="button"
class="dropdown-item closable"
@@ -436,7 +437,7 @@
</button>
{/if}
{#if collection.$isAuth && !isNew}
{#if isAuthCollection && !isNew}
<div class="tabs-header stretched">
<button
type="button"
@@ -523,7 +524,7 @@
/>
</Field>
{#if collection?.isAuth}
{#if isAuthCollection}
<AuthFields bind:record {isNew} {collection} />
{#if collection?.schema?.length}
@@ -564,7 +565,7 @@
{/each}
</form>
{#if collection.$isAuth && !isNew}
{#if isAuthCollection && !isNew}
<div class="tab-item" class:active={activeTab === tabProviderKey}>
<ExternalAuthsList {record} />
</div>