Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/opral/monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelstroschein committed Jan 8, 2025
2 parents 4caa161 + 4b89daa commit bde23c1
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 99 deletions.
7 changes: 7 additions & 0 deletions .changeset/lemon-cherries-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"lix-file-manager": minor
"csv-app": minor
"@lix-js/sdk": minor
---

Refactor: change "confirmed" to "checkpoint" and "unconfirmed" to "intermediate"
6 changes: 3 additions & 3 deletions inlang/packages/fink/src/routes/changes/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function App() {
.where("id", "=", change.id)
.set("meta", {
...change.meta,
tag: "confirmed",
tag: "checkpoint",
change_set: humanId(),
})
.executeTakeFirst();
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function App() {
setShowDialog(true);
}}
>
Confirm changes
Create checkpoint
</SlButton>
<SlDialog
label="Add commit details"
Expand All @@ -100,7 +100,7 @@ export default function App() {
</div>
<div className="mt-6 flex justify-end">
<SlButton variant="primary" slot="footer" type="submit">
Confirm changes
Create checkpoint
</SlButton>
</div>
</form>
Expand Down
62 changes: 31 additions & 31 deletions packages/csv-app/src/components/ChangeSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { currentVersionAtom, lixAtom } from "../state.ts";
import clsx from "clsx";
import {
activeFileAtom,
unconfirmedChangesAtom,
intermediateChangesAtom,
} from "../state-active-file.ts";
import { SlButton, SlInput } from "@shoelace-style/shoelace/dist/react";
import { saveLixToOpfs } from "../helper/saveLixToOpfs.ts";
import { confirmChanges } from "../helper/confirmChanges.ts";
import { createCheckpoint } from "../helper/createCheckpoint.ts";
import RowDiff from "./RowDiff.tsx";
import { CellSchemaV1 } from "@lix-js/plugin-csv";

Expand All @@ -28,7 +28,7 @@ export default function Component(props: {
firstComment: string | null;
}) {
const [isOpen, setIsOpen] = useState(
props.id === "unconfirmed-changes" ? true : false
props.id === "intermediate-changes" ? true : false
);

const [lix] = useAtom(lixAtom);
Expand All @@ -37,31 +37,31 @@ export default function Component(props: {
Awaited<ReturnType<typeof getChanges>>
>({});

const [unconfirmedChanges, setUnconfirmedChanges] = useState<
Awaited<ReturnType<typeof getUnconfirmedChanges>>
const [intermediateChanges, setIntermediateChanges] = useState<
Awaited<ReturnType<typeof getIntermediateChanges>>
>({});

const [currentVersion] = useAtom(currentVersionAtom);

useEffect(() => {
if (isOpen) {
if (props.id !== "unconfirmed-changes") {
if (props.id !== "intermediate-changes") {
getChanges(lix, props.id, activeFile!.id, currentVersion).then(
setChanges
);
} else {
getUnconfirmedChanges(lix, activeFile!.id, currentVersion).then(
setUnconfirmedChanges
getIntermediateChanges(lix, activeFile!.id, currentVersion).then(
setIntermediateChanges
);
}
const interval = setInterval(async () => {
if (props.id !== "unconfirmed-changes") {
if (props.id !== "intermediate-changes") {
getChanges(lix, props.id, activeFile!.id, currentVersion).then(
setChanges
);
} else {
getUnconfirmedChanges(lix, activeFile!.id, currentVersion).then(
setUnconfirmedChanges
getIntermediateChanges(lix, activeFile!.id, currentVersion).then(
setIntermediateChanges
);
}
}, 1000);
Expand All @@ -86,8 +86,8 @@ export default function Component(props: {
<div className="flex-1 flex gap-2 items-center justify-between py-3 rounded md:h-[46px]">
<div className="flex flex-col md:flex-row md:gap-2 md:items-center flex-1">
<p className="text-zinc-950 text-sm! font-semibold">
{props.id === "unconfirmed-changes"
? "Unconfirmed changes"
{props.id === "intermediate-changes"
? "Intermediate changes"
: props.authorName}
</p>
<p className="text-sm! text-zinc-600">{props.firstComment}</p>
Expand Down Expand Up @@ -115,18 +115,18 @@ export default function Component(props: {
</div>
<div className={clsx(isOpen ? "block" : "hidden")}>
<div className="flex flex-col gap-2 px-3 pb-3">
{Object.keys(unconfirmedChanges).length > 0 && <ConfirmChangesBox />}
{Object.keys(intermediateChanges).length > 0 && <CreateCheckpointBox />}

{Object.keys(
props.id === "unconfirmed-changes" ? unconfirmedChanges : changes
props.id === "intermediate-changes" ? intermediateChanges : changes
).map((rowId) => {
const uniqueColumnValue = rowId.split("|")[1];
return (
<RowDiff
uniqueColumnValue={uniqueColumnValue}
changes={
props.id === "unconfirmed-changes"
? unconfirmedChanges[rowId]
props.id === "intermediate-changes"
? intermediateChanges[rowId]
: changes[rowId]
}
></RowDiff>
Expand All @@ -138,13 +138,13 @@ export default function Component(props: {
);
}

const ConfirmChangesBox = () => {
const CreateCheckpointBox = () => {
const [description, setDescription] = useState("");
const [lix] = useAtom(lixAtom);
const [unconfirmedChanges] = useAtom(unconfirmedChangesAtom);
const [intermediateChanges] = useAtom(intermediateChangesAtom);

const handleConfirmChanges = async () => {
const changeSet = await confirmChanges(lix, unconfirmedChanges);
const handleCreateCheckpoint = async () => {
const changeSet = await createCheckpoint(lix, intermediateChanges);
if (description !== "") {
await createDiscussion({
lix,
Expand All @@ -162,8 +162,8 @@ const ConfirmChangesBox = () => {
placeholder="Describe the changes"
onInput={(event: any) => setDescription(event.target?.value)}
></SlInput>
<SlButton slot="footer" variant="primary" onClick={handleConfirmChanges}>
{description === "" ? "Confirm without description" : "Confirm"}
<SlButton slot="footer" variant="primary" onClick={handleCreateCheckpoint}>
{description === "" ? "Create checkpoint without description" : "Create checkpoint"}
</SlButton>
</div>
);
Expand Down Expand Up @@ -194,7 +194,7 @@ const getChanges = async (
"change.id"
)
.where("change.schema_key", "=", CellSchemaV1.key)
.where(changeHasLabel("confirmed"))
.where(changeHasLabel("checkpoint"))
.where("change_set_element.change_set_id", "=", changeSetId)
.where("change.file_id", "=", fileId)
.selectAll("change")
Expand Down Expand Up @@ -241,7 +241,7 @@ const getChanges = async (
.innerJoin("change_edge", "change_edge.parent_id", "change.id")
.where("change_edge.child_id", "=", change.id)
.where(changeInVersion(currentVersion))
.where(changeHasLabel("confirmed"))
.where(changeHasLabel("checkpoint"))
.selectAll("change")
.select("snapshot.content")
.executeTakeFirst();
Expand All @@ -253,7 +253,7 @@ const getChanges = async (
};

// duplicating because easier for now. clean up later
const getUnconfirmedChanges = async (
const getIntermediateChanges = async (
lix: Lix,
fileId: string,
currentVersion: Version
Expand All @@ -268,20 +268,20 @@ const getUnconfirmedChanges = async (
>
>
> => {
const unconfirmedLeafChanges = await lix.db
const intermediateLeafChanges = await lix.db
.selectFrom("change")
.innerJoin("snapshot", "snapshot.id", "change.snapshot_id")
.where("change.file_id", "=", fileId)
.where(changeIsLeafInVersion(currentVersion))
.where((eb) => eb.not(changeHasLabel("confirmed")))
.where((eb) => eb.not(changeHasLabel("checkpoint")))
.where("change.schema_key", "=", CellSchemaV1.key)
.selectAll("change")
.select("snapshot.content")
.execute();

const groupedByRow: any = {};

for (const change of unconfirmedLeafChanges) {
for (const change of intermediateLeafChanges) {
const parts = change.entity_id.split("|");
const rowEntityId = parts[0] + "|" + parts[1];

Expand All @@ -295,12 +295,12 @@ const getUnconfirmedChanges = async (
const row = groupedByRow[id];

for (const change of row) {
// defining a parent as the last confirmed change
// defining a parent as the last checkpoint change
const parent = await lix.db
.selectFrom("change")
.innerJoin("snapshot", "snapshot.id", "change.snapshot_id")
.where("change.entity_id", "=", change.entity_id)
.where(changeHasLabel("confirmed"))
.where(changeHasLabel("checkpoint"))
.where(changeInVersion(currentVersion))
// TODO fix the filter
// https://github.com/opral/lix-sdk/issues/151
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Change, changeIsLeafOf, Lix } from "@lix-js/sdk";
import { saveLixToOpfs } from "./saveLixToOpfs.ts";

export const confirmChanges = async (
export const createCheckpoint = async (
lix: Lix,
unconfirmedChanges: Change[]
intermediateChanges: Change[]
) => {
const changeSet = await lix.db.transaction().execute(async (trx) => {
// create a new set
Expand All @@ -13,10 +13,10 @@ export const confirmChanges = async (
.returning("id")
.executeTakeFirstOrThrow();

// get the id of the confirmed tag
const confirmedLabel = await trx
// get the id of the checkpoint tag
const checkpointLabel = await trx
.selectFrom("label")
.where("name", "=", "confirmed")
.where("name", "=", "checkpoint")
.select("id")
.executeTakeFirstOrThrow();

Expand All @@ -25,12 +25,12 @@ export const confirmChanges = async (
.insertInto("change_set_label")
.values({
change_set_id: newChangeSet.id,
label_id: confirmedLabel.id,
label_id: checkpointLabel.id,
})
.execute();

// insert the leaf changes into the set
for (const change of unconfirmedChanges) {
for (const change of intermediateChanges) {
const leafChange = await trx
.selectFrom("change")
.where(changeIsLeafOf(change))
Expand Down
12 changes: 6 additions & 6 deletions packages/csv-app/src/layouts/OpenFileLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ export default function Layout(props: { children: React.ReactNode }) {
</div>

<div className="mr-1 flex items-center gap-1.5">
{/* {unconfirmedChanges.length > 0 && (
{/* {intermediateChanges.length > 0 && (
<SlButton
size="small"
variant="neutral"
disabled={unconfirmedChanges.length === 0}
onClick={() => setShowConfirmChangesDialog(true)}
disabled={intermediateChanges.length === 0}
onClick={() => setShowIntermediateChangesDialog(true)}
>
Confirm Changes
Create Checkpoint
</SlButton>
)} */}
</div>
Expand All @@ -105,8 +105,8 @@ export default function Layout(props: { children: React.ReactNode }) {
// which assumes that nothing is auto saved
//
// counter={
// unconfirmedChanges.length !== 0
// ? unconfirmedChanges.length
// intermediateChanges.length !== 0
// ? intermediateChanges.length
// : undefined
// }
name="Changes"
Expand Down
12 changes: 6 additions & 6 deletions packages/csv-app/src/routes/changes/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { atom, useAtom } from "jotai";
import { lixAtom, withPollingAtom } from "../../state.ts";
import {
activeFileAtom,
unconfirmedChangesAtom,
intermediateChangesAtom,
} from "../../state-active-file.ts";
import { changeSetHasLabel } from "@lix-js/sdk";

Expand Down Expand Up @@ -32,7 +32,7 @@ const changeSetsAtom = atom(async (get) => {
.leftJoin("comment", "comment.discussion_id", "discussion.id")
.where("comment.parent_id", "is", null) // Filter to get only the first comment
.where("change.file_id", "=", activeFile!.id)
.where(changeSetHasLabel("confirmed"))
.where(changeSetHasLabel("checkpoint"))
.groupBy("change_set.id")
.orderBy("change.created_at", "desc")
.select("change_set.id")
Expand All @@ -44,18 +44,18 @@ const changeSetsAtom = atom(async (get) => {

export default function Page() {
const [changeSets] = useAtom(changeSetsAtom);
const [unconfirmedChanges] = useAtom(unconfirmedChangesAtom);
const [intermediateChanges] = useAtom(intermediateChangesAtom);

return (
<>
<OpenFileLayout>
<div className="px-3 pb-6 pt-3 md:pt-5">
<div className="mx-auto max-w-7xl bg-white border border-zinc-200 rounded-lg divide-y divide-zinc-200 overflow-hidden">
{/* virtual change set for uncommitted changes */}
{unconfirmedChanges.length > 0 && (
{intermediateChanges.length > 0 && (
<ChangeSet
key={"unconfirmed-changes"}
id={"unconfirmed-changes"}
key={"intermediate-changes"}
id={"intermediate-changes"}
firstComment={null}
authorName={null}
/>
Expand Down
6 changes: 3 additions & 3 deletions packages/csv-app/src/state-active-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ export const activeCellChangesAtom = atom(async (get) => {
return changes;
});

// The CSV app treats changes that are not in a change set as unconfirmed changes.
export const unconfirmedChangesAtom = atom(async (get) => {
// The CSV app treats changes that are not in a change set as intermediate changes.
export const intermediateChangesAtom = atom(async (get) => {
get(withPollingAtom);
const lix = await get(lixAtom);
const activeFile = await get(activeFileAtom);
Expand All @@ -153,7 +153,7 @@ export const unconfirmedChangesAtom = atom(async (get) => {
.selectFrom("change")
.where("change.file_id", "=", activeFile.id)
.where(changeIsLeafInVersion(currentBranch))
.where((eb) => eb.not(changeHasLabel("confirmed")))
.where((eb) => eb.not(changeHasLabel("checkpoint")))
.selectAll("change")
.execute();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Change, changeIsLeafOf, Lix } from "@lix-js/sdk";
import { saveLixToOpfs } from "./saveLixToOpfs.ts";

export const confirmChanges = async (
export const createCheckpoint = async (
lix: Lix,
unconfirmedChanges: Change[]
intermediateChanges: Change[]
) => {
const changeSet = await lix.db.transaction().execute(async (trx) => {
// create a new set
Expand All @@ -14,23 +14,23 @@ export const confirmChanges = async (
.executeTakeFirstOrThrow();

// get the id of the confirmed tag
const confirmedLabel = await trx
const checkpointLabel = await trx
.selectFrom("label")
.where("name", "=", "confirmed")
.where("name", "=", "checkpoint")
.select("id")
.executeTakeFirstOrThrow();

// tag the set as confirmed
// tag the set as checkpoint
await trx
.insertInto("change_set_label")
.values({
change_set_id: newChangeSet.id,
label_id: confirmedLabel.id,
label_id: checkpointLabel.id,
})
.execute();

// insert the leaf changes into the set
for (const change of unconfirmedChanges) {
for (const change of intermediateChanges) {
const leafChange = await trx
.selectFrom("change")
.where(changeIsLeafOf(change))
Expand Down
Loading

0 comments on commit bde23c1

Please sign in to comment.